Browse Source

Frontend : gestion des stocks

feature/export_comptable
Guillaume 4 years ago
parent
commit
0cfe6c91f3
4 changed files with 122 additions and 26 deletions
  1. +19
    -3
      ShopBundle/Controller/Frontend/CartController.php
  2. +2
    -1
      ShopBundle/Model/Product.php
  3. +100
    -22
      ShopBundle/Services/Order/OrderUtils.php
  4. +1
    -0
      ShopBundle/Services/ProductFamilyUtils.php

+ 19
- 3
ShopBundle/Controller/Frontend/CartController.php View File

use Lc\ShopBundle\Context\ProductFamilyInterface; use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCartInterface; use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Model\OrderReductionCart; use Lc\ShopBundle\Model\OrderReductionCart;
use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\UserUtils; use Lc\ShopBundle\Services\UserUtils;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
$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) {
$this->orderProducts[] = $orderProduct ;
if($this->orderUtils->isOrderProductAvailableAddCart($orderProduct)) {
$addOrderProduct = $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ;
if($addOrderProduct && $orderProduct->getQuantityOrder() > 0) {
$this->orderProducts[] = $orderProduct ;
}
}
else {
$availableQuantity = $orderProduct->getProduct()->getAvailableQuantityInherited() ;
$textError = "Le produit <strong>".$orderProduct->getTitleOrderShop()."</strong> n'est pas disponible" ;
if($availableQuantity !== false && $availableQuantity > 0) {
$unit = '' ;
if($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$unit = $orderProduct->getProduct()->getUnitInherited()->getUnit() ;
}
$textError .= ' dans cette quantité ' ;
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->orderUtils->getQuantityOrderByProduct($orderShop, $orderProduct->getProduct()).$unit.' déjà dans votre panier.' ;
}
$this->addFlash('error', $textError) ;
} }
} }
} }

+ 2
- 1
ShopBundle/Model/Product.php View File

{ {
if ($this->getQuantity()) { if ($this->getQuantity()) {
return $this->getQuantity(); return $this->getQuantity();
} else {
}
else {
return $this->getProductFamily()->getQuantity(); return $this->getProductFamily()->getQuantity();
} }
} }

+ 100
- 22
ShopBundle/Services/Order/OrderUtils.php View File

} }
$this->em->persist($orderProductAdd); $this->em->persist($orderProductAdd);
$this->em->persist($orderShop); $this->em->persist($orderShop);

} }
} }


if ($persist) {
$this->em->flush();
}

$return = true; $return = true;
} }

if ($persist) {
$this->em->flush();
}
} }


return $return; return $return;
} }



public function countQuantities($orderShop) public function countQuantities($orderShop)
{ {
return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts()); return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts());
} }
} }


public function isProductAvailable(Product $product, $quanityOrder)
{
$quanityAsked = $quanityOrder;

if($product->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$quanityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quanityOrder;
}

if ($product->getAvailableQuantityInherited() >= $quanityAsked || $product->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
} else {
return false;
}

}

public function isCartAllowToBeOrder($order){ public function isCartAllowToBeOrder($order){
return true; return true;
} }


return false ; return false ;
} }

public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false)
{
$orderShop = $this->getCartCurrent() ;
$productFamily = $product->getProductFamily() ;
$quantityAsked = $quantityOrder;

if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
if(!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true) ;
}
else {
$quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder;
}

if($checkCart) {
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true) ;
}
}

if(($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {

if(!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product) ;
}

if($checkCart) {
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product) ;
}
}

if ($product->getAvailableQuantityInherited() >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
}
else {
return false;
}
}

public function isOneProductAvailableAddCart($products): bool
{
$orderShop = $this->getCartCurrent() ;

foreach($products as $product) {
if($this->isProductAvailable($product, 1, true)) {
return true ;
}
}

return false ;
}

public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct)
{
$orderShop = $this->getCartCurrent() ;
$product = $orderProduct->getProduct() ;
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true);
}

public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false)
{
$quantity = 0 ;
$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($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $product->getUnitInherited()->getCoefficient()) ;
}
else {
$quantity += $orderProduct->getQuantityOrder() ;
}
}
}

return $quantity ;
}

public function getProductQuantityMaxAddCart($product)
{
$orderShop = $this->getCartCurrent() ;
$productFamily = $product->getProductFamily() ;

$byWeight = false ;
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$byWeight = true ;
}

return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ;
}
} }

+ 1
- 0
ShopBundle/Services/ProductFamilyUtils.php View File

namespace Lc\ShopBundle\Services ; namespace Lc\ShopBundle\Services ;


use Lc\ShopBundle\Context\PriceUtilsInterface; use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Model\ProductFamily;


class ProductFamilyUtils class ProductFamilyUtils
{ {

Loading…
Cancel
Save