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