Parcourir la source

Merge branch 'develop'

master
Guillaume il y a 2 ans
Parent
révision
16ad18d750
3 fichiers modifiés avec 62 ajouts et 24 suppressions
  1. +23
    -3
      Repository/Order/OrderShopRepositoryQuery.php
  2. +11
    -1
      Repository/Order/OrderShopStore.php
  3. +28
    -20
      Solver/Order/OrderShopSolver.php

+ 23
- 3
Repository/Order/OrderShopRepositoryQuery.php Voir le fichier

@@ -9,6 +9,7 @@ use Lc\CaracoleBundle\Model\Order\OrderPaymentInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface;
@@ -32,6 +33,7 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
protected bool $isJoinDeliveryPointSale = false;
protected bool $isJoinOrderPayment = false;
protected bool $isFilteredByStatus = false;
protected bool $isJoinMainOrderShop = false;

public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
{
@@ -267,14 +269,21 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery

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
{
return $this->andWhere('.mainOrderShop = true OR .mainOrderShop IS NOT NULL');
}

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

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

public function filterIsNullMainOrderShop(): self
@@ -435,4 +444,15 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
return $this;
}

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

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

}

+ 11
- 1
Repository/Order/OrderShopStore.php Voir le fichier

@@ -371,8 +371,10 @@ class OrderShopStore extends AbstractStore
$orderShops = $query->find();

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

@@ -442,6 +444,14 @@ class OrderShopStore extends AbstractStore
->joinComplementaryOrderShops();
}

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();

+ 28
- 20
Solver/Order/OrderShopSolver.php Voir le fichier

@@ -149,7 +149,6 @@ class OrderShopSolver

if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {

if (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product);
}
@@ -261,32 +260,41 @@ class OrderShopSolver

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

if ($this->getValidComplementaryOrderShops($orderShop)) {
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);
}
}
}
}

Chargement…
Annuler
Enregistrer