You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductSolver.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Product;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  7. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  8. class ProductSolver
  9. {
  10. public function isProductSaleStatusOn(ProductInterface $product)
  11. {
  12. if ($product->getProductFamily()->getSaleStatus() != 1) {
  13. return false;
  14. }
  15. $allCategoriesSalesOff = true;
  16. $unavailableSpecificDay = false;
  17. foreach ($product->getProductFamily()->getProductCategories() as $category) {
  18. if ($category->getParent()) {
  19. if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) {
  20. $allCategoriesSalesOff = false;
  21. }
  22. } else {
  23. if ($category->getSaleStatus()) {
  24. $allCategoriesSalesOff = false;
  25. }
  26. }
  27. // specific day
  28. // @TODO : spécifique pdl ?
  29. $displaySpecificDay = $category->getDisplaySpecificDay();
  30. if ($displaySpecificDay && $displaySpecificDay != date('N')) {
  31. $unavailableSpecificDay = true;
  32. }
  33. }
  34. if ($allCategoriesSalesOff) {
  35. return false;
  36. }
  37. if ($unavailableSpecificDay) {
  38. return false;
  39. }
  40. return true;
  41. }
  42. // getProductQuantity
  43. public function getProductQuantity(ProductInterface $product)
  44. {
  45. $productFamily = $product->getProductFamily();
  46. if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  47. return $this->getQuantityInherited($product) / $this->getUnitInherited($product)->getCoefficient();
  48. } else {
  49. return 1;
  50. }
  51. }
  52. public function getBuyingPriceInherited(ProductInterface $product)
  53. {
  54. if ($product->getBuyingPrice()) {
  55. return $product->getBuyingPrice();
  56. } else {
  57. return $product->getProductFamily()->getBuyingPrice();
  58. }
  59. }
  60. public function getBuyingPriceByRefUnitInherited(ProductInterface $product)
  61. {
  62. if ($product->getBuyingPriceByRefUnit()) {
  63. return $product->getBuyingPriceByRefUnit();
  64. } else {
  65. return $product->getProductFamily()->getBuyingPriceByRefUnit();
  66. }
  67. }
  68. public function getPriceInherited(ProductInterface $product)
  69. {
  70. if ($product->getPrice()) {
  71. return $product->getPrice();
  72. } else {
  73. return $product->getProductFamily()->getPrice();
  74. }
  75. }
  76. public function getPriceByRefUnitInherited(ProductInterface $product)
  77. {
  78. if ($product->getPriceByRefUnit()) {
  79. return $product->getPriceByRefUnit();
  80. } else {
  81. return $product->getProductFamily()->getPriceByRefUnit();
  82. }
  83. }
  84. public function getBehaviorPriceInherited(ProductInterface $product)
  85. {
  86. return $product->getProductFamily()->getBehaviorPrice();
  87. }
  88. public function getReductionCatalogInherited(ProductInterface $product)
  89. {
  90. return $product->getProductFamily()->getReductionCatalog();
  91. }
  92. public function getUnitInherited(ProductInterface $product)
  93. {
  94. if ($product->getUnit()) {
  95. return $product->getUnit();
  96. } else {
  97. return $product->getProductFamily()->getUnit();
  98. }
  99. }
  100. public function getTitleInherited(ProductInterface $product)
  101. {
  102. if ($product->getTitle()) {
  103. return $product->getTitle();
  104. } else {
  105. return $product->getProductFamily()->getTitle();
  106. }
  107. }
  108. public function getQuantityInherited(ProductInterface $product)
  109. {
  110. if ($product->getQuantity()) {
  111. return $product->getQuantity();
  112. } else {
  113. return $product->getProductFamily()->getQuantity();
  114. }
  115. }
  116. public function getQuantityLabelInherited(ProductInterface $product)
  117. {
  118. $quantity = $this->getQuantityInherited($product);
  119. $unit = $this->getUnitInherited($product);
  120. return $quantity . $unit->getWordingShort();
  121. }
  122. public function getAvailableQuantityInherited(ProductInterface $product)
  123. {
  124. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  125. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  126. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  127. return $product->getProductFamily()->getAvailableQuantity();
  128. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  129. return $product->getAvailableQuantity();
  130. }
  131. }
  132. public function getAvailableQuantityDefaultInherited(ProductInterface $product)
  133. {
  134. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  135. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  136. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  137. return $product->getProductFamily()->getAvailableQuantityDefault();
  138. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  139. return $product->getAvailableQuantityDefault();
  140. }
  141. }
  142. public function getAvailableQuantitySupplierInherited(ProductInterface $product)
  143. {
  144. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  145. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  146. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  147. return $product->getProductFamily()->getAvailableQuantitySupplier();
  148. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  149. return $product->getAvailableQuantitySupplier();
  150. }
  151. }
  152. /*public function getTaxRateInherited(ProductInterface $product)
  153. {
  154. return $product->getProductFamily()->getTaxRateInherited();
  155. }*/
  156. public function getExportTitleInherited(ProductInterface $product): ?string
  157. {
  158. $exportTitle = $product->getExportTitle();
  159. if ($exportTitle && strlen($exportTitle)) {
  160. return $exportTitle;
  161. } else {
  162. $productFamily = $product->getProductFamily();
  163. if ($productFamily) {
  164. return $productFamily->getExportTitle();
  165. }
  166. }
  167. return null;
  168. }
  169. public function getExportNoteInherited(ProductInterface $product): ?string
  170. {
  171. $exportNote = $product->getExportNote();
  172. if ($exportNote && strlen($exportNote)) {
  173. return $exportNote;
  174. } else {
  175. $productFamily = $product->getProductFamily();
  176. if ($productFamily) {
  177. return $productFamily->getExportNote();
  178. }
  179. }
  180. return null;
  181. }
  182. }