|
|
|
|
|
|
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); |
|
|
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); |
|
|
|
|
|
|
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily() ; |
|
|
|
|
|
|
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily(); |
|
|
$productFamily->setAvailableQuantity($newAvailability); |
|
|
$productFamily->setAvailableQuantity($newAvailability); |
|
|
$productFamily->setUpdatedBy($orderShop->getUser()) ; |
|
|
|
|
|
|
|
|
$productFamily->setUpdatedBy($orderShop->getUser()); |
|
|
|
|
|
|
|
|
$this->em->persist($productFamily); |
|
|
$this->em->persist($productFamily); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); |
|
|
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); |
|
|
|
|
|
|
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily() ; |
|
|
|
|
|
|
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily(); |
|
|
$productFamily->setAvailableQuantity($newAvailability); |
|
|
$productFamily->setAvailableQuantity($newAvailability); |
|
|
$productFamily->setUpdatedBy($orderShop->getUser()) ; |
|
|
|
|
|
|
|
|
$productFamily->setUpdatedBy($orderShop->getUser()); |
|
|
|
|
|
|
|
|
$this->em->persist($productFamily); |
|
|
$this->em->persist($productFamily); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); |
|
|
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); |
|
|
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); |
|
|
|
|
|
|
|
|
$product = $orderProduct->getProduct() ; |
|
|
|
|
|
|
|
|
$product = $orderProduct->getProduct(); |
|
|
$product->setAvailableQuantity($newAvailability); |
|
|
$product->setAvailableQuantity($newAvailability); |
|
|
$product->setUpdatedBy($orderShop->getUser()) ; |
|
|
|
|
|
|
|
|
$product->setUpdatedBy($orderShop->getUser()); |
|
|
|
|
|
|
|
|
$this->em->persist($product); |
|
|
$this->em->persist($product); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) |
|
|
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; |
|
|
$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; |
|
|
$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)) { |
|
|
|| $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 |
|
|
if ($product->getAvailableQuantityInherited() >= $quantityAsked |
|
|
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) { |
|
|
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
} else { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function isOneProductAvailableAddCart($products): bool |
|
|
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) |
|
|
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) |
|
|
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null) |
|
|
{ |
|
|
{ |
|
|
$product = $orderProduct->getProduct() ; |
|
|
|
|
|
|
|
|
$product = $orderProduct->getProduct(); |
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); |
|
|
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false) |
|
|
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())) { |
|
|
&& $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) |
|
|
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; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |