Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Guillaume 3 years ago
parent
commit
04b12a3ac4
5 changed files with 195 additions and 139 deletions
  1. +143
    -134
      Builder/Order/OrderShopBuilder.php
  2. +46
    -0
      EventSubscriber/Product/UpdateProductfamilyAfterFlushEventSubscriber.php
  3. +4
    -2
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  4. +1
    -1
      Repository/Order/OrderProductStore.php
  5. +1
    -2
      Repository/Product/ProductStore.php

+ 143
- 134
Builder/Order/OrderShopBuilder.php View File

protected DistributionBuilder $distributionBuilder; protected DistributionBuilder $distributionBuilder;
protected MerchantResolver $merchantResolver; protected MerchantResolver $merchantResolver;
protected CreditHistoryBuilder $creditHistoryBuilder; protected CreditHistoryBuilder $creditHistoryBuilder;
protected FlashBagTranslator $flashBagTranslator;


public function __construct( public function __construct(
EntityManagerInterface $entityManager,
OrderShopStore $orderShopStore,
OrderShopSolver $orderShopSolver,
OrderStatusStore $orderStatusStore,
OrderProductStore $orderProductStore,
ProductFamilyStore $productFamilyStore,
OrderProductBuilder $orderProductBuilder,
DocumentBuilder $documentBuilder,
PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
DistributionBuilder $distributionBuilder,
MerchantResolver $merchantResolver,
CreditHistoryBuilder $creditHistoryBuilder
) {
EntityManagerInterface $entityManager,
OrderShopStore $orderShopStore,
OrderShopSolver $orderShopSolver,
OrderStatusStore $orderStatusStore,
OrderProductStore $orderProductStore,
ProductFamilyStore $productFamilyStore,
OrderProductBuilder $orderProductBuilder,
DocumentBuilder $documentBuilder,
PriceSolver $priceSolver,
EventDispatcherInterface $eventDispatcher,
FlashBagInterface $flashBag,
OpeningResolver $openingResolver,
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
DistributionBuilder $distributionBuilder,
MerchantResolver $merchantResolver,
CreditHistoryBuilder $creditHistoryBuilder,
FlashBagTranslator $flashBagTranslator
)
{
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore; $this->orderShopStore = $orderShopStore;
$this->orderShopSolver = $orderShopSolver; $this->orderShopSolver = $orderShopSolver;
$this->distributionBuilder = $distributionBuilder; $this->distributionBuilder = $distributionBuilder;
$this->merchantResolver = $merchantResolver; $this->merchantResolver = $merchantResolver;
$this->creditHistoryBuilder = $creditHistoryBuilder; $this->creditHistoryBuilder = $creditHistoryBuilder;
$this->flashBagTranslator = $flashBagTranslator;
} }


