|
|
@@ -65,7 +65,6 @@ class OrderUtils |
|
|
|
|
|
|
|
public function getCartCurrent() |
|
|
|
{ |
|
|
|
|
|
|
|
$paramsSearchOrderShop = []; |
|
|
|
|
|
|
|
$user = $this->security->getUser(); |
|
|
@@ -91,7 +90,6 @@ class OrderUtils |
|
|
|
// merge |
|
|
|
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor |
|
|
|
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) { |
|
|
|
|
|
|
|
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); |
|
|
|
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client."); |
|
|
|
} else { |
|
|
@@ -152,69 +150,84 @@ class OrderUtils |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
if ($orderProductAdd->getQuantityOrder() > 0) { |
|
|
|
$updated = false; |
|
|
|
|
|
|
|
$orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop()); |
|
|
|
$orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct())); |
|
|
|
$orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited()); |
|
|
|
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited()); |
|
|
|
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); |
|
|
|
|
|
|
|
$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug()); |
|
|
|
$reductionCatalog = $productFamily->getReductionCatalog(); |
|
|
|
if ($reductionCatalog) { |
|
|
|
$orderProductReductionCatalog = new OrderProductReductionCatalog(); |
|
|
|
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle()); |
|
|
|
$orderProductReductionCatalog->setValue($reductionCatalog->getValue()); |
|
|
|
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit()); |
|
|
|
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate()); |
|
|
|
|
|
|
|
$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog); |
|
|
|
} |
|
|
|
if($this->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) { |
|
|
|
if ($orderProductAdd->getQuantityOrder() > 0) { |
|
|
|
$updated = false; |
|
|
|
|
|
|
|
$orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop()); |
|
|
|
$orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct())); |
|
|
|
$orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited()); |
|
|
|
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited()); |
|
|
|
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); |
|
|
|
|
|
|
|
$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug()); |
|
|
|
$reductionCatalog = $productFamily->getReductionCatalog(); |
|
|
|
if ($reductionCatalog) { |
|
|
|
$orderProductReductionCatalog = new OrderProductReductionCatalog(); |
|
|
|
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle()); |
|
|
|
$orderProductReductionCatalog->setValue($reductionCatalog->getValue()); |
|
|
|
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit()); |
|
|
|
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate()); |
|
|
|
|
|
|
|
$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog); |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() |
|
|
|
&& (string)$this->priceUtils->getPrice($orderProduct) == (string)$this->priceUtils->getPrice($orderProductAdd) |
|
|
|
&& $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) { |
|
|
|
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId() |
|
|
|
&& (string)$this->priceUtils->getPrice($orderProduct) == (string)$this->priceUtils->getPrice($orderProductAdd) |
|
|
|
&& $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) { |
|
|
|
|
|
|
|
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()); |
|
|
|
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()); |
|
|
|
|
|
|
|
if ($persist) { |
|
|
|
$this->em->persist($orderProduct); |
|
|
|
} |
|
|
|
if ($persist) { |
|
|
|
$this->em->persist($orderProduct); |
|
|
|
} |
|
|
|
|
|
|
|
$updated = true; |
|
|
|
$return = true; |
|
|
|
$updated = true; |
|
|
|
$return = true; |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!$updated) { |
|
|
|
$orderShop->addOrderProduct($orderProductAdd); |
|
|
|
if (!$updated) { |
|
|
|
$orderShop->addOrderProduct($orderProductAdd); |
|
|
|
|
|
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
|
$this->em->persist($orderProductReductionCatalog); |
|
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
|
$this->em->persist($orderProductReductionCatalog); |
|
|
|
|
|
|
|
if ($persist) { |
|
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
|
$this->em->persist($orderProductReductionCatalog); |
|
|
|
if ($persist) { |
|
|
|
if (isset($orderProductReductionCatalog)) { |
|
|
|
$this->em->persist($orderProductReductionCatalog); |
|
|
|
} |
|
|
|
$this->em->persist($orderProductAdd); |
|
|
|
$this->em->persist($orderShop); |
|
|
|
} |
|
|
|
$this->em->persist($orderProductAdd); |
|
|
|
$this->em->persist($orderShop); |
|
|
|
} |
|
|
|
|
|
|
|
$return = true; |
|
|
|
} |
|
|
|
|
|
|
|
$return = true; |
|
|
|
if ($persist) { |
|
|
|
$this->em->flush(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($persist) { |
|
|
|
$this->em->flush(); |
|
|
|
} |
|
|
|
else { |
|
|
|
$availableQuantity = $orderProductAdd->getProduct()->getAvailableQuantityInherited() ; |
|
|
|
$textError = "Le produit <strong>".$orderProductAdd->getTitleOrderShop()."</strong> n'est pas disponible" ; |
|
|
|
if($availableQuantity !== false && $availableQuantity > 0) { |
|
|
|
$unit = '' ; |
|
|
|
if($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { |
|
|
|
$unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnit() ; |
|
|
|
} |
|
|
|
$textError .= ' dans cette quantité ' ; |
|
|
|
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ; |
|
|
|
} |
|
|
|
$this->session->getFlashBag()->add('error', $textError) ; |
|
|
|
} |
|
|
|
|
|
|
|
return $return; |
|
|
|
return $return ; |
|
|
|
} |
|
|
|
|
|
|
|
public function countQuantities($orderShop) |
|
|
@@ -472,9 +485,11 @@ class OrderUtils |
|
|
|
return false ; |
|
|
|
} |
|
|
|
|
|
|
|
public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false) |
|
|
|
public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) |
|
|
|
{ |
|
|
|
$orderShop = $this->getCartCurrent() ; |
|
|
|
if(!$orderShop) { |
|
|
|
$orderShop = $this->getCartCurrent() ; |
|
|
|
} |
|
|
|
$productFamily = $product->getProductFamily() ; |
|
|
|
$quantityAsked = $quantityOrder; |
|
|
|
|
|
|
@@ -525,11 +540,10 @@ class OrderUtils |
|
|
|
return false ; |
|
|
|
} |
|
|
|
|
|
|
|
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct) |
|
|
|
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null) |
|
|
|
{ |
|
|
|
$orderShop = $this->getCartCurrent() ; |
|
|
|
$product = $orderProduct->getProduct() ; |
|
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true); |
|
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); |
|
|
|
} |
|
|
|
|
|
|
|
public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false) |
|
|
@@ -538,16 +552,18 @@ class OrderUtils |
|
|
|
$productFamily = $product->getProductFamily() ; |
|
|
|
$behaviorCountStock = $productFamily->getBehaviorCountStock() ; |
|
|
|
|
|
|
|
foreach($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
if($orderProduct->getProduct()->getId() == $product->getId() |
|
|
|
|| ( ($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) |
|
|
|
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { |
|
|
|
if($orderShop) { |
|
|
|
foreach($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
if($orderProduct->getProduct()->getId() == $product->getId() |
|
|
|
|| ( ($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) |
|
|
|
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { |
|
|
|
|
|
|
|
if($byWeight) { |
|
|
|
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $product->getUnitInherited()->getCoefficient()) ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$quantity += $orderProduct->getQuantityOrder() ; |
|
|
|
if($byWeight) { |
|
|
|
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $product->getUnitInherited()->getCoefficient()) ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$quantity += $orderProduct->getQuantityOrder() ; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |