Browse Source

Moulinettes prix produits

feature/export_comptable
Fab 4 years ago
parent
commit
839e8fc5af
2 changed files with 69 additions and 69 deletions
  1. +14
    -11
      ShopBundle/Services/Order/OrderUtils.php
  2. +55
    -58
      ShopBundle/Services/Order/OrderUtilsStockTrait.php

+ 14
- 11
ShopBundle/Services/Order/OrderUtils.php View File

@@ -102,10 +102,11 @@ class OrderUtils

$return = false;

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

if (!$orderShop) {
$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
@@ -125,15 +126,17 @@ class OrderUtils
$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($productFamily) {
$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) {

+ 55
- 58
ShopBundle/Services/Order/OrderUtilsStockTrait.php View File

@@ -21,9 +21,9 @@ trait OrderUtilsStockTrait
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));

$productFamily = $orderProduct->getProduct()->getProductFamily() ;
$productFamily = $orderProduct->getProduct()->getProductFamily();
$productFamily->setAvailableQuantity($newAvailability);
$productFamily->setUpdatedBy($orderShop->getUser()) ;
$productFamily->setUpdatedBy($orderShop->getUser());

$this->em->persist($productFamily);

@@ -33,9 +33,9 @@ trait OrderUtilsStockTrait
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();

$productFamily = $orderProduct->getProduct()->getProductFamily() ;
$productFamily = $orderProduct->getProduct()->getProductFamily();
$productFamily->setAvailableQuantity($newAvailability);
$productFamily->setUpdatedBy($orderShop->getUser()) ;
$productFamily->setUpdatedBy($orderShop->getUser());

$this->em->persist($productFamily);

@@ -44,9 +44,9 @@ trait OrderUtilsStockTrait
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();

$product = $orderProduct->getProduct() ;
$product = $orderProduct->getProduct();
$product->setAvailableQuantity($newAvailability);
$product->setUpdatedBy($orderShop->getUser()) ;
$product->setUpdatedBy($orderShop->getUser());

$this->em->persist($product);

@@ -59,119 +59,116 @@ trait OrderUtilsStockTrait

public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null)
{
if($product->getStatus() != 1) {
return false ;
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus() != 1) {
return false;
}

if(!$orderShop) {
$orderShop = $this->getCartCurrent() ;
if (!$orderShop) {
$orderShop = $this->getCartCurrent();
}
$productFamily = $product->getProductFamily() ;
$productFamily = $product->getProductFamily();
$quantityAsked = $quantityOrder;

if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
if(!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true) ;
}
else {
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 ($checkCart) {
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true);
}
}

if(($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
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 (!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product);
}

if($checkCart) {
$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 {
} else {
return false;
}
}

public function isOneProductAvailableAddCart($products): bool
{
foreach($products as $product) {
if($this->isProductAvailable($product, 1, true)) {
return true ;
foreach ($products as $product) {
if ($this->isProductAvailable($product, 1, true)) {
return true;
}
}

return false ;
return false;
}

public function isOrderProductAvailable(OrderProductInterface $orderProduct)
{
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()) ;
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder());
}

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

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

return $quantity ;
return $quantity;
}

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

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

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

public function getProductQuantity($product) {
public function getProductQuantity($product)
{

$productFamily = $product->getProductFamily() ;
$productFamily = $product->getProductFamily();

if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
return $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient() ;
}
else {
return 1 ;
if ($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
return $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient();
} else {
return 1;
}
}
}

Loading…
Cancel
Save