public function create( public function create(
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface {
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null
): OrderShopInterface
{
$orderShopFactory = new OrderShopFactory(); $orderShopFactory = new OrderShopFactory();
$orderShop = $orderShopFactory->create($section, $user, $visitor); $orderShop = $orderShopFactory->create($section, $user, $visitor);


protected array $cacheCartCurrentBySection = []; protected array $cacheCartCurrentBySection = [];


public function createIfNotExist( public function createIfNotExist(
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null,
bool $cache = false
): OrderShopInterface {
SectionInterface $section,
UserInterface $user = null,
VisitorInterface $visitor = null,
bool $cache = false
): OrderShopInterface
{


$cart = null; $cart = null;


// cache // cache
$cacheIdCartCurrent = 'cart_current_'.$section->getId();
if($cache
&& isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])
&& $this->cacheCartCurrentBySection[$cacheIdCartCurrent]) {
$cacheIdCartCurrent = 'cart_current_' . $section->getId();
if ($cache
&& isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])
&& $this->cacheCartCurrentBySection[$cacheIdCartCurrent]) {


return $this->cacheCartCurrentBySection[$cacheIdCartCurrent]; return $this->cacheCartCurrentBySection[$cacheIdCartCurrent];
} }
if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) { if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) {
$cart = $this->merge($cartUser, $cartVisitor); $cart = $this->merge($cartUser, $cartVisitor);
} else { } else {
if($cartUser) {
if ($cartUser) {
$cart = $cartUser; $cart = $cartUser;
}
elseif($cartVisitor) {
} elseif ($cartVisitor) {


if($user && $cartVisitor && !$cartVisitor->getUser()) {
if ($user && $cartVisitor && !$cartVisitor->getUser()) {
$cartVisitor->setUser($user); $cartVisitor->setUser($user);
$this->entityManager->update($cartVisitor); $this->entityManager->update($cartVisitor);
$this->entityManager->flush(); $this->entityManager->flush();
} }


public function setOrderStatus( public function setOrderStatus(
OrderShopInterface $orderShop,
string $alias,
bool $forceByAdmin = false
): OrderShopInterface {
OrderShopInterface $orderShop,
string $alias,
bool $forceByAdmin = false
): OrderShopInterface
{
$orderStatus = $this->orderStatusStore->getOneByAlias($alias); $orderStatus = $this->orderStatusStore->getOneByAlias($alias);


if ($orderStatus) { if ($orderStatus) {
if ($orderShop->getOrderStatus() === null if ($orderShop->getOrderStatus() === null
|| $orderShop->getOrderStatus()->getNextStatusAllowed()->contains($orderStatus)) {
|| $orderShop->getOrderStatus()->getNextStatusAllowed()->contains($orderStatus)) {
$this->applyChangeOrderStatus($orderShop, $orderStatus, $forceByAdmin); $this->applyChangeOrderStatus($orderShop, $orderStatus, $forceByAdmin);
} }
} else { } else {
} }


public function applyChangeOrderStatus( public function applyChangeOrderStatus(
OrderShopInterface $orderShop,
OrderStatusInterface $orderStatus,
bool $forceByAdmin = false
): void {
OrderShopInterface $orderShop,
OrderStatusInterface $orderStatus,
bool $forceByAdmin = false
): void
{
$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
OrderShopChangeStatusEvent::PRE_CHANGE_STATUS
new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
OrderShopChangeStatusEvent::PRE_CHANGE_STATUS
); );


$orderShop->setOrderStatusProtected($orderStatus); $orderShop->setOrderStatusProtected($orderStatus);
$orderShop->addOrderStatusHistory($orderStatusHistory); $orderShop->addOrderStatusHistory($orderStatusHistory);


$this->eventDispatcher->dispatch( $this->eventDispatcher->dispatch(
new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
OrderShopChangeStatusEvent::POST_CHANGE_STATUS
new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
OrderShopChangeStatusEvent::POST_CHANGE_STATUS
); );
} }


public function addOrderProduct( public function addOrderProduct(
OrderShopInterface $orderShop,
OrderProductInterface $orderProductAdd,
bool $persist = true
): bool {
OrderShopInterface $orderShop,
OrderProductInterface $orderProductAdd,
bool $persist = true
): bool
{
$return = false; $return = false;


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


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


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


$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog); $orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);


foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog()
)) {
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
&& (string)$this->priceSolver->getPrice($orderProduct)
== (string)$this->priceSolver->getPrice($orderProductAdd)
&& $this->orderProductReductionCatalogSolver->compare(
$orderProduct->getOrderProductReductionCatalog(),
$orderProductAdd->getOrderProductReductionCatalog()
)) {
$orderProduct->setQuantityOrder( $orderProduct->setQuantityOrder(
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
); );


if ($persist) { if ($persist) {
} }


public function merge( public function merge(
OrderShopInterface $orderShop1,
OrderShopInterface $orderShop2,
$persist = true
): OrderShopInterface {
OrderShopInterface $orderShop1,
OrderShopInterface $orderShop2,
$persist = true
): OrderShopInterface
{
//TODO essayer de comprendre prk on doit faire un refresh ici ??? //TODO essayer de comprendre prk on doit faire un refresh ici ???
$this->entityManager->refresh($orderShop1); $this->entityManager->refresh($orderShop1);
$this->entityManager->refresh($orderShop2); $this->entityManager->refresh($orderShop2);


$orderShop->addOrderPayment($orderPayment); $orderShop->addOrderPayment($orderPayment);


if($meanPayment == OrderPaymentModel::MEAN_PAYMENT_CREDIT) {
if ($meanPayment == OrderPaymentModel::MEAN_PAYMENT_CREDIT) {
$this->creditHistoryBuilder->create(CreditHistoryModel::TYPE_DEBIT, $this->merchantResolver->getUserMerchant(), [ $this->creditHistoryBuilder->create(CreditHistoryModel::TYPE_DEBIT, $this->merchantResolver->getUserMerchant(), [
'orderPayment' => $orderPayment
'orderPayment' => $orderPayment
]); ]);
} }


$orderShop->setStatTotal($this->priceSolver->getTotal($orderShop)); $orderShop->setStatTotal($this->priceSolver->getTotal($orderShop));
$orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop)); $orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop));
$orderShop->setStatTotalOrderProductsWithReductions( $orderShop->setStatTotalOrderProductsWithReductions(
$this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
$this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
); );
$orderShop->setStatTotalOrderProductsWithTaxAndReductions( $orderShop->setStatTotalOrderProductsWithTaxAndReductions(
$this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
$this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
); );
$orderShop->setStatMarginOrderProductsWithReductions( $orderShop->setStatMarginOrderProductsWithReductions(
$this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
$this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
); );
$orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop)); $orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop));
$orderShop->setStatDeliveryPriceWithTaxAndReduction( $orderShop->setStatDeliveryPriceWithTaxAndReduction(
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
); );


