@@ -74,8 +74,10 @@ class CartController extends BaseController | |||
$data = $form->getData() ; | |||
foreach($data as $orderProduct) { | |||
if($orderProduct instanceof OrderProductInterface) { | |||
$addOrderProduct = $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; | |||
if($addOrderProduct && $orderProduct->getQuantityOrder() > 0) { | |||
if($orderProduct->getQuantityOrder() > 0) { | |||
$addOrderProduct = $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; | |||
} | |||
if(isset($addOrderProduct) && $addOrderProduct && $orderProduct->getQuantityOrder() > 0) { | |||
$this->orderProducts[] = $orderProduct ; | |||
} | |||
} |
@@ -182,10 +182,14 @@ class OrderUtils | |||
if($availableQuantity !== false && $availableQuantity > 0) { | |||
$unit = '' ; | |||
if($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
$unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnit() ; | |||
$unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnitReference()->getUnit() ; | |||
} | |||
$textError .= ' dans cette quantité ' ; | |||
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ; | |||
$user = $this->security->getUser() ; | |||
if($user && $user->hasRole('ROLE_USER')) { | |||
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ; | |||
} | |||
} | |||
$this->utils->addFlash('error', $textError); | |||
} |
@@ -159,5 +159,15 @@ trait OrderUtilsStockTrait | |||
return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ; | |||
} | |||
public function getProductQuantity($product) { | |||
$productFamily = $product->getProductFamily() ; | |||
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
return $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient() ; | |||
} | |||
else { | |||
return 1 ; | |||
} | |||
} | |||
} |