Browse Source

OrderShopBuilder

packProduct
Guillaume 2 years ago
parent
commit
651b817207
1 changed files with 16 additions and 15 deletions
  1. +16
    -15
      Builder/Order/OrderShopBuilder.php

+ 16
- 15
Builder/Order/OrderShopBuilder.php View File

@@ -29,6 +29,7 @@ use Lc\CaracoleBundle\Model\Order\OrderStatusInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
@@ -264,7 +265,6 @@ class OrderShopBuilder

foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($this->orderProductSolver->compare($orderProduct, $orderProductAdd)) {

$orderProduct->setQuantityOrder(
$orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
);
@@ -496,23 +496,25 @@ class OrderShopBuilder
public function deductAvailabilityProduct(OrderShopInterface $orderShop): void
{
foreach ($orderShop->getOrderProducts() as $orderProduct) {
$this->applyDeductAvailabilityProduct($orderShop, $orderProduct);
$this->applyDeductAvailabilityProduct($orderShop, $orderProduct->getProduct(), $orderProduct->getQuantityOrder());
}
}

public function applyDeductAvailabilityProduct(
OrderShopInterface $orderShop,
OrderProductInterface $orderProduct
ProductInterface $product,
int $quantityOrder
): void {
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
switch ($product->getProductFamily()->getBehaviorCountStock()) {
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :

//Disponibilité par unité de référence
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder(
) * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($product);
$newAvailability = $oldAvailability - ($quantityOrder * ($this->productSolver->getQuantityInherited(
$product
) / $this->productSolver->getUnitInherited($product)->getCoefficient()));

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

@@ -521,10 +523,10 @@ class OrderShopBuilder
break;
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :

$oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($product);
$newAvailability = $oldAvailability - $quantityOrder;

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

@@ -532,10 +534,9 @@ class OrderShopBuilder

break;
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$oldAvailability = $this->productSolver->getAvailableQuantityInherited($product);
$newAvailability = $oldAvailability - $quantityOrder;

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

@@ -543,10 +544,10 @@ class OrderShopBuilder

break;
}

$this->entityManager->flush();
}


public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
{
$debug = '';

Loading…
Cancel
Save