Пример #1
0
 /**
  * Retourne les données sql sur base des paramètres passés en paramète
  * @param array $custom
  * @param array $current
  * @return array|null
  *
  */
 public static function getData($custom, $current)
 {
     if (!is_array($custom)) {
         return null;
     }
     if (!array_key_exists('catalog', $current)) {
         return null;
     }
     $conf = array('id' => null, 'type' => null, 'limit' => null, 'lang' => $current['lang']['iso'], 'context' => array(1 => 'all'));
     $current = $current['catalog'];
     if (!isset($custom['context'])) {
         if (isset($current['product']['id'])) {
             $conf['context'][1] = 'product';
         } elseif (isset($current['subcategory']['id'])) {
             $conf['id'] = $current['subcategory']['id'];
             $conf['context'][1] = 'product';
         } elseif (isset($current['category']['id'])) {
             $conf['id'] = $current['category']['id'];
             $conf['context'][1] = 'subcategory';
         } else {
             $conf['context'][1] = 'category';
         }
     }
     // custom values: data_sort
     if (isset($custom['select'])) {
         if ($custom['select'] == 'current') {
             if (isset($current['subcategory']['id'])) {
                 $conf['id'] = $current['subcategory']['id'];
                 $conf['type'] = 'collection';
             } elseif ($current['category']['id'] != null) {
                 $conf['id'] = $current['category']['id'];
                 $conf['type'] = 'collection';
             }
         } elseif (is_array($custom['select'])) {
             if (array_key_exists($conf['lang'], $custom['select'])) {
                 $conf['id'] = $custom['select'][$conf['lang']];
                 $conf['type'] = 'collection';
             }
         } elseif ($custom['select'] = 'all') {
             $conf['id'] = null;
             $conf['type'] = null;
         }
     } elseif (isset($custom['exclude'])) {
         if (is_array($custom['exclude'])) {
             if (array_key_exists($conf['lang'], $custom['exclude'])) {
                 $conf['id'] = $custom['exclude'][$conf['lang']];
                 $conf['type'] = 'exclude';
             }
         }
     }
     if (isset($custom['limit'])) {
         $conf['limit'] = $custom['limit'];
     }
     // custom values: display
     if (isset($custom['context'])) {
         if (is_array($custom['context'])) {
             foreach ($custom['context'] as $k => $v) {
                 $conf['context'][1] = $k;
                 if (is_array($v)) {
                     foreach ($v as $k2 => $v2) {
                         $conf['context'][2] = $k2;
                         $conf['context'][3] = $v2;
                     }
                 } else {
                     $conf['context'][2] = $v;
                 }
             }
         } else {
             $allowed = array('category', 'subcategory', 'product', 'last-product', 'last-product-cat', 'last-product-subcat', 'all', 'product-gallery');
             if (array_search($custom['context'], $allowed)) {
                 $conf['context'][1] = $custom['context'];
             }
         }
     }
     // *** Load SQL data
     $data = null;
     if ($conf['context'][1] == 'category' or $conf['context'][1] == 'all') {
         // Category
         $data = parent::s_category($conf['lang'], $conf['id'], $conf['type'], $conf['limit']);
         if (($conf['context'][2] == 'subcategory' or $conf['context'][1] == 'all') and $data != null) {
             foreach ($data as $k1 => $v_1) {
                 // Category > subcategory
                 $data_2 = parent::s_sub_category_in_cat($v_1['idclc'], $conf['limit']);
                 if ($data_2 != null) {
                     $data[$k1]['subdata'] = $data_2;
                     if (($conf['context'][3] == 'product' or $conf['context'][1] == 'all') and $data_2 != null) {
                         $data_3 = null;
                         foreach ($data_2 as $k2 => $v_2) {
                             // Category > subcategory > Product
                             $data_3 = parent::s_product($v_2['idclc'], $v_2['idcls'], $conf['limit']);
                             if ($data_3 != null) {
                                 $data[$k1]['subdata'][$k2]['subdata'] = $data_3;
                             }
                         }
                     }
                 }
             }
         } elseif ($conf['context'][2] == 'product' and $data != null) {
             foreach ($data as $k1 => $v_1) {
                 // Category > Product
                 $data_2 = parent::s_product($v_1['idclc'], null, $conf['limit']);
                 if ($data_2 != null) {
                     $data[$k1]['subdata'] = $data_2;
                 }
             }
         }
     } elseif ($conf['context'][1] == 'subcategory') {
         if ($custom['select'] == 'current' and isset($current['subcategory']['id'])) {
             // Subcategory[current]
             $data = parent::s_subcategory($conf['lang'], $current['subcategory']['id'], $conf['type'], $conf['limit']);
         } elseif (isset($current['category']['id']) and empty($custom['select'])) {
             // Subcategory[in_cat]
             $data = parent::s_sub_category_in_cat($current['category']['id'], $conf['limit']);
         } else {
             // Subcategory
             $data = parent::s_subcategory($conf['lang'], $conf['id'], $conf['type'], $conf['limit']);
         }
         if ($conf['context'][2] == 'product' and $data != null) {
             foreach ($data as $k1 => $v_1) {
                 // Subcategory > product
                 $data_2 = parent::s_product($v_1['idclc'], $v_1['idcls'], $conf['limit']);
                 if ($data_2 != null) {
                     $data[$k1]['subdata'] = $data_2;
                 }
             }
         }
     } elseif ($conf['context'][1] == 'product') {
         if (isset($current['product']['id']) and empty($custom['select'])) {
             // Product[in_product]
             $data = parent::s_product_in_product($current['product']['id'], $conf['id'], $conf['type']);
         } elseif ((isset($current['category']['id']) or isset($current['subcategory']['id'])) and empty($custom['select'])) {
             // Product[in_category OR in_subcategory]
             if (isset($current['category']['id'])) {
                 $catId = $current['category']['id'];
                 $subcatId = isset($current['subcategory']['id']) ? $current['subcategory']['id'] : 0;
             } else {
                 $catId = null;
                 $subcatId = isset($current['subcategory']['id']) ? $current['subcategory']['id'] : null;
             }
             $data = parent::s_product($catId, $subcatId);
         } else {
             // All products in lang
             $data = parent::s_product($conf['id'], 0);
         }
     } elseif ($conf['context'][1] == 'last-product' or $conf['context'][1] == 'last-product-cat') {
         // Product[last]
         // @TODO: mise en place des paramètre 'exclude'
         $data = parent::s_product($conf['id'], null, $conf['limit']);
     } elseif ($conf['context'][1] == 'last-product-subcat') {
         $data = parent::s_product(null, $conf['id'], $conf['limit']);
     } elseif ($conf['context'][1] == 'product-gallery') {
         // Product Gallery
         $data = parent::s_product_gallery($current['product']['id']);
     }
     return $data;
 }
Пример #2
0
 /**
  * Assign product's data to smarty
  * @access private
  */
 private function load_product_data()
 {
     $template = new frontend_model_template();
     $Catalog = new frontend_model_catalog();
     $data = parent::s_product_data($this->idProduct);
     $dataClean = $Catalog->setItemData($data, true);
     $template->assign('product', $dataClean, true);
     $this->load_category_data();
     $this->load_subcategory_data();
 }