Browse Source

OrderShopStore : gestion param mergeComplementaryOrderShopsSameSection

packProduct
Guillaume 2 years ago
parent
commit
532bd9f3c4
2 changed files with 31 additions and 21 deletions
  1. +3
    -1
      Repository/Order/OrderShopStore.php
  2. +28
    -20
      Solver/Order/OrderShopSolver.php

+ 3
- 1
Repository/Order/OrderShopStore.php View File

@@ -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);
}
}


+ 28
- 20
Solver/Order/OrderShopSolver.php View File

@@ -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);
}
}
}
}

Loading…
Cancel
Save