Beispiel #1
0
 public function before()
 {
     parent::before();
     //Visits
     $visited = \Cookie::get('visited', false);
     if (!$visited) {
         \Dashboard::log_visitor();
         \Cookie::set("visited", true, time() + 86400);
     }
     // Cart
     \Config::load('cart', true);
     $cartManager = new \Cart\Manager(\Config::get('cart'));
     \CartManager::init($cartManager);
     \CartManager::context('Cart');
     // Set Visitors group default
     \Product\Model_Attribute::set_user_group(3);
     \Theme::instance()->active('frontend');
     \Theme::instance()->set_template($this->template);
     // Set a global variable so views can use it
     $seo = array('meta_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'canonical_links' => '', 'meta_robots_index' => 1, 'meta_robots_follow' => 1);
     \View::set_global('seo', $seo, false);
     \View::set_global('theme', \Theme::instance(), false);
     \View::set_global('logged', $this->check_logged(), false);
     \View::set_global('guest', $this->check_guest(), false);
     \View::set_global('logged_type', $this->check_logged_type(), false);
 }
 public function before()
 {
     parent::before();
     // Override a package class
     \Autoloader::add_classes(array('Hybrid\\Pagination' => APPPATH . 'core/pagination.php'));
     // Cart
     \Config::load('cart', true);
     $cartManager = new \Cart\Manager(\Config::get('cart'));
     \CartManager::init($cartManager);
     \CartManager::context('Cart');
     // Set Visitors group default
     \Product\Model_Attribute::set_user_group(3);
     \Theme::instance()->active('frontend');
     \Theme::instance()->set_template($this->template);
     // Set a global variable so views can use it
     \View::set_global('theme', \Theme::instance(), false);
     \View::set_global('logged', $this->check_logged(), false);
     \View::set_global('guest', $this->check_guest(), false);
     \View::set_global('logged_type', $this->check_logged_type(), false);
     \View::set_global('my_categories', $this->my_categories(), false);
     // Pagination
     \Config::load('pagination', true);
 }
<?php

if (isset($_GET['action'])) {
    // ________ ADD ITEM ________
    if ($_GET['action'] == 'add_item') {
        if (isset($_POST['quantity'])) {
            $quantity = $_POST['quantity'];
            $manager = new ItemManager($database);
            try {
                $item = $manager->findById($_GET['id']);
            } catch (Exception $e) {
                $errors[] = $e->getMessage();
            }
            if (isset($_SESSION['id'])) {
                $manager = new CartManager($database);
                try {
                    $add = $manager->addToCart($currentUser, $item, $quantity);
                    header('Location: index.php?page=item&id=' . $item->getId() . '');
                    exit;
                } catch (Exception $e) {
                    $errors[] = $e->getMessage();
                }
            } else {
                if (!isset($_SESSION['order'])) {
                    $_SESSION['order'] = array();
                }
                for ($i = 0; $i < count($_SESSION['order']); $i++) {
                    $localItem = $_SESSION['order'][$i]['item'];
                    $localQuantity = $_SESSION['order'][$i]['quantity'];
                    if ($localItem == $item->getId()) {
                        $quantity = $localQuantity + $quantity;