diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index c3a0ded9f..b198dda6c 100644 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -22,23 +22,27 @@ /*************************************************************************************/ namespace Thelia\Action; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Thelia\Form\CategoryDeletionForm; + use Thelia\Form\BaseForm; -use Thelia\Core\HttpFoundation\Request; use Thelia\Action\Exception\FormValidationException; use Thelia\Core\Event\ActionEvent; use Symfony\Component\Form\Form; -use Symfony\Component\DependencyInjection\ContainerAware; -use Thelia\Core\Template\ParserContext; -use Thelia\Log\Tlog; use Symfony\Component\DependencyInjection\ContainerInterface; -use Thelia\Core\Security\SecurityContext; -use Thelia\Core\Security\Exception\AuthorizationException; + + class BaseAction { + /** + * @var The container + */ + protected $container; + + public function __construct(ContainerInterface $container) { + $this->container = $container; + } + /** * Validate a BaseForm * @@ -88,4 +92,14 @@ class BaseAction $event->stopPropagation(); } + /** + * Return the event dispatcher, + * + * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + public function getDispatcher() + { + return $this->container->get('event_dispatcher'); + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index b040634f9..3b4b32a78 100755 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -55,6 +55,7 @@ class Cart extends BaseAction implements EventSubscriberInterface public function addArticle(CartEvent $event) { $request = $event->getRequest(); + $message = null; try { $cartAdd = $this->getAddCartForm($request); @@ -91,11 +92,19 @@ class Cart extends BaseAction implements EventSubscriberInterface $message = $e->getMessage(); } + if($message) { + // The form has errors, propagate it. + $this->propagateFormError($cartAdd, $message, $event); + } - // The form has errors, propagate it. - $this->propagateFormError($cartAdd, $message, $event); } + /** + * increase the quantity for an existing cartItem + * + * @param CartItem $cartItem + * @param float $quantity + */ protected function updateQuantity(CartItem $cartItem, $quantity) { $cartItem->setDisptacher($this->getDispatcher()); @@ -103,6 +112,15 @@ class Cart extends BaseAction implements EventSubscriberInterface ->save(); } + /** + * try to attach a new item to an existing cart + * + * @param \Thelia\Model\Cart $cart + * @param int $productId + * @param int $productSaleElementsId + * @param float $quantity + * @param ProductPrice $productPrice + */ protected function addItem(\Thelia\Model\Cart $cart, $productId, $productSaleElementsId, $quantity, ProductPrice $productPrice) { $cartItem = new CartItem(); @@ -118,6 +136,15 @@ class Cart extends BaseAction implements EventSubscriberInterface ->save(); } + /** + * find a specific record in CartItem table using the Cart id, the product id + * and the product_sale_elements id + * + * @param int $cartId + * @param int $productId + * @param int $productSaleElementsId + * @return ChildCartItem + */ protected function findItem($cartId, $productId, $productSaleElementsId) { return CartItemQuery::create() @@ -127,6 +154,12 @@ class Cart extends BaseAction implements EventSubscriberInterface ->findOne(); } + /** + * Find the good way to construct the cart form + * + * @param Request $request + * @return CartAdd + */ private function getAddCartForm(Request $request) { if ($request->isMethod("post")) { diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index dbdc51a61..9006f2362 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -13,14 +13,17 @@ + + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 92fd1a97e..04e05024b 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -199,7 +199,7 @@ class BaseController extends ContainerAware * * @return EventDispatcherInterface */ - protected function getDispatcher() + public function getDispatcher() { return $this->container->get('event_dispatcher'); }