|
- <?php
-
- namespace Lc\CaracoleBundle\Builder\Order;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory;
- use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
- use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
- use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
- use Lc\CaracoleBundle\Solver\Price\PriceSolver;
- use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
- use Lc\CaracoleBundle\Solver\Product\ProductSolver;
-
- class OrderProductBuilder
- {
- protected EntityManagerInterface $entityManager;
- protected PriceSolver $priceSolver;
- protected OrderProductStore $orderProductStore;
- protected ProductSolver $productSolver;
- protected ProductFamilySolver $productFamilySolver;
- protected OrderProductSolver $orderProductSolver;
- protected OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory;
- protected ProductFamilyStore $productFamilyStore;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- PriceSolver $priceSolver,
- OrderProductStore $orderProductStore,
- ProductSolver $productSolver,
- OrderProductSolver $orderProductSolver,
- ProductFamilySolver $productFamilySolver,
- OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory,
- ProductFamilyStore $productFamilyStore
- ) {
- $this->entityManager = $entityManager;
- $this->priceSolver = $priceSolver;
- $this->orderProductStore = $orderProductStore;
- $this->productSolver = $productSolver;
- $this->orderProductSolver = $orderProductSolver;
- $this->productFamilySolver = $productFamilySolver;
- $this->orderProductReductionCatalogFactory = $orderProductReductionCatalogFactory;
- $this->productFamilyStore = $productFamilyStore;
- }
-
- public function init(OrderProductInterface $orderProduct) :OrderProductInterface
- {
- $orderProduct->setTitle($this->orderProductSolver->getTitleOrderShop($orderProduct));
- $orderProduct->setPrice($this->priceSolver->getPrice($orderProduct->getProduct()));
- // #402
- //$orderProduct->setPrice($this->priceSolver->getPriceWithReduction($orderProduct->getProduct()));
- $orderProduct->setBuyingPrice($this->priceSolver->getBuyingPrice($orderProduct->getProduct()));
- $orderProduct->setUnit($this->productSolver->getUnitInherited($orderProduct->getProduct()));
- $orderProduct->setTaxRate($this->productFamilySolver->getTaxRateInherited($orderProduct->getProduct()));
- $orderProduct->setQuantityProduct($this->productSolver->getQuantityInherited($orderProduct->getProduct()));
-
- return $orderProduct;
- }
-
- public function initReductionCatalog(SectionInterface $section, OrderProductInterface $orderProduct, ProductFamilyInterface $productFamily): OrderProductInterface
- {
- if(!$orderProduct->getOrderProductReductionCatalog()) {
-
- $reductionCatalog = $productFamily->getReductionCatalog();
- if ($reductionCatalog && $reductionCatalog->getStatus()) {
- $orderProductReductionCatalog = $this->orderProductReductionCatalogFactory->create(
- $reductionCatalog->getTitle(),
- is_null($reductionCatalog->getValue()) ? 0 : $reductionCatalog->getValue(),
- $reductionCatalog->getUnit(),
- $reductionCatalog->getBehaviorTaxRate()
- );
-
- $orderProduct->setOrderProductReductionCatalog($orderProductReductionCatalog);
- }
- }
-
- return $orderProduct;
- }
- }
|