Browse Source

Merge branch 'develop'

master
Fabien Normand 2 years ago
parent
commit
0a04332412
54 changed files with 1015 additions and 493 deletions
  1. +121
    -121
      Builder/Order/OrderShopBuilder.php
  2. +7
    -0
      Builder/PointSale/PointSaleSectionBuilder.php
  3. +50
    -0
      Container/PointSale/PointSaleSectionContainer.php
  4. +51
    -16
      Controller/AdminControllerTrait.php
  5. +7
    -0
      Controller/ControllerTrait.php
  6. +1
    -0
      Controller/Section/SectionAdminController.php
  7. +1
    -1
      Controller/Section/SwitchSectionAdminController.php
  8. +1
    -6
      Controller/Ticket/TicketAdminController.php
  9. +2
    -2
      Controller/User/GroupUserAdminController.php
  10. +5
    -0
      Definition/Field/PointSale/PointSaleFieldDefinition.php
  11. +8
    -2
      Definition/SectionSettingDefinition.php
  12. +21
    -17
      EventSubscriber/Product/OnlineOrOfflineProductCategoryAfterProductFamilyEventSubscriber.php
  13. +2
    -2
      EventSubscriber/User/InitUserMerchantEventSubscriber.php
  14. +24
    -0
      Factory/PointSale/PointSaleSectionFactory.php
  15. +2
    -0
      Factory/Product/ProductFamilyFactory.php
  16. +2
    -2
      Factory/Reduction/ReductionCatalogFactory.php
  17. +2
    -1
      Factory/User/UserPointSaleFactory.php
  18. +8
    -40
      Model/PointSale/PointSaleInterface.php
  19. +36
    -2
      Model/PointSale/PointSaleModel.php
  20. +15
    -0
      Model/PointSale/PointSaleSectionInterface.php
  21. +68
    -0
      Model/PointSale/PointSaleSectionModel.php
  22. +1
    -0
      Model/Product/ProductCategoryModel.php
  23. +4
    -1
      Model/Product/ProductFamilyModel.php
  24. +8
    -0
      Model/Section/SectionInterface.php
  25. +53
    -0
      Model/Section/SectionModel.php
  26. +2
    -1
      Model/User/UserPointSaleModel.php
  27. +8
    -6
      Notification/MailMailjetNotification.php
  28. +2
    -3
      Repository/Order/OrderProductStore.php
  29. +28
    -6
      Repository/Order/OrderShopRepositoryQuery.php
  30. +173
    -157
      Repository/Order/OrderShopStore.php
  31. +5
    -0
      Repository/PointSale/PointSaleRepositoryQuery.php
  32. +15
    -0
      Repository/PointSale/PointSaleSectionRepository.php
  33. +23
    -0
      Repository/PointSale/PointSaleSectionRepositoryQuery.php
  34. +43
    -0
      Repository/PointSale/PointSaleSectionStore.php
  35. +1
    -1
      Repository/PointSale/PointSaleStore.php
  36. +0
    -2
      Repository/Product/ProductCategoryRepositoryQuery.php
  37. +1
    -1
      Repository/Product/ProductCategoryStore.php
  38. +1
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  39. +1
    -0
      Repository/Product/ProductFamilyStore.php
  40. +2
    -2
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  41. +5
    -1
      Repository/Section/SectionRepositoryQuery.php
  42. +6
    -0
      Repository/Section/SectionStore.php
  43. +18
    -2
      Resolver/MerchantResolver.php
  44. +31
    -5
      Resolver/OpeningResolver.php
  45. +14
    -1
      Resources/translations/admin.fr.yaml
  46. +20
    -1
      Resources/views/admin/order/field/complementary.html.twig
  47. +5
    -1
      Resources/views/admin/order/field/distribution.html.twig
  48. +5
    -8
      Solver/Config/UnitSolver.php
  49. +76
    -67
      Solver/Order/OrderShopSolver.php
  50. +16
    -2
      Solver/PointSale/PointSaleSolver.php
  51. +4
    -6
      Solver/Product/ProductFamilySolver.php
  52. +8
    -4
      Statistic/Product/ProductsSalesStatistic.php
  53. +1
    -1
      Twig/FormTwigExtension.php
  54. +1
    -1
      Twig/StoreTwigExtension.php

+ 121
- 121
Builder/Order/OrderShopBuilder.php View File

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->populateProperties($this->orderShopStore);
$productsSalesStatistic->init($section, $this->distributionBuilder);
$productsSalesStatistic->populateProperties($this->orderShopStore->resetContext()->setSection($section));


return $productsSalesStatistic->getAsArray(); return $productsSalesStatistic->getAsArray();
} }

+ 7
- 0
Builder/PointSale/PointSaleSectionBuilder.php View File

<?php

namespace Lc\CaracoleBundle\Builder\PointSale;

class PointSaleSectionBuilder
{
}

+ 50
- 0
Container/PointSale/PointSaleSectionContainer.php View File

<?php

namespace Lc\CaracoleBundle\Container\PointSale;

use Lc\CaracoleBundle\Builder\PointSale\PointSaleSectionBuilder;
use Lc\CaracoleBundle\Factory\PointSale\PointSaleSectionFactory;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleSectionRepositoryQuery;
use Lc\CaracoleBundle\Repository\PointSale\PointSaleSectionStore;

class PointSaleSectionContainer
{
protected PointSaleSectionFactory $factory;
protected PointSaleSectionRepositoryQuery $repositoryQuery;
protected PointSaleSectionStore $store;
protected PointSaleSectionBuilder $builder;

public function __construct(
PointSaleSectionFactory $factory,
PointSaleSectionRepositoryQuery $repositoryQuery,
PointSaleSectionStore $store,
PointSaleSectionBuilder $builder
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
}

public function getFactory(): PointSaleSectionFactory
{
return $this->factory;
}

public function getRepositoryQuery(): PointSaleSectionRepositoryQuery
{
return $this->repositoryQuery;
}

public function getStore(): PointSaleSectionStore
{
$this->store->resetContext();

return $this->store;
}

public function getBuilder(): PointSaleSectionBuilder
{
return $this->builder;
}
}

+ 51
- 16
Controller/AdminControllerTrait.php View File



namespace Lc\CaracoleBundle\Controller; namespace Lc\CaracoleBundle\Controller;


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType; use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
AdminContext $context, AdminContext $context,
EntityComponent $entityComponent, EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin, TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
EntityManagerInterface $entityManager
) { ) {
if (!$this->isGranted( if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION, Permission::EA_EXECUTE_ACTION,
throw new InsufficientEntityPermissionException($context); throw new InsufficientEntityPermissionException($context);
} }


if (!$this->isInstanceOf(FilterMerchantInterface::class)) {
if (!$this->isInstanceOf(FilterMerchantInterface::class)
&& !$this->isInstanceOf(ProductFamilyInterface::class)) {
throw new \ErrorException('L\entité n\'est pas lié à un merchant.'); throw new \ErrorException('L\entité n\'est pas lié à un merchant.');
} }

$duplicateOtherMerchantForm = $this->createForm( $duplicateOtherMerchantForm = $this->createForm(
DuplicateToOtherMerchantFormType::class, DuplicateToOtherMerchantFormType::class,
null, null,
array(
[
'entityClass' => $context->getEntity()->getFqcn(), 'entityClass' => $context->getEntity()->getFqcn(),
'entityId' => $context->getEntity()->getInstance()->getId(), 'entityId' => $context->getEntity()->getInstance()->getId(),
'action' => $context->getRequest()->getUri(), 'action' => $context->getRequest()->getUri(),
'attr' => ['id' => 'duplicate-other-merchant-form'], 'attr' => ['id' => 'duplicate-other-merchant-form'],

)
]
); );


$duplicateOtherMerchantForm->handleRequest($context->getRequest()); $duplicateOtherMerchantForm->handleRequest($context->getRequest());


if ($duplicateOtherMerchantForm->isSubmitted() && $duplicateOtherMerchantForm->isValid()) { if ($duplicateOtherMerchantForm->isSubmitted() && $duplicateOtherMerchantForm->isValid()) {
$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance()); $newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());
$em->create($newEntity);
$entityManager->create($newEntity);
$merchant = $duplicateOtherMerchantForm->get('merchants')->getData(); $merchant = $duplicateOtherMerchantForm->get('merchants')->getData();
$newEntity->setMerchant($merchant);
$em->update($newEntity);
$em->flush();

if($this->isInstanceOf(ProductFamilyInterface::class)) {
$sectionStore = $this->getSectionContainer()->getStore()->setMerchant($merchant);

// Les ProductFamilySectionproperty sont créées en double, on rectifie ici
// @TODO : j'imagine qu'on peut faire mieux que ça. Résoudre le problème à la base par exemple.
$productFamilySectionPropertyArray = [];
foreach($newEntity->getProductFamilySectionProperties() as $productFamilySectionProperty) {
$productFamilySectionPropertyArray[$productFamilySectionProperty->getId()] = $productFamilySectionProperty;
$newEntity->removeProductFamilySectionProperty($productFamilySectionProperty);
}

foreach($productFamilySectionPropertyArray as $productFamilySectionProperty) {
$oldSection = $productFamilySectionProperty->getSection();
$newSection = $sectionStore->getOneByDevAlias($oldSection->getDevAlias());

if($newSection) {
$productFamilySectionProperty->setProductFamily($newEntity);
$productFamilySectionProperty->setSection($newSection);
$newEntity->addProductFamilySectionProperty($productFamilySectionProperty);
}
else {
$entityManager->remove($productFamilySectionProperty);
$newEntity->removeProductFamilySectionProperty($productFamilySectionProperty);
}
}

$newEntity->initProductCategories();
}
else {
$newEntity->setMerchant($merchant);
}

$entityManager->update($newEntity);
$entityManager->flush();


$url = $this->get(AdminUrlGenerator::class) $url = $this->get(AdminUrlGenerator::class)
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->setAction(ActionDefinition::INDEX)
->generateUrl(); ->generateUrl();

$this->addFlashTranslator( $this->addFlashTranslator(
'success', 'success',
'duplicateToOtherMerchant', 'duplicateToOtherMerchant',
['%merchant%' => $merchant->getTitle()] ['%merchant%' => $merchant->getTitle()]
); );


//TODO switch merchant route
return $this->redirect($url); return $this->redirect($url);
} }



