|
|
@@ -11,8 +11,6 @@ trait OrderUtilsStockTrait |
|
|
|
{ |
|
|
|
public function deductAvailabilityProduct(\Lc\ShopBundle\Model\OrderShop $orderShop) |
|
|
|
{ |
|
|
|
//TODO ne pas déduire des stocks les orderProduct marqué en relivraison |
|
|
|
|
|
|
|
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
//Si ce n'esrt pas une relivraison OU si c'est une relivraison + relivraison + ce n'est pas une erruer producteur |
|
|
|
if (!$orderProduct->isRedelivery() || ($orderProduct->isRedelivery() && $orderProduct->isRedeliverySupplierOrder() && !$orderProduct->isRedeliverySupplierMistake())) { |
|
|
@@ -59,127 +57,120 @@ trait OrderUtilsStockTrait |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public |
|
|
|
function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) |
|
|
|
{ |
|
|
|
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus() != 1) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!$orderShop) { |
|
|
|
$orderShop = $this->getCartCurrent(); |
|
|
|
} |
|
|
|
$productFamily = $product->getProductFamily(); |
|
|
|
$quantityAsked = $quantityOrder; |
|
|
|
public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) |
|
|
|
{ |
|
|
|
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus() != 1) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
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 (!$orderShop) { |
|
|
|
$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 ($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 (($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 { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public |
|
|
|
function isOneProductAvailableAddCart($products): bool |
|
|
|
{ |
|
|
|
foreach ($products as $product) { |
|
|
|
if ($this->isProductAvailable($product, 1, true)) { |
|
|
|
if ($product->getAvailableQuantityInherited() >= $quantityAsked |
|
|
|
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) { |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
public function isOneProductAvailableAddCart($products): bool |
|
|
|
{ |
|
|
|
foreach ($products as $product) { |
|
|
|
if ($this->isProductAvailable($product, 1, true)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public |
|
|
|
function isOrderProductAvailable(OrderProductInterface $orderProduct) |
|
|
|
{ |
|
|
|
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public |
|
|
|
function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null) |
|
|
|
{ |
|
|
|
$product = $orderProduct->getProduct(); |
|
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); |
|
|
|
} |
|
|
|
public function isOrderProductAvailable(OrderProductInterface $orderProduct) |
|
|
|
{ |
|
|
|
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()); |
|
|
|
} |
|
|
|
|
|
|
|
public |
|
|
|
function getQuantityOrderByProduct($orderShop, $product, $byWeight = false) |
|
|
|
{ |
|
|
|
$quantity = 0; |
|
|
|
$productFamily = $product->getProductFamily(); |
|
|
|
$behaviorCountStock = $productFamily->getBehaviorCountStock(); |
|
|
|
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null) |
|
|
|
{ |
|
|
|
$product = $orderProduct->getProduct(); |
|
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
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) |
|
|
|
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
public |
|
|
|
function getProductQuantityMaxAddCart($product) |
|
|
|
{ |
|
|
|
$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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |