Browse Source

Amélioration gestion du stock

feature/export_comptable
Guillaume 4 years ago
parent
commit
18d6532d18
3 changed files with 20 additions and 4 deletions
  1. +4
    -2
      ShopBundle/Controller/Frontend/CartController.php
  2. +6
    -2
      ShopBundle/Services/Order/OrderUtils.php
  3. +10
    -0
      ShopBundle/Services/Order/OrderUtilsStockTrait.php

+ 4
- 2
ShopBundle/Controller/Frontend/CartController.php View File

$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 ;
} }
} }

+ 6
- 2
ShopBundle/Services/Order/OrderUtils.php View File

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

+ 10
- 0
ShopBundle/Services/Order/OrderUtilsStockTrait.php View File

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

Loading…
Cancel
Save