$this->entityManager->persist($orderShop); $this->entityManager->persist($orderShop);
public function initDistribution(OrderShopInterface $orderShop): void public function initDistribution(OrderShopInterface $orderShop): void
{ {
$distribution = $this->distributionBuilder->guessDistributionByDeliveryDate( $distribution = $this->distributionBuilder->guessDistributionByDeliveryDate(
$orderShop->getDeliveryDate(),
$orderShop->getSection()
$orderShop->getDeliveryDate(),
$orderShop->getSection()
); );
$orderShop->setDistribution($distribution); $orderShop->setDistribution($distribution);
} }
} }


public function addReductionCart( public function addReductionCart(
OrderShopInterface $orderShop,
ReductionCartInterface $reductionCart
): ?OrderReductionCartInterface {
OrderShopInterface $orderShop,
ReductionCartInterface $reductionCart
): ?OrderReductionCartInterface
{
$orderReductionCartFactory = new OrderReductionCartFactory(); $orderReductionCartFactory = new OrderReductionCartFactory();
$orderReductionCart = $orderReductionCartFactory->create($orderShop, $reductionCart); $orderReductionCart = $orderReductionCartFactory->create($orderShop, $reductionCart);


$orderShop->addOrderReductionCart($orderReductionCart); $orderShop->addOrderReductionCart($orderReductionCart);


if ($this->orderShopResolver->isPositiveAmount($orderShop) if ($this->orderShopResolver->isPositiveAmount($orderShop)
&& $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {
&& $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {
$this->entityManager->create($orderReductionCart); $this->entityManager->create($orderReductionCart);
$this->entityManager->flush(); $this->entityManager->flush();




// createOrderReductionCredit // createOrderReductionCredit
public function addReductionCredit( public function addReductionCredit(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
): ?OrderReductionCreditInterface {
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
): ?OrderReductionCreditInterface
{
$orderReductionCreditFactory = new OrderReductionCreditFactory(); $orderReductionCreditFactory = new OrderReductionCreditFactory();
$orderReductionCredit = $orderReductionCreditFactory->create($orderShop, $reductionCredit); $orderReductionCredit = $orderReductionCreditFactory->create($orderShop, $reductionCredit);


$orderShop->addOrderReductionCredit($orderReductionCredit); $orderShop->addOrderReductionCredit($orderReductionCredit);


if ($this->orderShopResolver->isPositiveAmount($orderShop) if ($this->orderShopResolver->isPositiveAmount($orderShop)
&& $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {
&& $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {


$this->entityManager->create($orderReductionCredit); $this->entityManager->create($orderReductionCredit);
$this->entityManager->flush(); $this->entityManager->flush();
} }


public function applyDeductAvailabilityProduct( public function applyDeductAvailabilityProduct(
OrderShopInterface $orderShop,
OrderProductInterface $orderProduct
): void {
OrderShopInterface $orderShop,
OrderProductInterface $orderProduct
): void
{
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) { switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE : case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :


//Disponibilité par unité de référence //Disponibilité par unité de référence
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct()); $oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder(
) * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));


$productFamily = $orderProduct->getProduct()->getProductFamily(); $productFamily = $orderProduct->getProduct()->getProductFamily();
$productFamily->setAvailableQuantity($newAvailability); $productFamily->setAvailableQuantity($newAvailability);


public function updatePriceByProductFamily(ProductFamilyInterface $productFamily) public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
{ {
// @TODO : faire la vérification isOpenSale depuis la méthode appelante
if (!$this->openingResolver->isOpenSale(
$productFamily->getSection(),
null,
OpeningResolver::OPENING_CONTEXT_BACKEND
)) {
$countOrderProductUpdated = 0;

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

foreach ($orderProducts as $orderProduct) {
$quantityOrder = $orderProduct->getQuantityOrder();
$orderShop = $orderProduct->getOrderShop();
$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);

$countOrderProductUpdated++;
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;

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

foreach ($orderProducts as $orderProduct) {
$quantityOrder = $orderProduct->getQuantityOrder();
$orderShop = $orderProduct->getOrderShop();
$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);

$countOrderProductUpdated++;
}
} }
}
if ($countOrderProductUpdated) {
// @TODO : faire le add flash dans le controller
/*$this->utils->addFlash(
if ($countOrderProductUpdated) {
// @TODO : faire le add flash dans le controller
$this->flashBagTranslator->add(
'success', 'success',
'success.OrderShop.orderProductUpdated',
array(),
'orderProductUpdated',
'OrderShop',
array('%count%' => $countOrderProductUpdated) array('%count%' => $countOrderProductUpdated)
);*/
$this->entityManager->flush();
}
);


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


$orderShop->setStatTotal($this->priceSolver->getTotal($orderShop)); $orderShop->setStatTotal($this->priceSolver->getTotal($orderShop));
$orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop)); $orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop));
$orderShop->setStatTotalOrderProductsWithReductions( $orderShop->setStatTotalOrderProductsWithReductions(
$this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
$this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
); );
$orderShop->setStatTotalOrderProductsWithTaxAndReductions( $orderShop->setStatTotalOrderProductsWithTaxAndReductions(
$this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
$this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
); );
$orderShop->setStatMarginOrderProductsWithReductions( $orderShop->setStatMarginOrderProductsWithReductions(
$this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
$this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
); );
$orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop)); $orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop));
$orderShop->setStatDeliveryPriceWithTaxAndReduction( $orderShop->setStatDeliveryPriceWithTaxAndReduction(
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
); );


