選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

226 行
7.3KB

  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 getFullTitle(ProductInterface $product)
  109. {
  110. if ($product->getTitle()) {
  111. $endOfTitle = $product->getTitle();
  112. } else {
  113. $endOfTitle = $this->getQuantityInherited($product).' '.$this->getUnitInherited($product)->getWordingShort();
  114. }
  115. return $product->getProductFamily()->getTitle(). ' - '. $endOfTitle;
  116. }
  117. public function getQuantityInherited(ProductInterface $product)
  118. {
  119. if ($product->getQuantity()) {
  120. return $product->getQuantity();
  121. } else if($product->getProductFamily()->getQuantity()){
  122. return $product->getProductFamily()->getQuantity();
  123. }else{
  124. return 1;
  125. }
  126. }
  127. public function getQuantityLabelInherited(ProductInterface $product)
  128. {
  129. $quantity = $this->getQuantityInherited($product);
  130. $unit = $this->getUnitInherited($product);
  131. return $quantity . $unit->getWordingShort();
  132. }
  133. public function getAvailableQuantityInherited(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()->getAvailableQuantity();
  139. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  140. return $product->getAvailableQuantity();
  141. }
  142. }
  143. public function getAvailableQuantityDefaultInherited(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()->getAvailableQuantityDefault();
  149. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  150. return $product->getAvailableQuantityDefault();
  151. }
  152. }
  153. public function getAvailableQuantitySupplierInherited(ProductInterface $product)
  154. {
  155. switch ($product->getProductFamily()->getBehaviorCountStock()) {
  156. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  157. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  158. return $product->getProductFamily()->getAvailableQuantitySupplier();
  159. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  160. return $product->getAvailableQuantitySupplier();
  161. }
  162. }
  163. /*public function getTaxRateInherited(ProductInterface $product)
  164. {
  165. return $product->getProductFamily()->getTaxRateInherited();
  166. }*/
  167. public function getExportTitleInherited(ProductInterface $product): ?string
  168. {
  169. $exportTitle = $product->getExportTitle();
  170. if ($exportTitle && strlen($exportTitle)) {
  171. return $exportTitle;
  172. } else {
  173. $productFamily = $product->getProductFamily();
  174. if ($productFamily) {
  175. return $productFamily->getExportTitle();
  176. }
  177. }
  178. return null;
  179. }
  180. public function getExportNoteInherited(ProductInterface $product): ?string
  181. {
  182. $exportNote = $product->getExportNote();
  183. if ($exportNote && strlen($exportNote)) {
  184. return $exportNote;
  185. } else {
  186. $productFamily = $product->getProductFamily();
  187. if ($productFamily) {
  188. return $productFamily->getExportNote();
  189. }
  190. }
  191. return null;
  192. }
  193. }