/**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_product_to_product.php';
     require_once 'models/ecommerce/ecommerce_product.php';
     $PtP = new ecommerce_product_to_product();
     $Product = new ecommerce_product();
     $product_id = $this->GET['id'];
     $ptp_data = array();
     $ptp_data['product_id'] = $product_id;
     /**
      * saving
      */
     if (is_array($_POST['product_related'])) {
         $current = $PtP->listing("product_id = {$product_id}");
         foreach ($current as $c) {
             $PtP->delete($c['id']);
         }
         foreach ($_POST['product_related'] as $to_id) {
             if (is_numeric($to_id)) {
                 $ptp_data['related_product_id'] = $to_id;
                 $PtP->insert($ptp_data);
             }
         }
     }
     /**
      * listing
      */
     $current = $PtP->listing("product_id = {$product_id}");
     foreach ($current as $c) {
         $detail = $Product->detail($c['related_product_id']);
         if ($detail['publish'] == 0) {
             $detail['class'] = "class='disabled'";
         }
         $this->tpl->assign("CURRENT", $detail);
         $this->tpl->parse("content.ptn");
     }
     return true;
 }
示例#2
0
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * create objects
      */
     require_once 'models/common/common_node.php';
     require_once 'models/ecommerce/ecommerce_product_to_product.php';
     $Node = new common_node();
     $PtP = new ecommerce_product_to_product();
     /**
      * Set variables
      */
     if (is_numeric($this->GET['product_node_id'])) {
         $product_node_data = $Node->detail($this->GET['product_node_id']);
         $product_id = $product_node_data['content'];
     } else {
         if (is_numeric($this->GET['id'])) {
             $product_id = $this->GET['id'];
         }
     }
     if (is_numeric($this->GET['limit'])) {
         $limit = $this->GET['limit'];
     } else {
         $limit = 5;
     }
     /**
      * relation type
      */
     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;
     }
     /**
      * template
      */
     switch ($this->GET['product_list_template']) {
         case '2columns':
             $product_list_template = 'product_list_2columns';
             break;
         case '4columns':
             $product_list_template = 'product_list_4columns';
             break;
         case '3columns':
         default:
             $product_list_template = 'product_list_3columns';
             break;
     }
     /**
      * listing
      */
     if (is_numeric($product_id)) {
         $related = $PtP->getRelatedProduct($product_id, $limit, $type);
         /**
          * 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, '', ':');
             /**
              * check request for image width and customize query in that case
              */
             if (is_numeric($this->GET['image_width'])) {
                 $image_width = $this->GET['image_width'];
                 $query = $query . ":image_width={$image_width}";
             }
             /**
              * call controller
              */
             $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$product_list_template}~{$query}~");
             $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent());
             $this->tpl->parse('content.product_related');
         }
     }
     return true;
 }
 /**
  * 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;
 }
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * create objects
      */
     require_once 'models/ecommerce/ecommerce_product.php';
     require_once 'models/ecommerce/ecommerce_product_to_product.php';
     $Product = new ecommerce_product();
     $PtP = new ecommerce_product_to_product();
     /**
      * Set Variables
      */
     if ($this->GET['type'] == 'worst') {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     if (is_numeric($this->GET['limit'])) {
         $limit = $this->GET['limit'];
     } else {
         $limit = 5;
     }
     if (is_numeric($this->GET['customer_id'])) {
         $customer_id = $this->GET['customer_id'];
     } else {
         if ($this->GET['customer_id'] == 'session' && $_SESSION['client']['customer']['id'] > 0) {
             $customer_id = $_SESSION['client']['customer']['id'];
         } else {
             $customer_id = false;
         }
     }
     /**
      * type
      */
     switch ($this->GET['type']) {
         case 'static':
             $type = 'static';
             break;
         case 'dynamic':
         default:
             $type = 'dynamic';
             break;
     }
     /**
      * Get product_list
      */
     $product_list = $Product->getMostPopularProducts($order, $limit, $customer_id);
     $related = array();
     foreach ($product_list as $item) {
         $related_actual = $PtP->getRelatedProduct($item['product_id'], 1, $type);
         $related = array_merge($related, $related_actual);
     }
     /**
      * detect controller (template) for product list
      */
     switch ($this->GET['template']) {
         case 'scroll':
             $controller = 'product_list_scroll';
             break;
         case '4col':
             $controller = 'product_list_4columns';
             break;
         case '3col':
             $controller = 'product_list_3columns';
             break;
         case '2col':
             $controller = 'product_list_2columns';
             break;
         case '1col':
         default:
             $controller = 'product_list_shelf';
             break;
     }
     /**
      * 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, '', ':');
         /**
          * call controller
          */
         $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$controller}~{$query}~");
         $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent());
         $this->tpl->parse('content.product_related');
     }
     return true;
 }