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) | ||||
{ | { | ||||
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 = :section') | |||||
->setParameter('section', $section); | |||||
} | } | ||||
public function filterIsNullMainOrderShop(): self | public function filterIsNullMainOrderShop(): self | ||||
return $this; | return $this; | ||||
} | } | ||||
public function joinMainOrderShop(): self | |||||
{ | |||||
if (!$this->isJoinMainOrderShop) { | |||||
$this->isJoinMainOrderShop = true; | |||||
return $this | |||||
->leftJoin('.mainOrderShop', 'mainOrderShop'); | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
$orderShops = $query->find(); | $orderShops = $query->find(); | ||||
if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'] == true) { | 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); | |||||
} | } | ||||
} | } | ||||
->joinComplementaryOrderShops(); | ->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']) | if ((isset($params['excludeComplementaryOrderShops']) && $params['excludeComplementaryOrderShops']) | ||||
|| (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'])) { | || (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'])) { | ||||
$query->filterIsNullMainOrderShop(); | $query->filterIsNullMainOrderShop(); |
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 mergeComplentaryOrderShops( | public function mergeComplentaryOrderShops( | ||||
OrderShopInterface $orderShop, | OrderShopInterface $orderShop, | ||||
bool $combineProducts = true | |||||
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); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |