change quantity on cartUpdate EventListener
This commit is contained in:
@@ -110,7 +110,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
->filterByCartId($cart->getId())
|
->filterByCartId($cart->getId())
|
||||||
->filterById($cartItemId)
|
->filterById($cartItemId)
|
||||||
->findOne();
|
->findOne();
|
||||||
|
|
||||||
if ($cartItem) {
|
if ($cartItem) {
|
||||||
$this->updateQuantity($cartItem, $quantity);
|
$this->updateQuantity($cartItem, $quantity);
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
|
|||||||
protected function updateQuantity(CartItem $cartItem, $quantity)
|
protected function updateQuantity(CartItem $cartItem, $quantity)
|
||||||
{
|
{
|
||||||
$cartItem->setDisptacher($this->getDispatcher());
|
$cartItem->setDisptacher($this->getDispatcher());
|
||||||
$cartItem->addQuantity($quantity)
|
$cartItem->updateQuantity($quantity)
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,27 +41,25 @@ class CartItem extends BaseCartItem
|
|||||||
* @param $value
|
* @param $value
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addQuantity($value)
|
public function updateQuantity($value)
|
||||||
{
|
{
|
||||||
$currentQuantity = $this->getQuantity();
|
$currentQuantity = $this->getQuantity();
|
||||||
|
|
||||||
$newQuantity = $currentQuantity + $value;
|
if($value <= 0)
|
||||||
|
|
||||||
if($newQuantity <= 0)
|
|
||||||
{
|
{
|
||||||
$newQuantity = $currentQuantity;
|
$value = $currentQuantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ConfigQuery::read("verifyStock", 1) == 1)
|
if(ConfigQuery::read("verifyStock", 1) == 1)
|
||||||
{
|
{
|
||||||
$productSaleElements = $this->getProductSaleElements();
|
$productSaleElements = $this->getProductSaleElements();
|
||||||
|
|
||||||
if($productSaleElements->getQuantity() < $newQuantity) {
|
if($productSaleElements->getQuantity() < $value) {
|
||||||
$newQuantity = $currentQuantity;
|
$value = $currentQuantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setQuantity($newQuantity);
|
$this->setQuantity($value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user