Ejemplo n.º 1
0
 public function register()
 {
     if ($this->isLogged()) {
         RouteService::redirect('account', 'profile', true);
     }
     $v = new RegisterViewModel();
     $v->render();
 }
 /**
  * @param DeleteCategoryBindingModel $model
  * @throws \Exception
  * @Admin
  * @Editor
  */
 public function delete(DeleteCategoryBindingModel $model)
 {
     $isDeleted = $this->_eshopData->getCategoriesRepository()->remove($model->getCategoryId());
     // TODO ADD JAVASCRIPT CONFIRMATION BOX
     if ($isDeleted) {
         RouteService::redirect('categories', 'all', true);
     } else {
         echo 'Error during delete category';
     }
 }
 /**
  * @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";
 }
Ejemplo n.º 4
0
<?php

namespace EShop;

require_once 'FrontController.php';
use EShop\Config\AppConfig;
use EShop\Config\RouteConfig;
use EShop\Exceptions\InvalidCredentialsException;
use EShop\Exceptions\InvalidUserInputException;
use EShop\Exceptions\InvalidUserOperationException;
use EShop\Exceptions\UnauthorizedException;
use EShop\Helpers\RouteService;
use EShop\Helpers\TokenHelper;
RouteService::init(RouteConfig::getBasePath());
final class App
{
    /**
     * @var FrontController
     */
    private $frontController;
    public function __construct()
    {
        $this->frontController = new \EShop\FrontController();
        \EShop\DependencyContainer\AppStarter::registerDbConfigurations();
    }
    public function start()
    {
        if (!isset($_SESSION['formToken'])) {
            TokenHelper::setCSRFToken();
        }
        try {
Ejemplo n.º 5
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';
 }