fix cart quantity for issue #46

This commit is contained in:
Manuel Raynaud
2013-10-22 17:19:16 +02:00
parent 6fef556319
commit 0580539ed8
3 changed files with 23 additions and 5 deletions

View File

@@ -69,7 +69,8 @@ class Cart extends BaseAction implements EventSubscriberInterface
}
if ($append && $cartItem !== null) {
$this->updateQuantity($cartItem, $quantity);
$cartItem->addQuantity($quantity)
->save();
}
}

View File

@@ -74,7 +74,7 @@ class CartController extends BaseFrontController
$cartEvent->setQuantity($this->getRequest()->get("quantity"));
try {
$this->getDispatcher()->dispatch(TheliaEvents::CART_UPDATEITEM, $cartEvent);
$this->dispatch(TheliaEvents::CART_UPDATEITEM, $cartEvent);
$this->redirectSuccess();
} catch (PropelException $e) {

View File

@@ -60,14 +60,31 @@ class CartItem extends BaseCartItem
}
}
$this->addQuantity($value);
$this->setQuantity($value);
return $this;
}
public function addQuantity($quantity)
public function addQuantity($value)
{
$this->setQuantity($this->getQuantity() + $quantity);
$currentQuantity = $this->getQuantity();
$newQuantity = $currentQuantity + $value;
if($value <= 0)
{
$value = $currentQuantity;
}
if(ConfigQuery::read("verifyStock", 1) == 1)
{
$productSaleElements = $this->getProductSaleElements();
if($productSaleElements->getQuantity() < $newQuantity) {
$newQuantity = $currentQuantity;
}
}
$this->setQuantity($newQuantity);
return $this;
}