Quellcode durchsuchen

OrderProduct : refactor builder reduction

packProduct
Guillaume vor 2 Jahren
Ursprung
Commit
ae390be942
2 geänderte Dateien mit 36 neuen und 21 gelöschten Zeilen
  1. +34
    -2
      Builder/Order/OrderProductBuilder.php
  2. +2
    -19
      Builder/Order/OrderShopBuilder.php

+ 34
- 2
Builder/Order/OrderProductBuilder.php Datei anzeigen

@@ -3,9 +3,12 @@
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\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
@@ -19,6 +22,8 @@ class OrderProductBuilder
protected ProductSolver $productSolver;
protected ProductFamilySolver $productFamilySolver;
protected OrderProductSolver $orderProductSolver;
protected OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory;
protected ProductFamilyStore $productFamilyStore;

public function __construct(
EntityManagerInterface $entityManager,
@@ -26,7 +31,9 @@ class OrderProductBuilder
OrderProductStore $orderProductStore,
ProductSolver $productSolver,
OrderProductSolver $orderProductSolver,
ProductFamilySolver $productFamilySolver
ProductFamilySolver $productFamilySolver,
OrderProductReductionCatalogFactory $orderProductReductionCatalogFactory,
ProductFamilyStore $productFamilyStore
) {
$this->entityManager = $entityManager;
$this->priceSolver = $priceSolver;
@@ -34,6 +41,8 @@ class OrderProductBuilder
$this->productSolver = $productSolver;
$this->orderProductSolver = $orderProductSolver;
$this->productFamilySolver = $productFamilySolver;
$this->orderProductReductionCatalogFactory = $orderProductReductionCatalogFactory;
$this->productFamilyStore = $productFamilyStore;
}

public function init(OrderProductInterface $orderProduct) :OrderProductInterface
@@ -47,4 +56,27 @@ class OrderProductBuilder

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 Datei anzeigen

@@ -242,26 +242,9 @@ class OrderShopBuilder
if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($orderProductAdd->getQuantityOrder() > 0) {
$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) {
if ($this->orderProductSolver->compare($orderProduct, $orderProductAdd)) {

Laden…
Abbrechen
Speichern