示例#1
0
 static function getProductsFromBasket($image = FALSE)
 {
     try {
         self::init();
         $products = [];
         $productModel = new ProductTableModel();
         $productModel->setTable('product as p');
         $imageModel = new ImageTableModel();
         foreach (self::$basket as $id => $quantity) {
             if ($id !== 'id' && is_int($id)) {
                 $productModel->setId($id);
                 $product = $productModel->readRecordsById('id', 'p.title, p.price')[0];
                 if ($image) {
                     $imageModel->setId($id);
                     $imageModel->setTable('image');
                     $product['image'] = $imageModel->readRecordsById('product_id', 'image', 'AND main = 1')[0]['image'];
                 }
                 $product['total'] = (int) $product['price'] * $quantity;
                 if (is_array($product)) {
                     $products[$id] = new Product($id, $quantity);
                     $products[$id]->setData($product);
                 }
             }
         }
         return $products;
     } catch (Exception $ex) {
         Basket::cleanBasket();
         Basket::init();
         header('Location: /');
         exit;
     }
 }
示例#2
0
文件: index.php 项目: ralf000/newshop
<?php

use app\controllers\FrontController;
use app\helpers\Basket;
use app\services\Session;
/* Пути по-умолчанию для поиска файлов */
set_include_path(get_include_path() . PATH_SEPARATOR . 'app/controllers' . PATH_SEPARATOR . 'app/models' . PATH_SEPARATOR . 'app/services' . PATH_SEPARATOR . 'app/helpers' . PATH_SEPARATOR . 'app/tests' . PATH_SEPARATOR . 'app/widgets' . PATH_SEPARATOR . 'app/dataContainers');
/* Автозагрузчик классов */
spl_autoload_register(function ($class) {
    require_once $class . '.class.php';
});
//классы composer
require_once '/app/extensions/vendor/autoload.php';
Session::init();
Basket::init();
/* Инициализация и запуск FrontController */
$controller = FrontController::getInstance();
$controller->route();
/* Вывод данных */
echo $controller->getPage();