if ($context->getRequest()->isXmlHttpRequest()) { if ($context->getRequest()->isXmlHttpRequest()) {
$response['data'] = $this->renderView( $response['data'] = $this->renderView(
'@LcCaracole/admin/merchant/modal/duplicate_entity_to_other_merchant.html.twig', '@LcCaracole/admin/merchant/modal/duplicate_entity_to_other_merchant.html.twig',
array(
[
'form_duplicate_entity_to_other_merchant' => $duplicateOtherMerchantForm->createView(), 'form_duplicate_entity_to_other_merchant' => $duplicateOtherMerchantForm->createView(),
)
]
); );


return new Response(json_encode($response)); return new Response(json_encode($response));
} else {
}
else {
throw new \ErrorException('La requête doit être effectué en ajax'); throw new \ErrorException('La requête doit être effectué en ajax');
} }
} }
public function buildIndexActions(Actions $actions): void public function buildIndexActions(Actions $actions): void
{ {
parent::buildIndexActions($actions); parent::buildIndexActions($actions);

if ($this->isInstanceOf(FilterMerchantInterface::class)) { if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateToOhterMerchantAction()); $actions->add(Crud::PAGE_INDEX, $this->getDuplicateToOhterMerchantAction());
} }

+ 7
- 0
Controller/ControllerTrait.php View File

use Lc\CaracoleBundle\Container\Order\OrderStatusContainer; use Lc\CaracoleBundle\Container\Order\OrderStatusContainer;
use Lc\CaracoleBundle\Container\Order\OrderStatusHistoryContainer; use Lc\CaracoleBundle\Container\Order\OrderStatusHistoryContainer;
use Lc\CaracoleBundle\Container\PointSale\PointSaleContainer; use Lc\CaracoleBundle\Container\PointSale\PointSaleContainer;
use Lc\CaracoleBundle\Container\PointSale\PointSaleSectionContainer;
use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer; use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer;
use Lc\CaracoleBundle\Container\Product\ProductContainer; use Lc\CaracoleBundle\Container\Product\ProductContainer;
use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer; use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
DistributionContainer::class => DistributionContainer::class, DistributionContainer::class => DistributionContainer::class,
ProductFamilySectionPropertyContainer::class => ProductFamilySectionPropertyContainer::class, ProductFamilySectionPropertyContainer::class => ProductFamilySectionPropertyContainer::class,
QualityLabelContainer::class => QualityLabelContainer::class, QualityLabelContainer::class => QualityLabelContainer::class,
PointSaleSectionContainer::class => PointSaleSectionContainer::class,
] ]
); );
} }
{ {
return $this->get(QualityLabelContainer::class); return $this->get(QualityLabelContainer::class);
} }

public function getPointSaleSectionContainer(): PointSaleSectionContainer
{
return $this->get(PointSaleSectionContainer::class);
}
} }

+ 1
- 0
Controller/Section/SectionAdminController.php View File

->hideOnIndex(), ->hideOnIndex(),
BooleanField::new('isDefault'), BooleanField::new('isDefault'),
StatusField::new('status'), StatusField::new('status'),
BooleanField::new('isOnlineFrontend'),
], ],
$this->getSeoPanel(), $this->getSeoPanel(),
$this->getConfPanel(), $this->getConfPanel(),

+ 1
- 1
Controller/Section/SwitchSectionAdminController.php View File

class SwitchSectionAdminController extends AbstractController class SwitchSectionAdminController extends AbstractController
{ {
/** /**
* @Route("/admin/section/switch", name="carac_section_switch")
* @Route("/admin/section/switch", name="admin_section_switch")
*/ */
public function switchSection( public function switchSection(
Request $request, Request $request,

+ 1
- 6
Controller/Ticket/TicketAdminController.php View File

public function configureActions(Actions $actions): Actions public function configureActions(Actions $actions): Actions
{ {
$actions = parent::configureActions($actions); $actions = parent::configureActions($actions);

if(!$this->getSectionCurrent()) {
$actions->disable(ActionDefinition::NEW, ActionDefinition::EDIT, ActionDefinition::DUPLICATE,ActionDefinition::DUPLICATE_TO_OTHER_SECTION, ActionDefinition::DELETE);
}else{
$actions->disable( ActionDefinition::EDIT, ActionDefinition::DUPLICATE,ActionDefinition::DUPLICATE_TO_OTHER_SECTION, ActionDefinition::DELETE);
}
$actions->disable( ActionDefinition::EDIT, ActionDefinition::DUPLICATE,ActionDefinition::DUPLICATE_TO_OTHER_SECTION, ActionDefinition::DELETE);


return $actions; return $actions;
} }

+ 2
- 2
Controller/User/GroupUserAdminController.php View File



namespace Lc\CaracoleBundle\Controller\User; namespace Lc\CaracoleBundle\Controller\User;


use Lc\CaracoleBundle\Controller\ControllerTrait;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\SovBundle\Controller\User\GroupUserAdminController as SovGroupUserAdminController; use Lc\SovBundle\Controller\User\GroupUserAdminController as SovGroupUserAdminController;


abstract class GroupUserAdminController extends SovGroupUserAdminController abstract class GroupUserAdminController extends SovGroupUserAdminController
{ {
use ControllerTrait;
use AdminControllerTrait;


public function createEntity(string $entityFqcn) public function createEntity(string $entityFqcn)
{ {

+ 5
- 0
Definition/Field/PointSale/PointSaleFieldDefinition.php View File



namespace Lc\CaracoleBundle\Definition\Field\PointSale; namespace Lc\CaracoleBundle\Definition\Field\PointSale;


use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Field\Address\AddressField; use Lc\CaracoleBundle\Field\Address\AddressField;
use Lc\SovBundle\Field\CKEditorField; use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\ImageManagerField; use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Form\Common\FileUploadType;


class PointSaleFieldDefinition extends AbstractFieldDefinition class PointSaleFieldDefinition extends AbstractFieldDefinition
{ {
'id' => IntegerField::new('id')->setSortable(true)->onlyOnIndex(), 'id' => IntegerField::new('id')->setSortable(true)->onlyOnIndex(),
'title' => TextField::new('title')->setSortable(true), 'title' => TextField::new('title')->setSortable(true),
'code' => TextField::new('code'), 'code' => TextField::new('code'),
/*'image' => ImageField::new('image')
->setUploadDir('public/uploads/images/pointsale')
->setFormType(FileUploadType::class),*/
'image' => ImageManagerField::new('image'), 'image' => ImageManagerField::new('image'),
'description' => CKEditorField::new('description'), 'description' => CKEditorField::new('description'),
'status' => StatusField::new('status')->setSortable(true), 'status' => StatusField::new('status')->setSortable(true),

+ 8
- 2
Definition/SectionSettingDefinition.php View File

const SETTING_ORDER_CLOSED_START = 'orderClosedStart'; const SETTING_ORDER_CLOSED_START = 'orderClosedStart';
const SETTING_ORDER_CLOSED_END = 'orderClosedEnd'; const SETTING_ORDER_CLOSED_END = 'orderClosedEnd';
const SETTING_ORDER_MAXIMUM_PER_CYCLE = 'orderMaximumPerCycle'; const SETTING_ORDER_MAXIMUM_PER_CYCLE = 'orderMaximumPerCycle';
/*const SETTING_COLOR_PRIMARY = 'colorPrimary';
const SETTING_COLOR_SECONDARY = 'colorSecondary';*/
const SETTING_OPENING_TEXT_CLOSED = 'openingTextClosed';


const VALUE_ORDER_STATE_DEFAULT = 'default'; const VALUE_ORDER_STATE_DEFAULT = 'default';
const VALUE_ORDER_STATE_OPEN = 'open'; const VALUE_ORDER_STATE_OPEN = 'open';
] ]
); );


$this->addSettingText(
[
'category' => self::CATEGORY_GENERAL,
'name' => self::SETTING_OPENING_TEXT_CLOSED
]
);

$this->addSettingText( $this->addSettingText(
[ [
'name' => self::SETTING_ORDER_MAXIMUM_PER_CYCLE, 'name' => self::SETTING_ORDER_MAXIMUM_PER_CYCLE,

+ 21
- 17
EventSubscriber/Product/OnlineOrOfflineProductCategoryAfterProductFamilyEventSubscriber.php View File

protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected ProductCategoryContainer $productCategoryContainer; protected ProductCategoryContainer $productCategoryContainer;


public function __construct(EntityManagerInterface $entityManager, ProductCategoryContainer $productCategoryContainer)
{
public function __construct(
EntityManagerInterface $entityManager,
ProductCategoryContainer $productCategoryContainer
) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->productCategoryContainer = $productCategoryContainer; $this->productCategoryContainer = $productCategoryContainer;
} }
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return [ return [
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
]; ];
} }


{ {
if ($event->getEntity() instanceof ProductFamilySectionPropertyInterface) { if ($event->getEntity() instanceof ProductFamilySectionPropertyInterface) {
$this->setProductCategoryByProductFamilySectionProperty($event->getEntity()); $this->setProductCategoryByProductFamilySectionProperty($event->getEntity());
} else if ($event->getEntity() instanceof ProductFamilyInterface) {

foreach ($event->getEntity()->getProductFamilySectionProperties() as $productFamilySectionProperty) {
$this->setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty);
} else {
if ($event->getEntity() instanceof ProductFamilyInterface) {
foreach ($event->getEntity()->getProductFamilySectionProperties() as $productFamilySectionProperty) {
$this->setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty);
}
} }


} }
} }


$this->productCategoryContainer->getBuilder()->setOnlineIfOnlineProductfamily($productCategory); $this->productCategoryContainer->getBuilder()->setOnlineIfOnlineProductfamily($productCategory);
} }
} }
} else if ($productFamilySectionProperty->getStatus() == 0 || $productFamily->getStatus() == 0) {
$section = $productFamilySectionProperty->getSection();
$productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories();
foreach ($productCategoryArray as $productCategory) {
if ($productCategory->getSection() === $section) {
$this->productCategoryContainer->getBuilder()->setOfflineIfOfflineProductfamily($productCategory);
} else {
if ($productFamilySectionProperty->getStatus() == 0 || $productFamily->getStatus() == 0) {
$section = $productFamilySectionProperty->getSection();
$productCategoryArray = $productFamily->getProductCategories();
foreach ($productCategoryArray as $productCategory) {
if ($productCategory->getSection() === $section) {
$this->productCategoryContainer->getBuilder()->setOfflineIfOfflineProductfamily(
$productCategory
);
}
} }
} }

} }
} }
} }

