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.

222 lines
7.1KB

  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. foreach ($product->getProductFamily()->getProductCategories() as $category) {
  17. if ($category->getParent()) {
  18. if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) {
  19. $allCategoriesSalesOff = false;
  20. }
  21. } else {
  22. if ($category->getSaleStatus()) {
  23. $allCategoriesSalesOff = false;
  24. }
  25. }
  26. }
  27. if ($allCategoriesSalesOff) {
  28. return false;
  29. }
  30. return true;
  31. }
  32. // getProductQuantity
  33. public function getProductQuantity(ProductInterface $product)
  34. {
  35. $productFamily = $product->getProductFamily();
  36. if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  37. return $this->getQuantityInherited($product) / $this->getUnitInherited($product)->getCoefficient();
  38. } else {
  39. return 1;
  40. }
  41. }
  42. public function getBuyingPriceInherited(ProductInterface $product)
  43. {
  44. if ($product->getBuyingPrice()) {
  45. return $product->getBuyingPrice();
  46. } else {
  47. return $product->getProductFamily()->getBuyingPrice();
  48. }
  49. }
  50. public function getBuyingPriceByRefUnitInherited(ProductInterface $product)
  51. {
  52. if ($product->getBuyingPriceByRefUnit()) {
  53. return $product->getBuyingPriceByRefUnit();
  54. } else {
  55. return $product->getProductFamily()->getBuyingPriceByRefUnit();
  56. }
  57. }
  58. public function getPriceInherited(ProductInterface $product)
  59. {
  60. if ($product->getPrice()) {
  61. return $product->getPrice();
  62. } else {
  63. return $product->getProductFamily()->getPrice();
  64. }
  65. }
  66. public function getPriceByRefUnitInherited(ProductInterface $product)
  67. {
  68. if ($product->getPriceByRefUnit()) {
  69. return $product->getPriceByRefUnit();
  70. } else {
  71. return $product->getProductFamily()->getPriceByRefUnit();
  72. }
  73. }
  74. public function getBehaviorPriceInherited(ProductInterface $product)
  75. {
  76. return $product->getProductFamily()->getBehaviorPrice();
  77. }
  78. public function getReductionCatalogInherited(ProductInterface $product)
  79. {
  80. return $product->getProductFamily()->getReductionCatalog();
  81. }
  82. public function getUnitInherited(ProductInterface $product)
  83. {
  84. if ($product->getUnit()) {
  85. return $product->getUnit();
  86. } else {
  87. return $product->getProductFamily()->getUnit();
  88. }
  89. }
  90. public function getTitleInherited(ProductInterface $product)
  91. {
  92. if ($product->getTitle()) {
  93. return $product->getTitle();
  94. } else {
  95. return $product->getProductFamily()->getTitle();
  96. }
  97. }
  98. public function getFullTitle(ProductInterface $product)
  99. {
  100. if ($product->getTitle()) {
  101. $endOfTitle = $product->getTitle();
  102. } else {
  103. $endOfTitle = $this->getQuantityInherited($product) . ' ' . $this->getUnitInherited($product)->getWordingShort();
  104. }
  105. return $product->getProductFamily()->getTitle() . ' - ' . $endOfTitle;
  106. }
  107. public function getQuantityInherited(ProductInterface $product)
  108. {
  109. if ($product->getQuantity()) {
  110. return $product->getQuantity();
  111. } else if ($product->getProductFamily()->getQuantity()) {
  112. return $product->getProductFamily()->getQuantity();
  113. } else {
  114. return 1;
  115. }
  116. }
  117. public function getQuantityLabelInherited(ProductInterface $product)
  118. {
  119. $quantity = $this->getQuantityInherited($product);
  120. $unit = $this->getUnitInherited($product);
  121. return $quantity . $unit->getWordingShort();
  122. }
  123. public function getAvailableQuantityInherited(ProductInterface $product)
  124. {
  125. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  126. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  127. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  128. return $product->getProductFamily()->getAvailableQuantity();
  129. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  130. return $product->getAvailableQuantity();
  131. }
  132. }
  133. public function getAvailableQuantityDefaultInherited(ProductInterface $product)
  134. {
  135. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  136. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  137. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  138. return $product->getProductFamily()->getAvailableQuantityDefault();
  139. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  140. return $product->getAvailableQuantityDefault();
  141. }
  142. }
  143. public function getAvailableQuantitySupplierInherited(ProductInterface $product)
  144. {
  145. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  146. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  147. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  148. return $product->getProductFamily()->getAvailableQuantitySupplier();
  149. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  150. return $product->getAvailableQuantitySupplier();
  151. }
  152. }
  153. /*public function getTaxRateInherited(ProductInterface $product)
  154. {
  155. return $product->getProductFamily()->getTaxRateInherited();
  156. }*/
  157. public function getExportTitleInherited(ProductInterface $product): ?string
  158. {
  159. $exportTitle = $product->getExportTitle();
  160. if ($exportTitle && strlen($exportTitle)) {
  161. return $exportTitle;
  162. } else {
  163. $productFamily = $product->getProductFamily();
  164. if ($productFamily) {
  165. return $productFamily->getExportTitle();
  166. }
  167. }
  168. return null;
  169. }
  170. public function getExportNoteInherited(ProductInterface $product): ?string
  171. {
  172. $exportNote = $product->getExportNote();
  173. if ($exportNote && strlen($exportNote)) {
  174. return $exportNote;
  175. } else {
  176. $productFamily = $product->getProductFamily();
  177. if ($productFamily) {
  178. return $productFamily->getExportNote();
  179. }
  180. }
  181. return null;
  182. }
  183. public function getWeightInherited(ProductInterface $product): ? float
  184. {
  185. if ($product->getWeight()) {
  186. return $product->getWeight();
  187. }
  188. return $product->getProductFamily()->getWeight();
  189. }
  190. }