diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index 89be6ea0a..f02030c8b 100755 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -69,7 +69,8 @@ class Cart extends BaseAction implements EventSubscriberInterface } if ($append && $cartItem !== null) { - $this->updateQuantity($cartItem, $quantity); + $cartItem->addQuantity($quantity) + ->save(); } } diff --git a/core/lib/Thelia/Config/DefinePropel.php b/core/lib/Thelia/Config/DefinePropel.php index 3f7547fde..05a42a504 100755 --- a/core/lib/Thelia/Config/DefinePropel.php +++ b/core/lib/Thelia/Config/DefinePropel.php @@ -44,7 +44,9 @@ class DefinePropel "dsn" => $connection["dsn"], "user" => $connection["user"], "password" => $connection["password"], - "classname" => $connection["classname"] + "classname" => $connection["classname"], + 'options' => array( + \PDO::MYSQL_ATTR_INIT_COMMAND => array('value' =>'SET NAMES \'UTF8\'')) ); } } diff --git a/core/lib/Thelia/Controller/Front/CartController.php b/core/lib/Thelia/Controller/Front/CartController.php index ae116b40a..1b0d96003 100755 --- a/core/lib/Thelia/Controller/Front/CartController.php +++ b/core/lib/Thelia/Controller/Front/CartController.php @@ -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) { diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index 427e7e735..5432bd1ab 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -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; } diff --git a/templates/default/layout.tpl b/templates/default/layout.tpl index 22e8cb5a5..fcbe4a840 100644 --- a/templates/default/layout.tpl +++ b/templates/default/layout.tpl @@ -67,7 +67,7 @@ URL: http://www.thelia.net