modify addQuantity method
This commit is contained in:
@@ -7,6 +7,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Event\CartEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Base\CartItem as BaseCartItem;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class CartItem extends BaseCartItem
|
||||
{
|
||||
@@ -26,9 +27,41 @@ class CartItem extends BaseCartItem
|
||||
}
|
||||
}
|
||||
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
if ($this->dispatcher) {
|
||||
$cartEvent = new CartEvent($this->getCart());
|
||||
|
||||
$this->dispatcher->dispatch(TheliaEvents::CART_MODIFYITEM, $cartEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return $this
|
||||
*/
|
||||
public function addQuantity($value)
|
||||
{
|
||||
$this->setQuantity($this->getQuantity() + $value);
|
||||
$currentQuantity = $this->getQuantity();
|
||||
|
||||
$newQuantity = $currentQuantity + $value;
|
||||
|
||||
if($newQuantity <= 0)
|
||||
{
|
||||
$newQuantity = $currentQuantity;
|
||||
}
|
||||
|
||||
if(ConfigQuery::read("verifyStock", 1) == 1)
|
||||
{
|
||||
$productSaleElements = $this->getProductSaleElements();
|
||||
|
||||
if($productSaleElements->getQuantity() < $newQuantity) {
|
||||
$newQuantity = $currentQuantity;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setQuantity($currentQuantity);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user