ソースを参照

Refactoring

develop
Fabien Normand 2年前
コミット
fccbf1adb9
2個のファイルの変更61行の追加61行の削除
  1. +22
    -44
      Builder/Order/OrderShopBuilder.php
  2. +39
    -17
      EventSubscriber/Product/UpdateProductfamilyAfterFlushEventSubscriber.php

+ 22
- 44
Builder/Order/OrderShopBuilder.php ファイルの表示

@@ -39,7 +39,6 @@ use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore;
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Resolver\OrderShopResolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductReductionCatalogSolver;
use Lc\CaracoleBundle\Solver\Order\OrderProductSolver;
@@ -48,7 +47,7 @@ use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;
use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;

@@ -65,14 +64,12 @@ class OrderShopBuilder
protected DocumentBuilder $documentBuilder;
protected EventDispatcherInterface $eventDispatcher;
protected FlashBagInterface $flashBag;
protected OpeningResolver $openingResolver;
protected ProductSolver $productSolver;
protected OrderShopResolver $orderShopResolver;
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;
protected DistributionBuilder $distributionBuilder;
protected MerchantResolver $merchantResolver;
protected CreditHistoryBuilder $creditHistoryBuilder;
protected FlashBagTranslator $flashBagTranslator;
protected OrderShopFactory $orderShopFactory;
protected OrderProductSolver $orderProductSolver;

@@ -88,14 +85,12 @@ class OrderShopBuilder
PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
DistributionBuilder $distributionBuilder,
MerchantResolver $merchantResolver,
CreditHistoryBuilder $creditHistoryBuilder,
FlashBagTranslator $flashBagTranslator,
OrderShopFactory $orderShopFactory,
OrderProductSolver $orderProductSolver
) {
@@ -110,14 +105,12 @@ class OrderShopBuilder
$this->priceSolver = $priceSolver;
$this->eventDispatcher = $eventDispatcher;
$this->flashBag = $flashBag;
$this->openingResolver = $openingResolver;
$this->productSolver = $productSolver;
$this->orderShopResolver = $orderShopResolver;
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
$this->distributionBuilder = $distributionBuilder;
$this->merchantResolver = $merchantResolver;
$this->creditHistoryBuilder = $creditHistoryBuilder;
$this->flashBagTranslator = $flashBagTranslator;
$this->orderShopFactory = $orderShopFactory;
$this->orderProductSolver = $orderProductSolver;
}
@@ -541,50 +534,35 @@ class OrderShopBuilder
$this->entityManager->flush();
}

public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
public function updatePriceByProductFamily(ProductFamilyInterface $productFamily, SectionInterface $section)
{
$debug = '';

foreach ($this->merchantResolver->getCurrent()->getSections() as $section) {
// @TODO : faire la vérification isOpenSale depuis la méthode appelante
if (!$this->openingResolver->isOpenSale($section)) {
$countOrderProductUpdated = 0;
$countOrderProductUpdated = 0;

foreach ($productFamily->getProducts() as $product) {
$orderProducts = $this->orderProductStore->resetContext()->setSection(
$section
)->getInCartsByProduct($product);
foreach ($productFamily->getProducts() as $product) {
$orderProducts = $this->orderProductStore->resetContext()->setSection(
$section
)->getInCartsByProduct($product);

foreach ($orderProducts as $orderProduct) {
$quantityOrder = $orderProduct->getQuantityOrder();
$orderShop = $orderProduct->getOrderShop();
foreach ($orderProducts as $orderProduct) {
$quantityOrder = $orderProduct->getQuantityOrder();
$orderShop = $orderProduct->getOrderShop();

$orderShop->removeOrderProduct($orderProduct);
$this->entityManager->delete($orderProduct);
$this->entityManager->flush();
$this->entityManager->refresh($orderShop);
$orderShop->removeOrderProduct($orderProduct);
$this->entityManager->delete($orderProduct);
$this->entityManager->flush();
$this->entityManager->refresh($orderShop);

$orderProductFactory = new OrderProductFactory();
$addOrderProduct = $orderProductFactory->create($product, $quantityOrder);
$this->addOrderProduct($orderShop, $addOrderProduct);
$orderProductFactory = new OrderProductFactory();
$addOrderProduct = $orderProductFactory->create($product, $quantityOrder);
$this->addOrderProduct($orderShop, $addOrderProduct);

$countOrderProductUpdated++;
}
}
if ($countOrderProductUpdated) {
$this->flashBagTranslator->add(
'success',
'orderProductUpdated',
'OrderShop',
//array('%count%' => $countOrderProductUpdated)
['%count' => $debug]
);

$this->entityManager->flush();
}
return $countOrderProductUpdated;
$countOrderProductUpdated++;
}
}
if ($countOrderProductUpdated) {
$this->entityManager->flush();
}
return $countOrderProductUpdated;
}



+ 39
- 17
EventSubscriber/Product/UpdateProductfamilyAfterFlushEventSubscriber.php ファイルの表示

@@ -2,31 +2,29 @@

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
use Lc\CaracoleBundle\Container\Product\ProductContainer;
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class UpdateProductfamilyAfterFlushEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $em;
protected ProductFamilyContainer $productFamilyContainer;
protected ProductContainer $productContainer;
protected OrderShopBuilder $orderShopBuilder;
protected OpeningResolver $openingResolver;
protected FlashBagTranslator $flashBagTranslator;

public function __construct(EntityManagerInterface $entityManager, ProductFamilyContainer $productFamilyContainer, ProductContainer $productContainer, OrderShopBuilder $orderShopBuilder)
public function __construct(
OrderShopBuilder $orderShopBuilder,
OpeningResolver $openingResolver,
FlashBagTranslator $flashBagTranslator
)
{
$this->em = $entityManager;
$this->productFamilyContainer = $productFamilyContainer;
$this->productContainer = $productContainer;
$this->orderShopBuilder = $orderShopBuilder;
$this->openingResolver = $openingResolver;
$this->flashBagTranslator = $flashBagTranslator;
}

public static function getSubscribedEvents()
@@ -38,9 +36,33 @@ class UpdateProductfamilyAfterFlushEventSubscriber implements EventSubscriberInt

public function processAfterFlushProductFamily(AfterEntityUpdatedEvent $event)
{
$entity = $event->getEntityInstance();
if ($entity instanceof ProductFamilyInterface) {
$this->orderShopBuilder->updatePriceByProductFamily($entity);
$productFamily = $event->getEntityInstance();
if ($productFamily instanceof ProductFamilyInterface) {


foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) {

$section = $productFamilySectionProperty->getSection();

if (!$this->openingResolver->isOpenSale($section)) {

$countOrderProductUpdated = $this->orderShopBuilder->updatePriceByProductFamily($productFamily, $section);

if ($countOrderProductUpdated) {
$this->flashBagTranslator->add(
'success',
'orderProductUpdated',
'OrderShop',
array(
'%count%' => $countOrderProductUpdated,
'%section%' => $section->getTitle()
)
);
}

}
}
}
}
}

読み込み中…
キャンセル
保存