Browse Source

OrderProduct : refactor builder reduction

packProduct
Guillaume 2 years ago
parent
commit
ae390be942
2 changed files with 36 additions and 21 deletions
  1. +34
    -2
      Builder/Order/OrderProductBuilder.php
  2. +2
    -19
      Builder/Order/OrderShopBuilder.php

+ 34
- 2
Builder/Order/OrderProductBuilder.php View File

namespace Lc\CaracoleBundle\Builder\Order; namespace Lc\CaracoleBundle\Builder\Order;


use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory;
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; 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\Order\OrderProductStore;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver; use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver; use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver; use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
protected ProductSolver $productSolver; protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver; protected ProductFamilySolver $productFamilySolver;
protected OrderProductSolver $orderProductSolver; protected OrderProductSolver $orderProductSolver;
protected OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory;
protected ProductFamilyStore $productFamilyStore;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
OrderProductStore $orderProductStore, OrderProductStore $orderProductStore,
ProductSolver $productSolver, ProductSolver $productSolver,
OrderProductSolver $orderProductSolver, OrderProductSolver $orderProductSolver,
ProductFamilySolver $productFamilySolver
ProductFamilySolver $productFamilySolver,
OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory,
ProductFamilyStore $productFamilyStore
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->priceSolver = $priceSolver; $this->priceSolver = $priceSolver;
$this->productSolver = $productSolver; $this->productSolver = $productSolver;
$this->orderProductSolver = $orderProductSolver; $this->orderProductSolver = $orderProductSolver;
$this->productFamilySolver = $productFamilySolver; $this->productFamilySolver = $productFamilySolver;
$this->orderProductReductionCatalogFactory = $orderProductReductionCatalogFactory;
$this->productFamilyStore = $productFamilyStore;
} }


public function init(OrderProductInterface $orderProduct) :OrderProductInterface public function init(OrderProductInterface $orderProduct) :OrderProductInterface


return $orderProduct; return $orderProduct;
} }

public function initReductionCatalog(SectionInterface $section, OrderProductInterface $orderProduct, ProductFamilyInterface $productFamily = null): OrderProductInterface
{
if(is_null($productFamily)) {
$productFamily = $this->productFamilyStore->setSection($section)->getOneBySlug(
$orderProduct->getProduct()->getProductFamily()->getSlug()
);
}

$reductionCatalog = $productFamily->getReductionCatalog();
if ($reductionCatalog && $reductionCatalog->getStatus()) {
$orderProductReductionCatalog = $this->orderProductReductionCatalogFactory->create(
$reductionCatalog->getTitle(),
$reductionCatalog->getValue(),
$reductionCatalog->getUnit(),
$reductionCatalog->getBehaviorTaxRate()
);

$orderProduct->setOrderProductReductionCatalog($orderProductReductionCatalog);
}

return $orderProduct;
}
} }

+ 2
- 19
Builder/Order/OrderShopBuilder.php View File

if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) { if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($orderProductAdd->getQuantityOrder() > 0) { if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false; $updated = false;
$this->orderProductBuilder->init($orderProductAdd);
$productFamily = $this->productFamilyStore->setSection($orderShop->getSection())->getOneBySlug(
$orderProductAdd->getProduct()->getProductFamily()->getSlug()
);

if ($productFamily) {
$reductionCatalog = $productFamily->getReductionCatalog();

if ($reductionCatalog && $reductionCatalog->getStatus()) {
$orderProductReductionCatalogFactory = new OrderProductReductionCatalogFactory();
$orderProductReductionCatalog = $orderProductReductionCatalogFactory->create(
$reductionCatalog->getTitle(),
$reductionCatalog->getValue(),
$reductionCatalog->getUnit(),
$reductionCatalog->getBehaviorTaxRate()
);


$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
}
}
$this->orderProductBuilder->init($orderProductAdd);
$this->orderProductBuilder->initReductionCatalog($orderShop->getSection(), $orderProductAdd);


foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($this->orderProductSolver->compare($orderProduct, $orderProductAdd)) { if ($this->orderProductSolver->compare($orderProduct, $orderProductAdd)) {

Loading…
Cancel
Save