/** * @param $categoryId * @Route("products") */ public function getProducts($categoryId) { $userId = $this->getCurrentUserId(); $userCartId = $this->_eshopData->getCartsRepository()->getCartForCurrentUser($userId); $products = $this->_eshopData->getCategoriesRepository()->getAllProducts($userId, $userCartId, $categoryId); if ($products) { $viewModel = new CategoryProductsViewModel(); $viewModel->productViewModel = $products; $viewModel->currentCategoryId = $categoryId; $viewModel->render(); } }
/** * @Route("removeProduct") * @Authorize */ public function removeProductFromCart($cartId, $productId) { $isProductInCart = $this->_eshopData->getCartsRepository()->isProductInCart($cartId, $productId); if (!$isProductInCart) { throw new InvalidUserOperationException("You are trying to remove a product that is not in your cart"); } $isRemoved = $this->_eshopData->getCartsRepository()->removeProductsFromCart($cartId, $productId); if ($isRemoved) { RouteService::redirect('account', 'viewCart', true); } }