public static function isEditor()
 {
     if (\DF\Helpers\Session::get('userId') != null && strpos(\DF\Helpers\Session::get('roles'), 'Editor') >= 0) {
         return true;
     }
     return false;
 }
 public function getAllProducts()
 {
     $statement = $this->db->prepare("\n            SELECT * FROM products\n        ");
     $statement->execute();
     $products = $statement->fetchAll();
     $promoRepo = new PromotionsRepository();
     for ($i = 0; $i < count($products); $i++) {
         $discount = $promoRepo->getTheBiggestPromotion(Session::get('userId'), $products[$i]['id'], $products[$i]['category_id']);
         $products[$i]['original_price'] = $products[$i]['price'];
         $products[$i]['price'] = $products[$i]['price'] - $products[$i]['price'] * $discount / 100;
         $products[$i]['discount'] = $discount;
     }
     return $products;
 }
Esempio n. 3
0
 public function run()
 {
     error_reporting(E_ALL);
     Session::start();
     $this->initRouteService();
     $this->registerDatabaseConfiguration();
     if (Csrf::getCSRFToken() == null) {
         Csrf::setCSRFToken();
     }
     $this->loadRoles();
     //        RouteScanner::performScan();
     $this->frontController = new FrontController(new Router());
     $this->frontController->dispatch();
 }
 public function getProductsInCart($cartId)
 {
     $statement = $this->db->prepare("\n            SELECT\n\t            p.id, p.name, p.price, p.category_id, cp.quantity, p.quantity AS product_max_quantity, p.details\n            FROM cart_products cp\n            JOIN products p ON cp.product_id = p.id\n            WHERE cp.cart_id = ?;\n        ");
     $statement->execute([$cartId]);
     $products = [];
     if ($statement->rowCount() > 0) {
         $products = $statement->fetchAll();
     }
     $promoRepo = new PromotionsRepository();
     for ($i = 0; $i < count($products); $i++) {
         $discount = $promoRepo->getTheBiggestPromotion(Session::get('userId'), $products[$i]['id'], $products[$i]['category_id']);
         $products[$i]['original_price'] = $products[$i]['price'];
         $products[$i]['price'] = $products[$i]['price'] - $products[$i]['price'] * $discount / 100;
         $products[$i]['discount'] = $discount;
     }
     return $products;
 }
Esempio n. 5
0
?>
/js/respond.min.js"></script>
    <![endif]-->
    <link rel="shortcut icon" href="<?php 
echo \DF\Services\RouteService::$basePath . '/Content';
?>
/images/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<?php 
echo \DF\Services\RouteService::$basePath . '/Content';
?>
/images/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php 
echo \DF\Services\RouteService::$basePath . '/Content';
?>
/images/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php 
echo \DF\Services\RouteService::$basePath . '/Content';
?>
/images/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="<?php 
echo \DF\Services\RouteService::$basePath . '/Content';
?>
/images/ico/apple-touch-icon-57-precomposed.png">
</head>
<body>

<?php 
if (\DF\Helpers\Session::get('userId') != null) {
    require 'Views/partials/userNavbar.php';
}
require 'Views/partials/shopNavigation.php';
 protected function getCurrentUserId()
 {
     return Session::get('userId');
 }
 /**
  * @Authorize
  * @Route("{id:num}/add")
  */
 public function addToCart($id)
 {
     $result = $this->eshopData->getProductsRepository()->addToCart(Session::get('userId'), $id);
     RouteService::redirect('categories', '', [], true);
 }
 /**
  * @Authorize
  */
 public function logout()
 {
     if ($this->isLogged()) {
         Session::emptyUserRelated();
         RouteService::redirect('home', '', true);
     }
 }
 private function checkAuthorization()
 {
     if (!Session::exists('userId') && $this->getRouter()->routeInfo['authorize'] == true) {
         throw new \Exception("Unauthorized");
     }
     if (count($this->getRouter()->routeInfo['roles']) > 0) {
         if (!RoleService::userInRoles(Session::get('userId'), $this->getRouter()->routeInfo['roles'])) {
             throw new \Exception("You do not have the rights");
         }
     }
 }