public function minimalLayout()
 {
     if (0 && CurrentUser::loggedIn()) {
         $ui_array = array('page', 'vendor_id', 'id');
         $this->loadUIVars('ui_blog', $ui_array);
     } else {
         $page = $this->filterInt('page');
         $vendor_id = $this->filterInt('vendor_id');
         $category_id = $this->filterInt('id');
     }
     if (!isset($_GET['page']) || $_GET['page'] == '') {
         $_GET['page'] = 1;
     }
     // vendor lock
     if (isset($this->vendor_lock)) {
         $_GET['vendor_id'] = $this->vendor_lock;
     }
     $this->assign('top_cats', ProductsLayout::getTopCats());
     if (!isset($_GET['vendor_id'])) {
         $_GET['vendor_id'] = 0;
     } else {
         $_GET['vendor_id'] = (int) $_GET['vendor_id'];
     }
     $p = Model::load('ProductItem');
     $status = '(' . \Empathy\ELib\Storage\ProductItemStatus::AVAILABLE . ', ' . \Empathy\ELib\Storage\ProductItemStatus::SOLD_OUT . ')';
     $sql = ' WHERE status IN' . $status;
     if ($_GET['vendor_id'] > 0) {
         $sql .= ' AND vendor_id = ' . $_GET['vendor_id'];
     }
     if (isset($_GET['id']) && $_GET['id'] > 0) {
         $cats = array();
         switch ($_GET['id']) {
             case 1:
                 $cats = array(3, 7, 4, 5, 6);
                 break;
             case 2:
                 $cats = array(8);
                 break;
             default:
                 break;
         }
         $sql .= ' AND category_id IN' . $p->buildUnionString($cats);
     }
     $sql .= ' AND vendor_verified = 1';
     $sql .= ' ORDER BY id DESC';
     if ($_GET['page'] < 1) {
         $_GET['page'] = 1;
     }
     $per_page = 8;
     $products = $p->getAllCustomPaginate(Model::getTable('ProductItem'), $sql, $_GET['page'], $per_page);
     $p_nav = $p->getPaginatePages(Model::getTable('ProductItem'), $sql, $_GET['page'], $per_page);
     $this->pages = $p_nav;
     $this->assign('products', $products);
     $this->assign('p_nav', $p_nav);
     $this->assign('vendor_id', $_GET['vendor_id']);
     if (isset($_GET['id'])) {
         $this->assign('category_id', $_GET['id']);
     }
 }
 public function product()
 {
     $this->setTemplate('store_product.tpl');
     $product_id = 0;
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $product_id = $_GET['id'];
     }
     if (isset($_GET['product_name'])) {
         $name_arr = explode('-', $_GET['product_name']);
         $product_id = $name_arr[sizeof($name_arr) - 1];
     }
     $_GET['product_id'] = $product_id;
     if ($this->isXMLHttpRequest()) {
         header('Content-type: application/json');
         $c = Model::load('ProductColour');
         $c->id = $_GET['colour_id'];
         $c->load();
         $item = array();
         $item['image'] = $c->image;
         $item['option_id'] = $c->property_option_id;
         echo json_encode($item);
         exit;
     } else {
         // default event from store.php
         $p = Model::load('ProductItem');
         $c = Model::load('CategoryItem');
         $v = Model::load('ProductVariant');
         $o = Model::load('ProductVariantPropertyOption');
         $c->id = 0;
         $p->id = $_GET['product_id'];
         $v->id = 0;
         $o->id = 0;
         if (isset($_POST['add'])) {
             $options = array();
             if (isset($_POST['property'])) {
                 foreach ($_POST['property'] as $option) {
                     array_push($options, $option);
                 }
             }
             if (sizeof($options) > 0) {
                 $variant_id = $v->findVariant($options, $p->id);
             } else {
                 $sql = ' WHERE product_id = ' . $p->id . ' LIMIT 0, 1';
                 $variant = $v->getAllCustom(Model::getTable('ProductVariant'), $sql);
                 if (sizeof($variant) > 0) {
                     $variant_id = $variant[0]['id'];
                 }
             }
             if (is_numeric($variant_id) && $variant_id > 0) {
                 $sc = new ShoppingCart();
                 $sc->add($variant_id, 1);
                 $this->redirect('store/cart');
             }
         }
         $l = new ProductsLayout($c, $p, $v, $o, $this);
         $this->assign('breadcrumb', $l->getBreadCrumb());
         $this->assign('buttons', $l->getButtons());
         $this->assign('p_nav', $l->getPNav());
         if ($_GET['product_id'] != 0) {
             $c = Model::load('ProductColour');
             $colours = $c->getColoursIndexed($_GET['product_id']);
             if (sizeof($colours) > 0) {
                 $this->assign('colours', $colours);
             }
             if (defined('ELIB_USE_PRODUCT_BRANDS') && ELIB_USE_PRODUCT_BRANDS == true) {
                 $b = Model::load('BrandItem');
                 $b->id = $p->brand_id;
                 $b->load();
                 $this->assign('brand', $b->name);
             }
             $this->assign('product_view', 1);
             //$variant_count = $this->assignVariantsTableData($p, $v);
             //$this->getPropertiesAndOptions($p->id, (sizeof($colours) > 0));
             $this->getPropertiesAndOptions($p, sizeof($colours) > 0);
         }
         $_GET['category_id'] = -1;
         $this->assign('category_id', $_GET['category_id']);
         $this->assign('product_id', $_GET['product_id']);
         $this->assign('option_id', 0);
         if ($_GET['product_id'] != 0) {
             $p = $l->getProduct();
             if (sizeof($colours) > 0) {
                 $p->image = $c->getFirstColourImage($_GET['product_id']);
             }
             $this->assign('product', $p);
             $qty = array();
             $i = 0;
             for ($i; $i < 31; $i++) {
                 $qty[$i] = $i;
             }
             $this->assign('qty', $qty);
         }
     }
     // seo
     $c = Model::load('CategoryItem');
     $c->id = $p->category_id;
     $c->load();
     $this->assign('price', $p->getPrice());
     $custom_title = '';
     $custom_keywords = '';
     $custom_description = '';
     if (isset($b)) {
         $custom_title = $b->name . ' ';
         $custom_keywords = $b->name . ' ';
         $custom_description = $b->name . ' ';
     }
     $custom_title .= $p->name . ' - ' . $c->name . ' at Brighton BMX Co';
     $custom_keywords .= $p->name . ' ' . $c->name;
     $custom_description .= $p->name . ' in ' . $c->name;
     $this->assign('custom_title', $custom_title);
     $this->assign('custom_keywords', strtolower($custom_keywords));
     $this->assign('custom_description', $custom_description . ' - ' . strip_tags($p->description));
 }