/**
  * main action
  */
 public function mainAction()
 {
     //do nothing if basket is not initialized
     if (!is_numeric($_SESSION['basket']['id'])) {
         return true;
     }
     /**
      * create object
      */
     require_once 'models/ecommerce/ecommerce_basket.php';
     $Basket = new ecommerce_basket();
     $basket_content_ids = $Basket->getContentItemsProductIdList($_SESSION['basket']['id']);
     $viewed_list_ids = array();
     $Node = new common_node();
     $viewed_products = array();
     /**
      * go through history
      */
     foreach ($_SESSION['history'] as $item) {
         if (is_numeric($item['node_id'])) {
             $node_data = $Node->nodeDetail($item['node_id']);
             if ($node_data['node_controller'] == 'product') {
                 if (!in_array($node_data['content'], $basket_content_ids) && !in_array($node_data['content'], $viewed_list_ids) && $_SESSION['active_pages'][0] != $node_data['id']) {
                     $viewed_products[] = $node_data['content'];
                 }
             }
         }
     }
     /**
      * Pass product_id_list to product_list controller
      */
     if (is_array($viewed_products) && count($viewed_products) > 0) {
         /**
          * prepare HTTP query for product_list component
          */
         $viewed_list['product_id_list'] = $viewed_products;
         $query = http_build_query($viewed_list, '', ':');
         /**
          * detect controller for product list
          */
         switch ($this->GET['template']) {
             case 'scroll':
                 $controller = 'product_list_scroll';
                 break;
             case '3col':
                 $controller = 'product_list_3columns';
                 break;
             case '2col':
                 $controller = 'product_list_2columns';
                 break;
             case '1col':
             default:
                 $controller = 'product_list';
                 break;
         }
         /**
          * call controller
          */
         $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$controller}~{$query}:image_width={$this->GET['image_width']}~");
         $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent());
         $this->tpl->parse('content.recently_viewed');
     }
     return true;
 }
Пример #2
0
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * create objects
      */
     require_once 'models/ecommerce/ecommerce_basket.php';
     require_once 'models/ecommerce/ecommerce_product_to_product.php';
     $Basket = new ecommerce_basket();
     $PtP = new ecommerce_product_to_product();
     /**
      * Set variables
      */
     switch ($this->GET['type']) {
         case 'static':
             $type = 'static';
             $this->tpl->assign("TITLE", I18N_RELATED_PRODUCTS_STATIC);
             break;
         case 'dynamic':
         default:
             $type = 'dynamic';
             $this->tpl->assign("TITLE", I18N_RELATED_PRODUCTS_DYNAMIC);
             break;
     }
     $related = array();
     //limit for each product - how many related products to show to each product in basket
     if (is_numeric($this->GET['limit_each'])) {
         $limit_each = $this->GET['limit_each'];
     } else {
         $limit_each = 2;
     }
     /**
      * get product list
      */
     $basket_content_ids = $Basket->getContentItemsProductIdList($_SESSION['basket']['id']);
     /**
      * Get list
      */
     if (is_array($basket_content_ids)) {
         foreach ($basket_content_ids as $id) {
             $related_to_one = $PtP->getRelatedProduct($id, $limit_each, $type);
             if (is_array($related_to_one)) {
                 //make sure we don't add duplicates
                 foreach ($related_to_one as $item_one) {
                     if (!is_array($related['product_list'])) {
                         $related[] = $item_one;
                     } else {
                         $exists = 0;
                         foreach ($related['product_list'] as $item) {
                             if ($item['id'] == $item_one['id']) {
                                 $exists = 1;
                             }
                         }
                         if ($exists == 0) {
                             $related[] = $item_one;
                         }
                     }
                 }
             }
         }
     }
     /**
      * Pass product_id_list to product_list controller
      */
     if (is_array($related) && count($related) > 0) {
         /**
          * prepare HTTP query for product_list component
          */
         $related_list['product_id_list'] = $related;
         $query = http_build_query($related_list, '', ':');
         /**
          * detect controller for product list
          */
         switch ($this->GET['template']) {
             case 'scroll':
                 $controller = 'product_list_scroll';
                 break;
             case '3col':
                 $controller = 'product_list_3columns';
                 break;
             case '2col':
                 $controller = 'product_list_2columns';
                 break;
             case '1col':
             default:
                 $controller = 'product_list';
                 break;
         }
         /**
          * call controller
          */
         $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$controller}~{$query}:image_width={$this->GET['image_width']}~");
         $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent());
         $this->tpl->parse('content.product_related');
     }
     return true;
 }