Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

80 lines
3.6KB

  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): OrderProductInterface
  54. {
  55. if(!$orderProduct->getOrderProductReductionCatalog()) {
  56. $reductionCatalog = $productFamily->getReductionCatalog();
  57. if ($reductionCatalog && $reductionCatalog->getStatus()) {
  58. $orderProductReductionCatalog = $this->orderProductReductionCatalogFactory->create(
  59. $reductionCatalog->getTitle(),
  60. $reductionCatalog->getValue(),
  61. $reductionCatalog->getUnit(),
  62. $reductionCatalog->getBehaviorTaxRate()
  63. );
  64. $orderProduct->setOrderProductReductionCatalog($orderProductReductionCatalog);
  65. }
  66. }
  67. return $orderProduct;
  68. }
  69. }