+ 2
- 2
EventSubscriber/User/InitUserMerchantEventSubscriber.php View File



public function createUserMerchant(EntityManagerEvent $event) public function createUserMerchant(EntityManagerEvent $event)
{ {
$user = $event->getEntity();
/* $user = $event->getEntity();
$entityRepository = $this->em->getRepository(get_class($user)); $entityRepository = $this->em->getRepository(get_class($user));
if ($user instanceof UserInterface) { if ($user instanceof UserInterface) {
$existingUser = $entityRepository->findOneByEmail($user->getEmail()); $existingUser = $entityRepository->findOneByEmail($user->getEmail());
); );
$this->em->create($userMerchant); $this->em->create($userMerchant);
} }
}
}*/
} }





+ 24
- 0
Factory/PointSale/PointSaleSectionFactory.php View File

<?php

namespace Lc\CaracoleBundle\Factory\PointSale;

use App\Entity\PointSale\PointSaleSection;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleSectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class PointSaleSectionFactory extends AbstractFactory
{

public function create(PointSaleInterface $pointSale, SectionInterface $section): PointSaleSectionInterface
{
$pointSaleSection = new PointSaleSection();

$pointSaleSection->setPointSale($pointSale);
$pointSaleSection->setSection($section);

return $pointSaleSection;
}

}

+ 2
- 0
Factory/Product/ProductFamilyFactory.php View File

use Lc\CaracoleBundle\Context\SectionContextTrait; use Lc\CaracoleBundle\Context\SectionContextTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\AbstractFactory; use Lc\SovBundle\Factory\AbstractFactory;


