Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

82 lines
3.8KB

  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. // #402
  48. //$orderProduct->setPrice($this->priceSolver->getPriceWithReduction($orderProduct->getProduct()));
  49. $orderProduct->setBuyingPrice($this->priceSolver->getBuyingPrice($orderProduct->getProduct()));
  50. $orderProduct->setUnit($this->productSolver->getUnitInherited($orderProduct->getProduct()));
  51. $orderProduct->setTaxRate($this->productFamilySolver->getTaxRateInherited($orderProduct->getProduct()));
  52. $orderProduct->setQuantityProduct($this->productSolver->getQuantityInherited($orderProduct->getProduct()));
  53. return $orderProduct;
  54. }
  55. public function initReductionCatalog(SectionInterface $section, OrderProductInterface $orderProduct, ProductFamilyInterface $productFamily): OrderProductInterface
  56. {
  57. if(!$orderProduct->getOrderProductReductionCatalog()) {
  58. $reductionCatalog = $productFamily->getReductionCatalog();
  59. if ($reductionCatalog && $reductionCatalog->getStatus()) {
  60. $orderProductReductionCatalog = $this->orderProductReductionCatalogFactory->create(
  61. $reductionCatalog->getTitle(),
  62. is_null($reductionCatalog->getValue()) ? 0 : $reductionCatalog->getValue(),
  63. $reductionCatalog->getUnit(),
  64. $reductionCatalog->getBehaviorTaxRate()
  65. );
  66. $orderProduct->setOrderProductReductionCatalog($orderProductReductionCatalog);
  67. }
  68. }
  69. return $orderProduct;
  70. }
  71. }