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.

85 line
3.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Order;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory;
  5. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  6. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  7. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  8. use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
  9. use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
  10. use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
  11. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  12. use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
  13. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  14. class OrderProductBuilder
  15. {
  16. protected EntityManagerInterface $entityManager;
  17. protected PriceSolver $priceSolver;
  18. protected OrderProductStore $orderProductStore;
  19. protected ProductSolver $productSolver;
  20. protected ProductFamilySolver $productFamilySolver;
  21. protected OrderProductSolver $orderProductSolver;
  22. protected OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory;
  23. protected ProductFamilyStore $productFamilyStore;
  24. public function __construct(
  25. EntityManagerInterface $entityManager,
  26. PriceSolver $priceSolver,
  27. OrderProductStore $orderProductStore,
  28. ProductSolver $productSolver,
  29. OrderProductSolver $orderProductSolver,
  30. ProductFamilySolver $productFamilySolver,
  31. OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory,
  32. ProductFamilyStore $productFamilyStore
  33. ) {
  34. $this->entityManager = $entityManager;
  35. $this->priceSolver = $priceSolver;
  36. $this->orderProductStore = $orderProductStore;
  37. $this->productSolver = $productSolver;
  38. $this->orderProductSolver = $orderProductSolver;
  39. $this->productFamilySolver = $productFamilySolver;
  40. $this->orderProductReductionCatalogFactory = $orderProductReductionCatalogFactory;
  41. $this->productFamilyStore = $productFamilyStore;
  42. }
  43. public function init(OrderProductInterface $orderProduct) :OrderProductInterface
  44. {
  45. $orderProduct->setTitle($this->orderProductSolver->getTitleOrderShop($orderProduct));
  46. $orderProduct->setPrice($this->priceSolver->getPrice($orderProduct->getProduct()));
  47. $orderProduct->setBuyingPrice($this->priceSolver->getBuyingPrice($orderProduct->getProduct()));
  48. $orderProduct->setUnit($this->productSolver->getUnitInherited($orderProduct->getProduct()));
  49. $orderProduct->setTaxRate($this->productFamilySolver->getTaxRateInherited($orderProduct->getProduct()));
  50. $orderProduct->setQuantityProduct($this->productSolver->getQuantityInherited($orderProduct->getProduct()));
  51. return $orderProduct;
  52. }
  53. public function initReductionCatalog(SectionInterface $section, OrderProductInterface $orderProduct, ProductFamilyInterface $productFamily = null): OrderProductInterface
  54. {
  55. if(!$orderProduct->getOrderProductReductionCatalog()) {
  56. if (is_null($productFamily)) {
  57. $productFamily = $this->productFamilyStore->setSection($section)->getOneBySlug(
  58. $orderProduct->getProduct()->getProductFamily()->getSlug()
  59. );
  60. }
  61. $reductionCatalog = $productFamily->getReductionCatalog();
  62. if ($reductionCatalog && $reductionCatalog->getStatus()) {
  63. $orderProductReductionCatalog = $this->orderProductReductionCatalogFactory->create(
  64. $reductionCatalog->getTitle(),
  65. $reductionCatalog->getValue(),
  66. $reductionCatalog->getUnit(),
  67. $reductionCatalog->getBehaviorTaxRate()
  68. );
  69. $orderProduct->setOrderProductReductionCatalog($orderProductReductionCatalog);
  70. }
  71. }
  72. return $orderProduct;
  73. }
  74. }