request; $dispatcher = $this->getDispatcher(); $produitsHorsStock = false; foreach ($parameters as $key=>$value) { $string = explode("-", $key); $pseId = $string[1];; $qty = $string[3]; $productId = ProductSaleElementsQuery::create()->findOneById($pseId)->getProductId(); $stock = ProductSaleElementsQuery::create()->findOneById($pseId)->getQuantity(); if ($stock > 0) { $eventAjout = new CartEvent($request->getSession()->getSessionCart($dispatcher)); $eventAjout ->setQuantity($qty) ->setProduct($productId) ->setProductSaleElementsId($pseId); $dispatcher->dispatch(TheliaEvents::CART_ADDITEM, $eventAjout); } else { $produitsHorsStock = true; } } if (! $produitsHorsStock) return new RedirectResponse(URL::getInstance()->absoluteUrl('/cart')); } }