{ {
$productFamily = new ProductFamily(); $productFamily = new ProductFamily();


$productFamily->setBehaviorAddToCart(ProductFamilyModel::BEHAVIOR_ADD_TO_CART_SIMPLE);
$productFamily->setSaleStatus(true); $productFamily->setSaleStatus(true);
$productFamily->setStatus(1); $productFamily->setStatus(1);



+ 2
- 2
Factory/Reduction/ReductionCatalogFactory.php View File

class ReductionCatalogFactory extends AbstractFactory class ReductionCatalogFactory extends AbstractFactory
{ {


public function create(MerchantInterface $merchant): ReductionCatalogInterface
public function create(MerchantInterface $merchant, int $status = 1): ReductionCatalogInterface
{ {
$reductionCatalog = new ReductionCatalog(); $reductionCatalog = new ReductionCatalog();


$reductionCatalog->setMerchant($merchant); $reductionCatalog->setMerchant($merchant);
$reductionCatalog->setStatus(1);
$reductionCatalog->setStatus($status);


return $reductionCatalog; return $reductionCatalog;
} }

+ 2
- 1
Factory/User/UserPointSaleFactory.php View File



namespace Lc\CaracoleBundle\Factory\User; namespace Lc\CaracoleBundle\Factory\User;


use App\Entity\User\UserPointSale;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\User\UserPointSaleInterface; use Lc\CaracoleBundle\Model\User\UserPointSaleInterface;
use Lc\SovBundle\Factory\AbstractFactory; use Lc\SovBundle\Factory\AbstractFactory;
{ {
public function create(UserInterface $user, PointSaleInterface $pointSale): UserPointSaleInterface public function create(UserInterface $user, PointSaleInterface $pointSale): UserPointSaleInterface
{ {
$userPointSale = parent::create();
$userPointSale = new UserPointSale();


$userPointSale->setUser($user); $userPointSale->setUser($user);
$userPointSale->setPointSale($pointSale); $userPointSale->setPointSale($pointSale);

+ 8
- 40
Model/PointSale/PointSaleInterface.php View File

interface PointSaleInterface interface PointSaleInterface
{ {
public function getTitle(): ?string; public function getTitle(): ?string;

public function setTitle(string $title); public function setTitle(string $title);

public function getDescription(): ?string; public function getDescription(): ?string;

public function setDescription(?string $description); public function setDescription(?string $description);

public function getCreatedBy(): ?UserInterface; public function getCreatedBy(): ?UserInterface;

public function setCreatedBy(?UserInterface $createdBy); public function setCreatedBy(?UserInterface $createdBy);

public function getUpdatedBy(): ?UserInterface; public function getUpdatedBy(): ?UserInterface;

public function setUpdatedBy(?UserInterface $updatedBy); public function setUpdatedBy(?UserInterface $updatedBy);

public function getDevAlias(): ?string; public function getDevAlias(): ?string;

public function setDevAlias(?string $devAlias); public function setDevAlias(?string $devAlias);

public function getOrderAmountMin(): ?float; public function getOrderAmountMin(): ?float;

public function setOrderAmountMin(float $orderAmountMin): PointSaleInterface; public function setOrderAmountMin(float $orderAmountMin): PointSaleInterface;


/** /**
* @return Collection|MerchantInterface[] * @return Collection|MerchantInterface[]
*/ */
public function getMerchants(): Collection; public function getMerchants(): Collection;

public function addMerchant(MerchantInterface $merchant): PointSaleInterface; public function addMerchant(MerchantInterface $merchant): PointSaleInterface;

public function removeMerchant(MerchantInterface $merchant): PointSaleInterface; public function removeMerchant(MerchantInterface $merchant): PointSaleInterface;

public function getCode(): ?string; public function getCode(): ?string;

public function setCode(?string $code): PointSaleInterface; public function setCode(?string $code): PointSaleInterface;

public function getDeliveryPrice(): ?float; public function getDeliveryPrice(): ?float;

public function setDeliveryPrice(float $deliveryPrice): PointSaleInterface; public function setDeliveryPrice(float $deliveryPrice): PointSaleInterface;

public function getIsPublic(): ?bool; public function getIsPublic(): ?bool;

public function setIsPublic(bool $isPublic): PointSaleInterface; public function setIsPublic(bool $isPublic): PointSaleInterface;

public function getAddress(): ?AddressInterface; public function getAddress(): ?AddressInterface;

public function setAddress(AddressInterface $address): PointSaleInterface; public function setAddress(AddressInterface $address): PointSaleInterface;


/** /**
* @return Collection|UserPointSaleInterface[] * @return Collection|UserPointSaleInterface[]
*/ */
public function getUserPointSales(): Collection; public function getUserPointSales(): Collection;

public function addUserPointSale(UserPointSaleInterface $userPointSale public function addUserPointSale(UserPointSaleInterface $userPointSale
): PointSaleInterface; ): PointSaleInterface;

public function removeUserPointSale(UserPointSaleInterface $userPointSale public function removeUserPointSale(UserPointSaleInterface $userPointSale
): PointSaleInterface; ): PointSaleInterface;

public function getImage(): ?File; public function getImage(): ?File;

public function setImage(?File $image): PointSaleInterface; public function setImage(?File $image): PointSaleInterface;

public function getMetaTitle(): ?string; public function getMetaTitle(): ?string;

public function setMetaTitle(?string $metaTitle); public function setMetaTitle(?string $metaTitle);

public function getMetaDescription(): ?string; public function getMetaDescription(): ?string;

public function setMetaDescription(?string $metaDescription); public function setMetaDescription(?string $metaDescription);

public function setOldUrls($oldUrls); public function setOldUrls($oldUrls);

public function getOldUrls(): ?array; public function getOldUrls(): ?array;

public function getSlug(): ?string; public function getSlug(): ?string;

public function setSlug(?string $slug); public function setSlug(?string $slug);


/** /**
* @return $this * @return $this
*/ */
public function setPosition(float $position); public function setPosition(float $position);

public function clearPosition(); public function clearPosition();

public function getStatus(): ?float; public function getStatus(): ?float;

public function setStatus(float $status); public function setStatus(float $status);

public function getCreatedAt(): ?\DateTimeInterface; public function getCreatedAt(): ?\DateTimeInterface;

public function setCreatedAt(\DateTimeInterface $createdAt); public function setCreatedAt(\DateTimeInterface $createdAt);

public function getUpdatedAt(): ?\DateTimeInterface; public function getUpdatedAt(): ?\DateTimeInterface;

public function setUpdatedAt(\DateTimeInterface $updatedAt); public function setUpdatedAt(\DateTimeInterface $updatedAt);

/**
* @return Collection|PointSaleSectionInterface[]
*/
public function getPointSaleSections(): Collection;
public function addPointSaleSection(PointSaleSectionInterface $pointSaleSection): PointSaleInterface;
public function removePointSaleSection(PointSaleSectionInterface $pointSaleSection): PointSaleInterface;

} }

+ 36
- 2
Model/PointSale/PointSaleModel.php View File

abstract class PointSaleModel extends AbstractFullEntity implements FilterMultipleMerchantsInterface, abstract class PointSaleModel extends AbstractFullEntity implements FilterMultipleMerchantsInterface,
OrderAmountMinInterface, PointSaleInterface OrderAmountMinInterface, PointSaleInterface
{ {

use OrderAmountMinTrait; use OrderAmountMinTrait;


/** /**
*/ */
protected $image; protected $image;


/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleSectionInterface", mappedBy="pointSale", cascade={"persist"})
*/
protected $pointSaleSections;

public function __construct() public function __construct()
{ {
$this->merchants = new ArrayCollection(); $this->merchants = new ArrayCollection();
$this->userPointSales = new ArrayCollection(); $this->userPointSales = new ArrayCollection();
$this->pointSaleSections = new ArrayCollection();
} }


public function __toString() public function __toString()
return $this; return $this;
} }



public function getDeliveryPrice(): ?float public function getDeliveryPrice(): ?float
{ {
return $this->deliveryPrice; return $this->deliveryPrice;


return $this; return $this;
} }

/**
* @return Collection|PointSaleSectionInterface[]
*/
public function getPointSaleSections(): Collection
{
return $this->pointSaleSections;
}

public function addPointSaleSection(PointSaleSectionInterface $pointSaleSection): self
{
if (!$this->pointSaleSections->contains($pointSaleSection)) {
$this->pointSaleSections[] = $pointSaleSection;
$pointSaleSection->setPointSale($this);
}

return $this;
}

public function removePointSaleSection(PointSaleSectionInterface $pointSaleSection): self
{
if ($this->pointSaleSections->removeElement($pointSaleSection)) {
// set the owning side to null (unless already changed)
if ($pointSaleSection->getPointSale() === $this) {
$pointSaleSection->setPointSale(null);
}
}

return $this;
}
} }

+ 15
- 0
Model/PointSale/PointSaleSectionInterface.php View File

<?php

namespace Lc\CaracoleBundle\Model\PointSale;

use Lc\CaracoleBundle\Model\Section\SectionInterface;

interface PointSaleSectionInterface
{
public function getSection(): SectionInterface;
public function setSection(SectionInterface $section): PointSaleSectionInterface;
public function getPointSale(): PointSaleInterface;
public function setPointSale(PointSaleInterface $pointSale): PointSaleSectionInterface;
public function getOrderAmountMin(): ?float;
public function setOrderAmountMin(float $orderAmountMin): self;
}

+ 68
- 0
Model/PointSale/PointSaleSectionModel.php View File

<?php

namespace Lc\CaracoleBundle\Model\PointSale;

use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\EntityInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class PointSaleSectionModel implements EntityInterface, PointSaleSectionInterface
{
/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="pointSaleSections")
* @ORM\JoinColumn(nullable=false)
*/
protected $section;

/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface", inversedBy="pointSaleSections")
* @ORM\JoinColumn(nullable=false)
*/
protected $pointSale;


/**
* @ORM\Column(type="float", nullable=true)
*/
protected $orderAmountMin;

public function getSection(): SectionInterface
{
return $this->section;
}

public function setSection(SectionInterface $section): self
{
$this->section = $section;

return $this;
}

public function getPointSale(): PointSaleInterface
{
return $this->pointSale;
}

public function setPointSale(PointSaleInterface $pointSale): self
{
$this->pointSale = $pointSale;

return $this;
}

public function getOrderAmountMin(): ?float
{
return $this->orderAmountMin;
}

public function setOrderAmountMin(?float $orderAmountMin): self
{
$this->orderAmountMin = $orderAmountMin;

return $this;
}
}

+ 1
- 0
Model/Product/ProductCategoryModel.php View File

$parent = $this->getParent(); $parent = $this->getParent();
$title = $parent ? $parent->getTitle() . ' - ' : ''; $title = $parent ? $parent->getTitle() . ' - ' : '';
$title .= $this->getTitle(); $title .= $this->getTitle();

return $title; return $title;
} }



+ 4
- 1
Model/Product/ProductFamilyModel.php View File

const QUALITY_LABEL_AOC = 'aoc'; const QUALITY_LABEL_AOC = 'aoc';
const QUALITY_LABEL_AOP = 'aop'; const QUALITY_LABEL_AOP = 'aop';
const QUALITY_LABEL_IGP = 'igp'; const QUALITY_LABEL_IGP = 'igp';
const QUALITY_LABEL_RECUP = 'recup';


static $organicLabels = [ static $organicLabels = [
self::QUALITY_LABEL_AB, self::QUALITY_LABEL_AB,
self::QUALITY_LABEL_AOC, self::QUALITY_LABEL_AOC,
self::QUALITY_LABEL_AOP, self::QUALITY_LABEL_AOP,
self::QUALITY_LABEL_IGP, self::QUALITY_LABEL_IGP,
// @TODO : à gérer autrement
self::QUALITY_LABEL_RECUP,
]; ];


const TYPE_EXPIRATION_DATE_DLC = 'dlc'; const TYPE_EXPIRATION_DATE_DLC = 'dlc';
protected $products; protected $products;


/** /**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=true)
*/ */
protected $subtitle; protected $subtitle;



+ 8
- 0
Model/Section/SectionInterface.php View File

use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleSectionInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
public function getUpdatedAt(): ?\DateTimeInterface; public function getUpdatedAt(): ?\DateTimeInterface;


public function setUpdatedAt(\DateTimeInterface $updatedAt); public function setUpdatedAt(\DateTimeInterface $updatedAt);

/**
* @return Collection|PointSaleSectionInterface[]
*/
public function getPointSaleSections(): Collection;
public function addPointSaleSection(PointSaleSectionInterface $pointSaleSection): SectionInterface;
public function removePointSaleSection(PointSaleSectionInterface $pointSaleSection): SectionInterface;
} }

+ 53
- 0
Model/Section/SectionModel.php View File

use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleSectionInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface; use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface;
*/ */
protected $productFamilySectionProperties; protected $productFamilySectionProperties;


/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleSectionInterface", mappedBy="section")
*/
protected $pointSaleSections;

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isOnlineFrontend;

public function __construct() public function __construct()
{ {
$this->orderShops = new ArrayCollection(); $this->orderShops = new ArrayCollection();


return $this; return $this;
} }

/**
* @return Collection|PointSaleSectionInterface[]
*/
public function getPointSaleSections(): Collection
{
return $this->pointSaleSections;
}

public function addPointSaleSection(PointSaleSectionInterface $pointSaleSection): self
{
if (!$this->pointSaleSections->contains($pointSaleSection)) {
$this->pointSaleSections[] = $pointSaleSection;
$pointSaleSection->setSection($this);
}

return $this;
}

public function removePointSaleSection(PointSaleSectionInterface $pointSaleSection): self
{
if ($this->pointSaleSections->removeElement($pointSaleSection)) {
// set the owning side to null (unless already changed)
if ($pointSaleSection->getSection() === $this) {
$pointSaleSection->setSection(null);
}
}

return $this;
}

public function getIsOnlineFrontend(): ?bool
{
return $this->isOnlineFrontend;
}

public function setIsOnlineFrontend(?bool $isOnlineFrontend): self
{
$this->isOnlineFrontend = $isOnlineFrontend;

return $this;
}
} }

+ 2
- 1
Model/User/UserPointSaleModel.php View File



use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;


