/**
  * @param DeleteProductBindingModel $model
  * @throws InvalidUserInputException
  * @throws \Exception
  * @Admin
  * @Editor
  */
 public function deleteProduct(DeleteProductBindingModel $model)
 {
     $exists = $this->_eshopData->getProductsRepository()->findById($model->getProductId());
     if (!$exists) {
         throw new InvalidUserInputException("Product with such id does not exists");
     }
     $isDeleted = $this->_eshopData->getProductsRepository()->remove($model->getProductId());
     if ($isDeleted) {
         RouteService::redirect('categories', 'products/' . $model->getCategoryId(), true);
     }
     echo "Error during delete product";
 }
 /**
  * @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();
     }
 }
Ejemplo n.º 3
0
 public function putDiscountOnAllProducts(AddAllProductsPromoBindingModel $model)
 {
     if ($model->getDiscount() < 1) {
         throw new InvalidUserInputException("Discount cannot be equal or less than 0.");
     }
     $hasPromotion = $this->_eshopData->getProductsRepository()->allProductsPromotionAvailable();
     if ($hasPromotion) {
         throw new InvalidUserOperationException("There is already valid promo for all products.");
     }
     $isDiscounted = $this->_eshopData->getProductsRepository()->putAllProductsOnPromotion($model->getDiscount());
     if ($isDiscounted) {
         RouteService::redirect('admin/admin', 'adminPanel', true);
     }
     echo 'Error during add all products promo';
 }
 /**
  * @param BindModels\ReorderProductBindingModel $model
  * @throws InvalidUserInputException
  * @throws InvalidUserOperationException
  * @throws \Exception
  * @Authorize
  * @Admin
  * @Editor
  */
 public function reorder(BindModels\ReorderProductBindingModel $model)
 {
     if ($model->getQuantity() < 2) {
         throw new InvalidUserInputException("You cannot order less than 1 item quantity");
     }
     $productExists = $this->_eshopData->getProductsRepository()->findById($model->getProductId());
     if ($productExists == null) {
         throw new InvalidUserOperationException("The selected product does not exist anymore.");
     }
     $isUpdated = $this->_eshopData->getProductsRepository()->reorderProduct($model->getProductId(), $model->getQuantity());
     if ($isUpdated) {
         RouteService::redirect('categories', 'products/' . $productExists->getCategoryId(), true);
     }
     echo 'Error during reorder product';
 }