|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; |
|
|
use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
|
|
|
use Lc\CaracoleBundle\Event\Order\CartChangeEvent; |
|
|
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; |
|
|
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; |
|
|
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; |
|
|
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
|
|
|
|
|
|
protected FlashBagTranslator $flashBagTranslator; |
|
|
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, |
|
|
|
|
|
FlashBagTranslator $flashBagTranslator |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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(); |
|
|
$cacheIdCartCurrent = 'cart_current_' . $section->getId(); |
|
|
if ($cache |
|
|
if ($cache |
|
|
&& isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent]) |
|
|
|
|
|
&& $this->cacheCartCurrentBySection[$cacheIdCartCurrent]) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
&& isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent]) |
|
|
|
|
|
&& $this->cacheCartCurrentBySection[$cacheIdCartCurrent]) { |
|
|
return $this->cacheCartCurrentBySection[$cacheIdCartCurrent]; |
|
|
return $this->cacheCartCurrentBySection[$cacheIdCartCurrent]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
|
|
if ($reductionCatalog && $reductionCatalog->getStatus()) { |
|
|
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) { |
|
|
|
|
|
|
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
$this->entityManager->create($orderProductReductionCatalog); |
|
|
$this->entityManager->create($orderProductReductionCatalog); |
|
|
} |
|
|
} |
|
|
//TODO est-ce un update ou un create ??? |
|
|
|
|
|
|
|
|
// @TODO : update ou create ? |
|
|
$this->entityManager->persist($orderProductAdd); |
|
|
$this->entityManager->persist($orderProductAdd); |
|
|
$this->entityManager->update($orderShop); |
|
|
$this->entityManager->update($orderShop); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($persist) { |
|
|
if ($persist) { |
|
|
$this->entityManager->flush(); |
|
|
$this->entityManager->flush(); |
|
|
|
|
|
$this->eventDispatcher->dispatch(new CartChangeEvent($orderShop), CartChangeEvent::POST_UPDATE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @TODO : dispatch event cart change |
|
|
|
|
|
//$this->eventCartChange($orderShop); |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// @TODO : retourner le message d'erreur et faire le addFlash dans le contrôleur |
|
|
// @TODO : retourner le message d'erreur et faire le addFlash dans le contrôleur |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$this->utils->addFlash('error', $textError);*/ |
|
|
$this->utils->addFlash('error', $textError);*/ |
|
|
|
|
|
|
|
|
|
|
|
$return = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $return; |
|
|
return $return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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); |
|
|
if ($orderShop1 && $orderShop2) { |
|
|
if ($orderShop1 && $orderShop2) { |
|
|
foreach ($orderShop2->getOrderProducts() as $orderProduct) { |
|
|
foreach ($orderShop2->getOrderProducts() as $orderProduct) { |
|
|
$orderProductAlreadyInCart = $this->orderShopSolver->hasOrderProductAlreadyInCart($orderShop1, $orderProduct); |
|
|
|
|
|
|
|
|
$orderProductAlreadyInCart = $this->orderShopSolver->hasOrderProductAlreadyInCart( |
|
|
|
|
|
$orderShop1, |
|
|
|
|
|
$orderProduct |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if ($orderProductAlreadyInCart) { |
|
|
if ($orderProductAlreadyInCart) { |
|
|
if ($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) { |
|
|
if ($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) { |
|
|
|
|
|
|
|
|
$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(), [ |
|
|
|
|
|
'orderPayment' => $orderPayment |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
$this->creditHistoryBuilder->create( |
|
|
|
|
|
CreditHistoryModel::TYPE_DEBIT, |
|
|
|
|
|
$this->merchantResolver->getUserMerchant(), |
|
|
|
|
|
[ |
|
|
|
|
|
'orderPayment' => $orderPayment |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->orderShopResolver->isPaid($orderShop)) { |
|
|
if ($this->orderShopResolver->isPaid($orderShop)) { |
|
|
|
|
|
|
|
|
$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) |
|
|
{ |
|
|
{ |
|
|
|
|
|
$debug = ''; |
|
|
|
|
|
|
|
|
foreach ($this->merchantResolver->getCurrent()->getSections() as $section) { |
|
|
foreach ($this->merchantResolver->getCurrent()->getSections() as $section) { |
|
|
// @TODO : faire la vérification isOpenSale depuis la méthode appelante |
|
|
// @TODO : faire la vérification isOpenSale depuis la méthode appelante |
|
|
if (!$this->openingResolver->isOpenSale($section)) { |
|
|
if (!$this->openingResolver->isOpenSale($section)) { |
|
|
$countOrderProductUpdated = 0; |
|
|
$countOrderProductUpdated = 0; |
|
|
|
|
|
|
|
|
foreach ($productFamily->getProducts() as $product) { |
|
|
foreach ($productFamily->getProducts() as $product) { |
|
|
$orderProducts = $this->orderProductStore->resetContext()->setSection($section)->getInCartsByProduct($product); |
|
|
|
|
|
|
|
|
$orderProducts = $this->orderProductStore->resetContext()->setSection( |
|
|
|
|
|
$section |
|
|
|
|
|
)->getInCartsByProduct($product); |
|
|
|
|
|
|
|
|
foreach ($orderProducts as $orderProduct) { |
|
|
foreach ($orderProducts as $orderProduct) { |
|
|
$quantityOrder = $orderProduct->getQuantityOrder(); |
|
|
$quantityOrder = $orderProduct->getQuantityOrder(); |
|
|
$orderShop = $orderProduct->getOrderShop(); |
|
|
$orderShop = $orderProduct->getOrderShop(); |
|
|
|
|
|
|
|
|
$orderShop->removeOrderProduct($orderProduct); |
|
|
$orderShop->removeOrderProduct($orderProduct); |
|
|
$this->entityManager->delete($orderProduct); |
|
|
$this->entityManager->delete($orderProduct); |
|
|
$this->entityManager->flush(); |
|
|
$this->entityManager->flush(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if ($countOrderProductUpdated) { |
|
|
if ($countOrderProductUpdated) { |
|
|
// @TODO : faire le add flash dans le controller |
|
|
|
|
|
$this->flashBagTranslator->add( |
|
|
$this->flashBagTranslator->add( |
|
|
'success', |
|
|
|
|
|
'orderProductUpdated', |
|
|
|
|
|
'OrderShop', |
|
|
|
|
|
array('%count%' => $countOrderProductUpdated) |
|
|
|
|
|
|
|
|
'success', |
|
|
|
|
|
'orderProductUpdated', |
|
|
|
|
|
'OrderShop', |
|
|
|
|
|
//array('%count%' => $countOrderProductUpdated) |
|
|
|
|
|
['%count' => $debug] |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
$this->entityManager->flush(); |
|
|
$this->entityManager->flush(); |
|
|
|
|
|
|
|
|
$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); |