/** /**
* @ORM\MappedSuperclass * @ORM\MappedSuperclass
*/ */
abstract class UserPointSaleModel implements UserPointSaleInterface
abstract class UserPointSaleModel implements UserPointSaleInterface, EntityInterface
{ {
/** /**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="userPointSales") * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="userPointSales")

+ 8
- 6
Notification/MailMailjetNotification.php View File

{ {
protected MerchantResolver $merchantResolver; protected MerchantResolver $merchantResolver;


const MERCHANT = 'merchant';

public function __construct( public function __construct(
MailjetTransport $mailjetTransport, MailjetTransport $mailjetTransport,
Environment $templating, Environment $templating,


public function send($params = []) public function send($params = [])
{ {
$merchantCurrent = $this->merchantResolver->getCurrent();
$merchant = isset($params[self::MERCHANT]) ? $params[self::MERCHANT] : $this->merchantResolver->getCurrent();


$merchantConfigEmailFrom = $this->settingSolver->getSettingValue( $merchantConfigEmailFrom = $this->settingSolver->getSettingValue(
$merchantCurrent,
$merchant,
MerchantSettingDefinition::SETTING_EMAIL_FROM MerchantSettingDefinition::SETTING_EMAIL_FROM
); );
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen( $emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen(
)) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom; )) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;


$merchantConfigEmailFromName = $this->settingSolver->getSettingValue( $merchantConfigEmailFromName = $this->settingSolver->getSettingValue(
$merchantCurrent,
$merchant,
MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME
); );
$emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName;
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName;


$merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue( $merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue(
$merchantCurrent,
$merchant,
MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX
); );
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix;
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix;
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) { if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' '; $emailSubjectPrefix .= ' ';
} }

+ 2
- 3
Repository/Order/OrderProductStore.php View File



public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
if($this->section) {
$query->filterBySection($this->section);
}
$this->addFilterBySectionOptionnal($query);

return $query; return $query;
} }



+ 28
- 6
Repository/Order/OrderShopRepositoryQuery.php View File

use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface; use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
protected bool $isJoinDeliveryPointSale = false; protected bool $isJoinDeliveryPointSale = false;
protected bool $isJoinOrderPayment = false; protected bool $isJoinOrderPayment = false;
protected bool $isFilteredByStatus = false; protected bool $isFilteredByStatus = false;
protected bool $isJoinMainOrderShop = false;


public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator) public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
{ {
parent::__construct($repository, 'orderShop', $paginator); parent::__construct($repository, 'orderShop', $paginator);
} }



public function selectSumStatTotalWithTax(): self public function selectSumStatTotalWithTax(): self
{ {
return $this return $this
); );
} }



public function selectSum(): self public function selectSum(): self
{ {
$this->joinProduct(); $this->joinProduct();


public function filterIsNotComplementaryOrderShop(): self public function filterIsNotComplementaryOrderShop(): self
{ {
return $this
->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
return $this->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
} }


public function filterIsComplementaryOrderShop(): self public function filterIsComplementaryOrderShop(): self
{ {
return $this->andWhere('.mainOrderShop = true OR .mainOrderShop IS NOT NULL');
}

public function filterSectionMainOrderShop(SectionInterface $section)
{
$this->joinMainOrderShop();

return $this return $this
->andWhere('.mainOrderShop = true OR .mainOrderShop IS NOT NULL');
->andWhere('mainOrderShop.section = :sectionMainOrderShop')
->setParameter('sectionMainOrderShop', $section);
} }


public function filterIsNullMainOrderShop(): self public function filterIsNullMainOrderShop(): self
return $this->andWhere('.deliveryDate > :today')->setParameter('today', (new DateTime())->setTime(23, 59)); return $this->andWhere('.deliveryDate > :today')->setParameter('today', (new DateTime())->setTime(23, 59));
} }


public function filterHasOrderProducts()
{
return $this->andWhere('orderShop.orderProducts IS NOT EMPTY');
}

public function selectOrderReductionCarts(): self public function selectOrderReductionCarts(): self
{ {
$this->joinOrderReductionCarts(); $this->joinOrderReductionCarts();
return $this->addSelect('orderReductionCarts'); return $this->addSelect('orderReductionCarts');
} }



public function joinOrderProducts(bool $addSelect = false): self public function joinOrderProducts(bool $addSelect = false): self
{ {
if (!$this->isJoinOrderProducts) { if (!$this->isJoinOrderProducts) {
return $this; return $this;
} }


public function joinMainOrderShop(): self
{
if (!$this->isJoinMainOrderShop) {
$this->isJoinMainOrderShop = true;

return $this
->leftJoin('.mainOrderShop', 'mainOrderShop');
}
return $this;
}

} }

+ 173
- 157
Repository/Order/OrderShopStore.php View File

use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore; use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface; use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator; use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
protected OrderShopSolver $orderShopSolver; protected OrderShopSolver $orderShopSolver;
protected ReductionCartStore $reductionCartStore; protected ReductionCartStore $reductionCartStore;
protected DistributionBuilder $distributionBuilder; protected DistributionBuilder $distributionBuilder;
protected SettingSolver $settingSolver;


public function __construct( public function __construct(
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagTranslator $flashBagTranslator,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder
)
{
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagTranslator $flashBagTranslator,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder,
SettingSolver $settingSolver
) {
$this->query = $query; $this->query = $query;
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->priceSolver = $priceSolver; $this->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver; $this->orderShopSolver = $orderShopSolver;
$this->reductionCartStore = $reductionCartStore; $this->reductionCartStore = $reductionCartStore;
$this->distributionBuilder = $distributionBuilder; $this->distributionBuilder = $distributionBuilder;
$this->settingSolver = $settingSolver;
} }


public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$this $this
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);


return $query; return $query;
} }
public function getByCurrentDistribution($params = [], $query = null) public function getByCurrentDistribution($params = [], $query = null)
{ {
return $this->getBy( return $this->getBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
$this->section
),
'isValid' => true,
],
$params
),
$query
); );
} }


public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null) public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null)
{ {
return $this->getByCurrentDistribution( return $this->getByCurrentDistribution(
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
); );
} }


public function countByCurrentDistribution(array $params, $query = null) public function countByCurrentDistribution(array $params, $query = null)
{ {
return $this->countBy( return $this->countBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
$this->section
),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
); );


// @TODO : optimisation à remettre en place // @TODO : optimisation à remettre en place
public function countValidByUserAllMerchant($user, $query = null): int public function countValidByUserAllMerchant($user, $query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


public function countValidByUser(UserInterface $user = null, $query = null): int public function countValidByUser(UserInterface $user = null, $query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'user' => $user,
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'user' => $user,
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


public function countValidByCurrentDistribution($query = null): int public function countValidByCurrentDistribution($query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


// countValidOrderWithReductionCredit // countValidOrderWithReductionCredit
public function countValidWithReductionCredit( public function countValidWithReductionCredit(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int
{

ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int {
//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent //TODO vérifier que ne pas utiliser createDefaultQuery est pertinent
$query = $this->createQuery($query); $query = $this->createQuery($query);


} }


$query $query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// countValidOrderWithReductionCart // countValidOrderWithReductionCart
public function countValidWithReductionCart( public function countValidWithReductionCart(
ReductionCartInterface $reductionCart,
$query = null
): int
{
ReductionCartInterface $reductionCart,
$query = null
): int {
$query = $this->createQuery($query); $query = $this->createQuery($query);


$query $query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// countValidOrderWithReductionCartPerUser // countValidOrderWithReductionCartPerUser
public function countValidWithReductionCartByUser( public function countValidWithReductionCartByUser(
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int
{
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// findCartCurrent // findCartCurrent
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
public function getOneCartCurrent(
UserInterface $user = null,
VisitorInterface $visitor = null,
$query = null
): ?OrderShopInterface {
if (is_null($user) && is_null($visitor)) { if (is_null($user) && is_null($visitor)) {
return null; return null;
} }
} }


$query $query
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);


return $query->findOne(); return $query->findOne();
} }


// findLastOrderValidOfWeek // findLastOrderValidOfWeek
//getOneLastValidByCycle //getOneLastValidByCycle
public function getOneLastValidByDistribution(DistributionInterface $distribution, $query = null): ?OrderShopInterface
{
public function getOneLastValidByDistribution(
DistributionInterface $distribution,
$query = null
): ?OrderShopInterface {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');


return $query->findOne(); return $query->findOne();
} }
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');


return $query->findOne(); return $query->findOne();
} }


$orderShops = $query->find(); $orderShops = $query->find();


if (isset($params['mergeComplementaryOrderShops'])) {
if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'] == true) {
$mergeComplementaryOrderShopsSameSection = isset($params['mergeComplementaryOrderShopsSameSection'])
? $params['mergeComplementaryOrderShopsSameSection'] : false;
foreach ($orderShops as $orderShop) { foreach ($orderShops as $orderShop) {
$this->orderShopSolver->mergeComplentaryOrderShops($orderShop);
$this->orderShopSolver->mergeComplentaryOrderShops($orderShop, true, $mergeComplementaryOrderShopsSameSection);
} }
} }


$query->filterMinimumTomorrowDelivery(); $query->filterMinimumTomorrowDelivery();
} }


if (isset($params['mergeComplementaryOrderShops'])) {
if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops']) {
$query $query
->joinComplementaryOrderShops();
->joinComplementaryOrderShops();
} }


if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {
if (isset($params['isComplementaryOrderShop']) && $params['isComplementaryOrderShop']) {
$query->filterIsComplementaryOrderShop();

if(isset($params['sectionMainOrderShop']) && $params['sectionMainOrderShop']) {
$query->filterSectionMainOrderShop($params['sectionMainOrderShop']);
}
}

if ((isset($params['excludeComplementaryOrderShops']) && $params['excludeComplementaryOrderShops'])
|| (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'])) {
$query->filterIsNullMainOrderShop(); $query->filterIsNullMainOrderShop();
} }


} }


public function isReductionCreditUsed( public function isReductionCreditUsed(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
)
{
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
) {
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) { if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
return true; return true;
} else { } else {
public function getReductionCreditsAvailableByUser(UserInterface $user): array public function getReductionCreditsAvailableByUser(UserInterface $user): array
{ {
$reductionCredits = $this->reductionCreditStore $reductionCredits = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);


$reductionCreditsArray = []; $reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) { foreach ($reductionCredits as $reductionCredit) {
public function getReductionGiftsAvailableByUser(UserInterface $user): array public function getReductionGiftsAvailableByUser(UserInterface $user): array
{ {
$reductionGifts = $this->reductionCreditStore $reductionGifts = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);


$reductionGiftsArray = []; $reductionGiftsArray = [];
foreach ($reductionGifts as $reductionGift) { foreach ($reductionGifts as $reductionGift) {
public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float
{ {
return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart( return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart(
$reductionCart
);
$reductionCart
);
} }


// getReductionCartUsedQuantityPerUser // getReductionCartUsedQuantityPerUser
public function getReductionCartUsedQuantityByUser( public function getReductionCartUsedQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
return $this->countValidWithReductionCartByUser($reductionCart, $user); return $this->countValidWithReductionCartByUser($reductionCart, $user);
} }




// getReductionCartRemainingQuantityPerUser // getReductionCartRemainingQuantityPerUser
public function getReductionCartRemainingQuantityByUser( public function getReductionCartRemainingQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
if ($reductionCart->getAvailableQuantityPerUser()) { if ($reductionCart->getAvailableQuantityPerUser()) {
return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser( return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser(
$reductionCart,
$user
);
$reductionCart,
$user
);
} }


return false; return false;
public function getReductionCartAvailableByUser(UserInterface $user, $query = null) public function getReductionCartAvailableByUser(UserInterface $user, $query = null)
{ {
$reductionCarts = $this->reductionCartStore $reductionCarts = $this->reductionCartStore
->setMerchant($this->merchant)
->getOnline();
->setMerchant($this->merchant)
->getOnline();


$reductionCartsArray = []; $reductionCartsArray = [];
foreach ($reductionCarts as $reductionCart) { foreach ($reductionCarts as $reductionCart) {
if ($this->reductionCartSolver->matchWithUser($reductionCart, $user) if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {

&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
$reductionCartsArray[] = $reductionCart; $reductionCartsArray[] = $reductionCart;
} }
} }


//countValidOrderProductsOfCyclesByProducts //countValidOrderProductsOfCyclesByProducts
public function countValidOrderProductsOfDistributionsByProducts( public function countValidOrderProductsOfDistributionsByProducts(
array $distributions,
array $products,
$query = null
): array
{
array $distributions,
array $products,
$query = null
): array {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query $query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');




return $query->find(); return $query->find();
} }


//countValidOrderProductsOfCycleByProduct //countValidOrderProductsOfCycleByProduct
public function countValidOrderProductsOfDistributionByProduct(DistributionInterface $distribution, ProductInterface $product, $query = null): ?string
{
public function countValidOrderProductsOfDistributionByProduct(
DistributionInterface $distribution,
ProductInterface $product,
$query = null
): ?string {
//TODO attention à vérifier //TODO attention à vérifier
$query = $this->createQuery($query); $query = $this->createQuery($query);


$query $query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');


$result = $query->findOne(); $result = $query->findOne();


} }


public function isReductionCreditAllowAddToOrder( public function isReductionCreditAllowAddToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
)
{
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
$user = $orderShop->getUser(); $user = $orderShop->getUser();


// appartient à l'utilisateur // appartient à l'utilisateur

+ 5
- 0
Repository/PointSale/PointSaleRepositoryQuery.php View File

} }
return $this; return $this;
} }

public function innerJoinDeliveryAvailabilityPointSale()
{
return $this->innerJoin('.deliveryAvailabilityPointSale');
}
} }

+ 15
- 0
Repository/PointSale/PointSaleSectionRepository.php View File

<?php

namespace Lc\CaracoleBundle\Repository\PointSale;

use App\Entity\PointSale\PointSaleSection;
use Doctrine\Persistence\ManagerRegistry;
use Lc\SovBundle\Repository\AbstractRepository;

class PointSaleSectionRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PointSaleSection::class);
}
}

+ 23
- 0
Repository/PointSale/PointSaleSectionRepositoryQuery.php View File

<?php

namespace Lc\CaracoleBundle\Repository\PointSale;

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class PointSaleSectionRepositoryQuery extends AbstractRepositoryQuery
{
use SectionRepositoryQueryTrait;

public function __construct(PointSaleSectionRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'pointSaleSection', $paginator);
}

public function filterByPointSale(PointSaleInterface $pointSale): self
{
return $this->andWhereEqual('pointSale', $pointSale);
}
}

+ 43
- 0
Repository/PointSale/PointSaleSectionStore.php View File

<?php

namespace Lc\CaracoleBundle\Repository\PointSale;

use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

class PointSaleSectionStore extends AbstractStore
{
use SectionStoreTrait;

protected PointSaleSectionRepositoryQuery $query;

public function __construct(PointSaleSectionRepositoryQuery $query)
{
$this->query = $query;
}

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$this->addFilterBySectionOptionnal($query);
return $query;
}

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
return $query;
}

public function getOneByPointSale(PointSaleInterface $pointSale, $query = null)
{
$query = $this->createDefaultQuery($query);
$query->filterByPointSale($pointSale);
return $query->findOne();
}
}

+ 1
- 1
Repository/PointSale/PointSaleStore.php View File



public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->filterByMerchant($this->merchant);
$this->addFilterByMerchantOptionnal($query);
return $query; return $query;
} }



+ 0
- 2
Repository/Product/ProductCategoryRepositoryQuery.php View File

return $this; return $this;
} }




public function hasProductFamilyOnline(): self public function hasProductFamilyOnline(): self
{ {
$this->joinProductFamilies(); $this->joinProductFamilies();

+ 1
- 1
Repository/Product/ProductCategoryStore.php View File



public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->orderBy('position');
$query->addOrderBy('.parent')->addOrderBy('.position');
return $query; return $query;
} }



+ 1
- 1
Repository/Product/ProductFamilyRepositoryQuery.php View File

return $this->andWhereEqual('supplier', $supplier); return $this->andWhereEqual('supplier', $supplier);
} }


public function joinProductCategories(bool $addSelect = false): self
public function joinProductCategories(bool $addSelect = true): self
{ {
if (!$this->isJoinProductCategories) { if (!$this->isJoinProductCategories) {
$this->isJoinProductCategories = true; $this->isJoinProductCategories = true;

+ 1
- 0
Repository/Product/ProductFamilyStore.php View File

'ids' => [], 'ids' => [],
'categories' => [], 'categories' => [],
]; ];

foreach ($productFamilies as $productFamily) { foreach ($productFamilies as $productFamily) {
$conditions['ids'][] = $productFamily->getId(); $conditions['ids'][] = $productFamily->getId();
$conditions['categories'] = array_merge( $conditions['categories'] = array_merge(

+ 2
- 2
Repository/Reduction/ReductionCreditRepositoryQuery.php View File

public function filterInactive() public function filterInactive()
{ {
$this->joinUsers(); $this->joinUsers();
return $this->having('COUNT(users.id) = 0');
return $this->andWhere('.users IS EMPTY');
} }


public function filterActive() public function filterActive()
{ {
$this->joinUsers(); $this->joinUsers();
return $this->having('COUNT(users.id) > 0');
return $this->andWhere('.users IS NOT EMPTY');
} }


public function joinUsers() public function joinUsers()

+ 5
- 1
Repository/Section/SectionRepositoryQuery.php View File

return $this->andWhereEqual('isDefault', $isDefault); return $this->andWhereEqual('isDefault', $isDefault);
} }



public function filterIsOnlineFrontend()
{
return $this->filterIsOnline()
&& $this->andWhereEqual('isOnlineFrontend', true);
}


} }

+ 6
- 0
Repository/Section/SectionStore.php View File

// @TODO : à implémenter avec le nouveau système d'ouverture des commandes // @TODO : à implémenter avec le nouveau système d'ouverture des commandes
} }


public function getOnlineFrontend($query = null)
{
$query = $this->createDefaultQuery($query);
$query->filterIsOnlineFrontend();
return $query->find();
}


} }

+ 18
- 2
Resolver/MerchantResolver.php View File

$merchant = $this->getCurrent(); $merchant = $this->getCurrent();
} }


//TODO Pas de REPO !!!!!
// @TODO Pas de REPO !!!!!
return $this->userMerchantRepository->findOneBy( return $this->userMerchantRepository->findOneBy(
[ [
'user' => $user, 'user' => $user,
); );
} }


public function getAbsoluteUrl(MerchantInterface $merchant, string $name, array $parameters = []): string
{
$url = $this->settingSolver->getSettingValue($merchant, MerchantSettingDefinition::SETTING_URL);

if(substr($url, strlen($url) - 1, 1) == '/') {
$url = substr($url, 0, strlen($url) - 1);
}

return $url . $this->router->generate($name, $parameters);
}

public function getUrl(SectionInterface $section) public function getUrl(SectionInterface $section)
{ {
$url = $this->settingSolver->getSettingValue($section->getMerchant(), MerchantSettingDefinition::SETTING_URL); $url = $this->settingSolver->getSettingValue($section->getMerchant(), MerchantSettingDefinition::SETTING_URL);
$url .= $section->getSlug(); $url .= $section->getSlug();
} }


return$url;
return $url;
}

public function getUrlAdmin(MerchantInterface $merchant)
{
return $this->settingSolver->getSettingValue($merchant, MerchantSettingDefinition::SETTING_URL).'admin';
} }


public function getMerchantUser(UserInterface $user = null) public function getMerchantUser(UserInterface $user = null)

+ 31
- 5
Resolver/OpeningResolver.php View File



namespace Lc\CaracoleBundle\Resolver; namespace Lc\CaracoleBundle\Resolver;


use App\Entity\Section\Section;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Model\Section\OpeningInterface; use Lc\CaracoleBundle\Model\Section\OpeningInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionModel;
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
use Lc\CaracoleBundle\Repository\Section\OpeningStore; use Lc\CaracoleBundle\Repository\Section\OpeningStore;
use Lc\CaracoleBundle\Solver\Section\OpeningSolver; use Lc\CaracoleBundle\Solver\Section\OpeningSolver;
} }


// isHolidays // isHolidays
public function isClosingPeriod(SectionInterface $section = null)
public function isClosingPeriod(SectionInterface $section = null, \DateTime $date = null)
{ {
if (is_null($section)) { if (is_null($section)) {
$section = $this->sectionResolver->getCurrent(); $section = $this->sectionResolver->getCurrent();
} }


$date = new \DateTime();
if(is_null($date)) {
$date = new \DateTime();
}


$orderClosedStart = $this->settingSolver->getSettingValue( $orderClosedStart = $this->settingSolver->getSettingValue(
$section, $section,
SectionSettingDefinition::SETTING_ORDER_CLOSED_START SectionSettingDefinition::SETTING_ORDER_CLOSED_START
); );

$orderClosedEnd = $this->settingSolver->getSettingValue( $orderClosedEnd = $this->settingSolver->getSettingValue(
$section, $section,
SectionSettingDefinition::SETTING_ORDER_CLOSED_END SectionSettingDefinition::SETTING_ORDER_CLOSED_END
} }


$date = new \DateTime(); $date = new \DateTime();
if($this->isClosingPeriod($section)) {
$date = $this->settingSolver->getSettingValue(
$section,
SectionSettingDefinition::SETTING_ORDER_CLOSED_END
);
}

$openingArray = $this->openingStore $openingArray = $this->openingStore
->setSection($section) ->setSection($section)
->get(); ->get();
return ''; return '';
} }


public function isOpenSaleOnlyComplementaryOrders(Section $section = null, UserInterface $user = null)
public function isOpenSaleOnlyComplementaryOrders(SectionInterface $section = null, UserInterface $user = null)
{ {
if (is_null($section)) { if (is_null($section)) {
$section = $this->sectionResolver->getCurrent(); $section = $this->sectionResolver->getCurrent();
&& count($orderShopsUser) > 0; && count($orderShopsUser) > 0;
} }


public function getMessageOpeningNextSale(SectionInterface $section): ?string
{
$openingTextClosed = $this->settingSolver->getSettingValue(
$section,
SectionSettingDefinition::SETTING_OPENING_TEXT_CLOSED
);
if ($openingTextClosed && strlen($openingTextClosed) > 0) {
return $openingTextClosed ;
}

$dateOpeningNextSale = $this->getFormatedDateOpeningNextSale($section);
if ($dateOpeningNextSale && strlen($dateOpeningNextSale) > 0) {
return 'Réouverture aux commandes le <u>'.$dateOpeningNextSale.'</u>' ;
}

return null;
}

public function getMessages(): array public function getMessages(): array
{ {
return $this->messages; return $this->messages;

+ 14
- 1
Resources/translations/admin.fr.yaml View File





flash_message: flash_message:
success:
duplicateToOtherMerchant: "Le document a bien été dupliqué sur le marchand : %merchant%"
error: error:
formValidation: Une erreur est survenue lors de la soumission du formulaire formValidation: Une erreur est survenue lors de la soumission du formulaire

settings_saved: Paramètres mis à jour settings_saved: Paramètres mis à jour
duplicateToOtherMerchant: "Le document a bien été dupliqué sur le marchand : %merchant%"
duplicateToOtherSection: "Le document a bien été dupliqué sur la section : %section%" duplicateToOtherSection: "Le document a bien été dupliqué sur la section : %section%"


action: action:
code: Code code: Code
code_help: Code utilisé pour retrouver l'ambassade dans le tunnel de commande (Non sensible à la casse) code_help: Code utilisé pour retrouver l'ambassade dans le tunnel de commande (Non sensible à la casse)
image: Image image: Image
pointSaleSections: Sections

PointSaleSection:
fields:
orderAmountMin: Montant minimum de commande


Address: Address:
fields: fields:
Merchant: Merchant:
label: Marchand label: Marchand
label_plurial: Marchands label_plurial: Marchands

Section: Section:
label: Section label: Section
label_plurial: Sections label_plurial: Sections
cycle: Cycle de vente cycle: Cycle de vente
isDefault: Section par défaut isDefault: Section par défaut
cycleType: Cycle cycleType: Cycle
isOnlineFrontend: Visible sur le site

TaxRate: TaxRate:
label: Règle de taxe label: Règle de taxe
label_plurial: Règles de taxes label_plurial: Règles de taxes
label: Catégorie label: Catégorie
label_plurial: Catégories label_plurial: Catégories
ProductFamily: ProductFamily:
flashes:
success:
duplicateToOtherMerchant: Duplication du produit sur un autre marchand réussie
fields: fields:
priceWithTax: Prix de vente priceWithTax: Prix de vente
sales: Historique des ventes sales: Historique des ventes

+ 20
- 1
Resources/views/admin/order/field/complementary.html.twig View File

{% set value = entity.instance.complementaryOrderShops|length %}
{% set order_shop = entity.instance %}
{% set main_order_shop = entity.instance.mainOrderShop %}
{% if main_order_shop is defined and main_order_shop is not null %}
{% if order_shop.getSection() != main_order_shop.getSection() or section_container.solver.isSectionWithdrawal(order_shop.getSection()) %}
<span class="badge badge-warning section-{{ main_order_shop.getSection().getDevAlias() }}">
Complément {{ main_order_shop.getSection() }}
</span>
{% else %}
<span class="badge badge-warning">Complément</span>
{% endif %}
{% else %}
<span class="badge badge-secondary">Principale</span>
{% set complementary_order_shops = entity.instance.complementaryOrderShops %}
{% if complementary_order_shops and complementary_order_shops|length > 0 %}
<span class="badge badge-success section-{{ order_shop.getSection().getDevAlias() }}">{{ complementary_order_shops|length}} complément{% if complementary_order_shops|length > 1 %}s{% endif %}</span>
{% endif %}
{% endif %}

{# {% set value = entity.instance.complementaryOrderShops|length %}
{% if value > 0 %} {% if value > 0 %}
<span class="badge badge-success"> <span class="badge badge-success">
{{ value|length }} compléments {{ value|length }} compléments
non non
</span> </span>
{% endif %} {% endif %}
#}

+ 5
- 1
Resources/views/admin/order/field/distribution.html.twig View File

{% endif %} {% endif %}
{% endif %} {% endif %}


{{ labelCycleType ~ distribution.cycleNumber }}A{{ distribution.year|slice(2,2) }}
{% if cycleType == "year" %}
A{{ distribution.cycleNumber }}
{% else %}
{{ labelCycleType ~ distribution.cycleNumber }}A{{ distribution.year|slice(2,2) }}
{% endif %}

+ 5
- 8
Solver/Config/UnitSolver.php View File



namespace Lc\CaracoleBundle\Solver\Config; namespace Lc\CaracoleBundle\Solver\Config;




use Lc\CaracoleBundle\Model\Config\UnitInterface; use Lc\CaracoleBundle\Model\Config\UnitInterface;


class UnitSolver class UnitSolver
{ {
public function getWeight(UnitInterface $unit, int $quantityProduct, ?int $quantity){
if($quantity) {
public function getWeight(UnitInterface $unit, float $quantityProduct, ?float $quantity)
{
if ($quantity) {
return ($quantityProduct / $unit->getCoefficient()) * $quantity; return ($quantityProduct / $unit->getCoefficient()) * $quantity;
}else{
}
else {
return 0; return 0;
} }
} }


} }

+ 76
- 67
Solver/Order/OrderShopSolver.php View File

use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface; use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver; use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver; use Lc\CaracoleBundle\Solver\Product\ProductSolver;


protected ProductSolver $productSolver; protected ProductSolver $productSolver;


public function __construct( public function __construct(
EntityManagerInterface $entityManager,
ProductSolver $productSolver
EntityManagerInterface $entityManager,
ProductSolver $productSolver
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->productSolver = $productSolver; $this->productSolver = $productSolver;
public static function getTypeDeliveryChoices() public static function getTypeDeliveryChoices()
{ {
return [ return [
OrderShopModel::DELIVERY_TYPE_HOME,
OrderShopModel::DELIVERY_TYPE_POINTSALE,
OrderShopModel::DELIVERY_TYPE_HOME,
OrderShopModel::DELIVERY_TYPE_POINTSALE,
]; ];
} }




// getOrderProductsByProductFamily // getOrderProductsByProductFamily
public function getOrderProductsByProductFamily( public function getOrderProductsByProductFamily(
OrderShopInterface $orderShop,
ProductFamilyInterface $productFamily
OrderShopInterface $orderShop,
ProductFamilyInterface $productFamily
): array { ): array {
$arrayOrderProducts = []; $arrayOrderProducts = [];


} }


public function getQuantityOrderByProduct( public function getQuantityOrderByProduct(
OrderShopInterface $orderShop,
ProductInterface $product,
$byWeight = false
OrderShopInterface $orderShop,
ProductInterface $product,
$byWeight = false
): int { ): int {
$quantity = 0; $quantity = 0;
$productFamily = $product->getProductFamily(); $productFamily = $product->getProductFamily();


foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $product->getId() if ($orderProduct->getProduct()->getId() == $product->getId()
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {
if ($byWeight) { if ($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct( $quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct(
) / $this->productSolver->getUnitInherited($orderProduct->getProduct())->getCoefficient());
) / $this->productSolver->getUnitInherited(
$orderProduct->getProduct()
)->getCoefficient());
} else { } else {
$quantity += $orderProduct->getQuantityOrder(); $quantity += $orderProduct->getQuantityOrder();
} }


// isProductAvailable // isProductAvailable
public function isProductAvailable( public function isProductAvailable(
ProductInterface $product,
$quantityOrder = 0,
$checkCart = false,
$orderShop
SectionInterface $section,
OrderShopInterface $orderShop,
ProductInterface $product,
int $quantityOrder = 0,
bool $checkCart = false
) { ) {
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus( if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus(
) != 1 || !$this->productSolver->isProductSaleStatusOn($product)) {
) != 1 || !$this->productSolver->isProductSaleStatusOn($product)) {
return false; return false;
} }


if ($checkCart && !$orderShop) {
throw new \Exception("Attention : définir le orderShop à l'endroit où est appelé isAvailable");
}

$productFamily = $product->getProductFamily(); $productFamily = $product->getProductFamily();
$quantityAsked = $quantityOrder; $quantityAsked = $quantityOrder;


if (!$quantityOrder) { if (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true); $quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true);
} else { } else {
$quantityAsked = ($this->productSolver->getQuantityInherited(
$product
) / $this->productSolver->getUnitInherited($product)->getCoefficient()) * $quantityOrder;
$quantityAsked = ($this->productSolver->getQuantityInherited($product)
/ $this->productSolver->getUnitInherited($product)->getCoefficient()) * $quantityOrder;
} }


if ($checkCart) { if ($checkCart) {
} }


if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {
if (!$quantityOrder) { if (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product); $quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product);
} }
public function isOneProductAvailableAddCart(OrderShopInterface $orderShop, $products): bool public function isOneProductAvailableAddCart(OrderShopInterface $orderShop, $products): bool
{ {
foreach ($products as $product) { foreach ($products as $product) {
if ($this->isProductAvailable($product, 1, true, $orderShop)) {
if ($this->isProductAvailable($orderShop->getSection(), $orderShop, $product, 1, true)) {
return true; return true;
} }
} }
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, OrderShopInterface $orderShop) public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, OrderShopInterface $orderShop)
{ {
return $this->isProductAvailable( return $this->isProductAvailable(
$orderProduct->getProduct(),
$orderProduct->getQuantityOrder(),
true,
$orderShop
$orderShop->getSection(),
$orderShop,
$orderProduct->getProduct(),
1,
true
); );
} }


} }


public function mergeComplentaryOrderShops( public function mergeComplentaryOrderShops(
OrderShopInterface $orderShop,
bool $combineProducts = true
OrderShopInterface $orderShop,
bool $combineProducts = true,
bool $onlySameSection = false
): OrderShopInterface { ): OrderShopInterface {
$this->entityManager->refresh($orderShop); $this->entityManager->refresh($orderShop);


if ($this->getValidComplementaryOrderShops($orderShop)) { if ($this->getValidComplementaryOrderShops($orderShop)) {
foreach ($this->getValidComplementaryOrderShops($orderShop) as $complementaryOrderShop) { foreach ($this->getValidComplementaryOrderShops($orderShop) as $complementaryOrderShop) {
foreach ($complementaryOrderShop->getOrderProducts() as $orderProductAdd) {
$updated = false;
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($combineProducts && $orderProduct->getProduct()->getId() == $orderProductAdd->getProduct(
)->getId()
&& (string)$orderProduct->getPrice() == (string)$orderProductAdd->getPrice()
) {
$orderProduct->setUpdatedOnMergeComplementaryOrderShop(true);
$orderProduct->setQuantityOrder(
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
);

$updated = true;

if (!$onlySameSection || $complementaryOrderShop->getSection()->getId()
== $orderShop->getSection()->getId()) {

// @TODO : obligatoire sinon un seul orderProduct de présent
$this->entityManager->refresh($complementaryOrderShop);

foreach ($complementaryOrderShop->getOrderProducts() as $orderProductAdd) {
$updated = false;
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($combineProducts && $orderProduct->getProduct()->getId(
) == $orderProductAdd->getProduct()->getId()
&& (string)$orderProduct->getPrice() == (string)$orderProductAdd->getPrice()
) {
$orderProduct->setUpdatedOnMergeComplementaryOrderShop(true);
$orderProduct->setQuantityOrder(
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
);

$updated = true;
}
} }
}


if (!$updated) {
$orderProductAdd->setOnMergeComplementaryOrderShop($complementaryOrderShop);
$orderProductAdd->setCreatedOnMergeComplementaryOrderShop(true);
$orderShop->addOrderProduct($orderProductAdd);
if (!$updated) {
$orderProductAdd->setOnMergeComplementaryOrderShop($complementaryOrderShop);
$orderProductAdd->setCreatedOnMergeComplementaryOrderShop(true);
$orderShop->addOrderProduct($orderProductAdd);
}
} }
} }
} }
} }


public function isReductionCreditAddedToOrder( public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) { ) {
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) { if ($orderReductionCredit->getReductionCredit() == $reductionCredit) {




public function hasOrderProductAlreadyInCart( public function hasOrderProductAlreadyInCart(
OrderShopInterface $orderShop,
OrderProductInterface $orderProductTest
OrderShopInterface $orderShop,
OrderProductInterface $orderProductTest
): ?OrderProductInterface { ): ?OrderProductInterface {
foreach ($orderShop->getOrderProducts() as $orderProduct) { foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct() == $orderProductTest->getProduct()) { if ($orderProduct->getProduct() == $orderProductTest->getProduct()) {
public function isValid(OrderShopInterface $orderShop): bool public function isValid(OrderShopInterface $orderShop): bool
{ {
if ($orderShop->getOrderStatus() && in_array( if ($orderShop->getOrderStatus() && in_array(
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsValid
) > 0) {
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsValid
) > 0) {
return true; return true;
} }


public function isCart(OrderShopInterface $orderShop): bool public function isCart(OrderShopInterface $orderShop): bool
{ {
if ($orderShop->getOrderStatus() && in_array( if ($orderShop->getOrderStatus() && in_array(
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsCart
) > 0) {
$orderShop->getOrderStatus()->getAlias(),
OrderStatusModel::$statusAliasAsCart
) > 0) {
return true; return true;
} }




public function isDone(OrderShopInterface $orderShop): bool public function isDone(OrderShopInterface $orderShop): bool
{ {
if ($orderShop->getOrderStatus() && $orderShop->getOrderStatus()->getAlias() == OrderStatusModel::ALIAS_DONE ) {
if ($orderShop->getOrderStatus() && $orderShop->getOrderStatus()->getAlias() == OrderStatusModel::ALIAS_DONE) {
return true; return true;
} }
return false; return false;
} }


return max( return max(
$this->productSolver->getAvailableQuantityInherited($product) - $this->getQuantityOrderByProduct(
$orderShop,
$product,
$byWeight
),
0
$this->productSolver->getAvailableQuantityInherited($product) - $this->getQuantityOrderByProduct(
$orderShop,
$product,
$byWeight
),
0
); );
} }



+ 16
- 2
Solver/PointSale/PointSaleSolver.php View File

<?php <?php



namespace Lc\CaracoleBundle\Solver\PointSale; namespace Lc\CaracoleBundle\Solver\PointSale;



use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;


class PointSaleSolver class PointSaleSolver
{ {


return $html; return $html;
} }

public function getOrderAmountMin(PointSaleInterface $pointSale, SectionInterface $section)
{
foreach($pointSale->getPointSaleSections() as $pointSaleSection) {
if($pointSaleSection->getSection()->getId() == $section->getId()) {
$orderAmountMin = $pointSaleSection->getOrderAmountMin();

if(!is_null($orderAmountMin)) {
return $orderAmountMin;
}
}
}

return $pointSale->getOrderAmountMin();
}
} }

+ 4
- 6
Solver/Product/ProductFamilySolver.php View File



class ProductFamilySolver class ProductFamilySolver
{ {

protected ProductSolver $productSolver; protected ProductSolver $productSolver;
protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver; protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
protected ProductCategorySolver $productCategorySolver; protected ProductCategorySolver $productCategorySolver;
$this->productCategorySolver = $productCategorySolver; $this->productCategorySolver = $productCategorySolver;
} }



public static function getBehaviorCountStockChoices(): array public static function getBehaviorCountStockChoices(): array
{ {
return [ return [
return $productsOnlineArray; return $productsOnlineArray;
} }



public function getReductionCatalogInherited(ProductFamilyInterface $productFamily): ?ReductionCatalogInterface public function getReductionCatalogInherited(ProductFamilyInterface $productFamily): ?ReductionCatalogInterface
{ {
return $productFamily->getReductionCatalog(); return $productFamily->getReductionCatalog();
} }



public function getProductCategoryParent(ProductFamilyInterface $productFamily, SectionInterface $section) public function getProductCategoryParent(ProductFamilyInterface $productFamily, SectionInterface $section)
{ {
$productCategories = $productFamily->getProductCategories(); $productCategories = $productFamily->getProductCategories();


if (count($productCategories) > 0) { if (count($productCategories) > 0) {

foreach ($productCategories as $productCategory) { foreach ($productCategories as $productCategory) {
if($productCategory->getSection() === $section && $productCategory->getParent()!==null){
if($productCategory->getSection()->getId() == $section->getId()
&& $productCategory->getParent() !== null) {

return $productCategory->getParent(); return $productCategory->getParent();
} }
} }

} }


return false; return false;

+ 8
- 4
Statistic/Product/ProductsSalesStatistic.php View File



namespace Lc\CaracoleBundle\Statistic\Product; namespace Lc\CaracoleBundle\Statistic\Product;


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Builder\Distribution\DistributionBuilder; use Lc\CaracoleBundle\Builder\Distribution\DistributionBuilder;
use Lc\CaracoleBundle\Container\Order\OrderShopContainer; use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
// Initialise les valeurs des données pour chaque Interval de date // Initialise les valeurs des données pour chaque Interval de date
public function init(SectionInterface $section, DistributionBuilder $distributionBuilder) public function init(SectionInterface $section, DistributionBuilder $distributionBuilder)
{ {
$this->distributionList = $distributionBuilder->getDistributionListFromCurrentOrder($section, $this->nbCycle);
$distributionArray = $distributionBuilder->getDistributionListFromCurrentOrder($section, $this->nbCycle);
$this->distributionList = $distributionArray->toArray();


// if ($openingResolver->isOpenSale($section, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) {
// $currentCycleNumber = $currentCycleNumber - 1;
// }
// @TODO : à retravailler pour inclure cette logique directement dans getDistributionListFromCurrentOrder()
$distributionCurrentOrder = $distributionBuilder->guessCurrentDistributionOrder($section);
if(!$distributionArray->contains($distributionCurrentOrder)) {
array_unshift($this->distributionList, $distributionCurrentOrder);
}


foreach ($this->distributionList as $distribution){ foreach ($this->distributionList as $distribution){
$this->labels[$this->getKey($distribution->getCycleNumber(),$distribution->getYear())] = $distribution->getCycleNumber(); $this->labels[$this->getKey($distribution->getCycleNumber(),$distribution->getYear())] = $distribution->getCycleNumber();

+ 1
- 1
Twig/FormTwigExtension.php View File

SwitchSectionFormType::class, SwitchSectionFormType::class,
null, null,
[ [
'action' => $this->urlGenerator->generate('carac_section_switch'),
'action' => $this->urlGenerator->generate('admin_section_switch'),
'attr' => ['class' => 'switch-section'], 'attr' => ['class' => 'switch-section'],
'section' => $section, 'section' => $section,
] ]

+ 1
- 1
Twig/StoreTwigExtension.php View File

return $this->merchantResolver->getUserMerchant(); return $this->merchantResolver->getUserMerchant();
} }


public function getMerchantSetting(MerchantInterface $merchant, string $settingName): string
public function getMerchantSetting(MerchantInterface $merchant, string $settingName): ?string
{ {
return $this->settingSolver->getSettingValue($merchant, $settingName); return $this->settingSolver->getSettingValue($merchant, $settingName);
} }

Loading…
Cancel
Save