$this->entityManager->update($orderShop); $this->entityManager->update($orderShop);
public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2) public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2)
{ {
$productsSalesStatistic = new ProductsSalesStatistic( $productsSalesStatistic = new ProductsSalesStatistic(
$this->entityManager,
$entity,
$nbWeek,
$this->productSolver
$this->entityManager,
$entity,
$nbWeek,
$this->productSolver
); );


$productsSalesStatistic->init($section, $this->distributionBuilder, $this->openingResolver); $productsSalesStatistic->init($section, $this->distributionBuilder, $this->openingResolver);

+ 46
- 0
EventSubscriber/Product/UpdateProductfamilyAfterFlushEventSubscriber.php View File

<?php

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 Symfony\Component\EventDispatcher\EventSubscriberInterface;

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

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

public static function getSubscribedEvents()
{
return [
AfterEntityUpdatedEvent::class => ['processAfterFlushProductFamily'],
];
}

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

+ 4
- 2
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php View File



use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;


use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
use Lc\CaracoleBundle\Container\Product\ProductContainer; use Lc\CaracoleBundle\Container\Product\ProductContainer;
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
protected EntityManagerInterface $em; protected EntityManagerInterface $em;
protected ProductFamilyContainer $productFamilyContainer; protected ProductFamilyContainer $productFamilyContainer;
protected ProductContainer $productContainer; protected ProductContainer $productContainer;
protected OrderShopBuilder $orderShopBuilder;


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


public static function getSubscribedEvents() public static function getSubscribedEvents()
$this->processPrice($entity); $this->processPrice($entity);
$this->processReductionCatalog($entity); $this->processReductionCatalog($entity);
} }
//TODO updatePriceByProductFamily
} }





+ 1
- 1
Repository/Order/OrderProductStore.php View File

{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query->filterByProduct($product); $query->filterByProduct($product);
$query->filterByOrderStatus(OrderStatusModel::$statusAliasAsValid);
$query->filterByOrderStatus(OrderStatusModel::$statusAliasAsCart);
return $query->find(); return $query->find();
} }
} }

+ 1
- 2
Repository/Product/ProductStore.php View File

$query = $this->createQuery(); $query = $this->createQuery();
$query->filterByProductFamily($productFamily); $query->filterByProductFamily($productFamily);
$query->filterIsOriginProduct(); $query->filterIsOriginProduct();
$query->filterIsOnlineAndOffline();
return $query->find();
return $query->find();


} }
} }

Loading…
Cancel
Save