$data = $form->getData() ; | $data = $form->getData() ; | ||||
foreach($data as $orderProduct) { | foreach($data as $orderProduct) { | ||||
if($orderProduct instanceof OrderProductInterface) { | 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 ; | $this->orderProducts[] = $orderProduct ; | ||||
} | } | ||||
} | } |
if($availableQuantity !== false && $availableQuantity > 0) { | if($availableQuantity !== false && $availableQuantity > 0) { | ||||
$unit = '' ; | $unit = '' ; | ||||
if($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | 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 .= ' 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); | $this->utils->addFlash('error', $textError); | ||||
} | } |
return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ; | 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 ; | |||||
} | |||||
} | |||||
} | } |