Esempio n. 1
0
 static function cat4($file)
 {
     $xml = simplexml_load_file($file);
     $goods_list = $xml->offers->offer;
     if (empty($goods_list)) {
         $goods_list = $xml->shop->offers->offer;
     }
     $count = array();
     $goods = array();
     foreach ($goods_list as $data) {
         $d = array();
         $cid = (int) trim($data->categoryId);
         $id = (int) trim($data->attributes()->id);
         $in_stock = (int) trim($data->attributes()->available);
         //			if((float)$data->price==0){
         //				continue;
         //			}
         $goods[$id] = array('ext_category' => $cid, 'name' => trim(u2w((string) $data->name)), 'description' => trim(u2w((string) $data->Description)), 'html2' => trim(u2w((string) $data->html2)), 'price' => (double) trim($data->price), 'vendor' => trim(u2w($data->Vendor)), 'weight_flg' => trim(u2w($data->weight_flg)), 'in_stock' => $in_stock, 'param' => array());
         if (isset($data->param)) {
             foreach ($data->param as $p) {
                 $goods[$id]['param'][trim(u2w($p->attributes()->name))] = trim(u2w((string) $p));
             }
         }
         if (empty($count[$cid])) {
             $count[$cid] = 0;
         }
         $count[$cid]++;
     }
     $catalog = array();
     $only_changes = false;
     if (!empty($xml->shop->only_changes) && $xml->shop->only_changes == 'true') {
         $only_changes = true;
     }
     if (!empty($xml->only_changes) && $xml->only_changes == 'true') {
         $only_changes = true;
     }
     $category = $xml->Categories->category;
     if (empty($category)) {
         $category = $xml->shop->Categories->category;
     }
     if (empty($category)) {
         $category = $xml->shop->categories->category;
     }
     if (!empty($category)) {
         $item = array();
         foreach ($category as $cat) {
             $id = (int) $cat->attributes()->id;
             $n = u2w((string) $cat);
             //			if(strpos('НЕ ИСП',$n)!==false){
             //				continue;
             //			}
             if (strpos($n, 'НЕ ИСП') !== false) {
                 continue;
             }
             $item[$id]['name'] = u2w((string) $cat);
             $item[$id]['c'] = isset($count[$id]) ? $count[$id] : 0;
             if ($parentId = (int) $cat->attributes()->parent) {
                 $item[$parentId]['ch'][$id] =& $item[$id];
             } elseif ($parentId = (int) $cat->attributes()->parentId) {
                 $item[$parentId]['ch'][$id] =& $item[$id];
             } else {
                 $catalog[$id] =& $item[$id];
             }
         }
         foreach ($item as $id => &$i) {
             if (isset($i['ch'])) {
                 $i['cr'] = _recount_cat($i);
             }
         }
     }
     return array('catalog' => $catalog, 'count' => $count, 'goods' => $goods, 'only_changes' => $only_changes);
 }
Esempio n. 2
0
 function getChildCategory($id = 0)
 {
     global $ST, $get;
     $res = array();
     $cond = "";
     $man_cond = "";
     if (($manid = $this->getURIVal('manid')) && ($manid = explode(',', $manid))) {
         $man_cond .= " AND manufacturer_id IN ('" . implode("','", $manid) . "')";
     }
     $q = trim(strtolower(SQL::slashes(urldecode($get->get('search')))));
     if ($q) {
         $man_cond .= " AND (lower(i.name) LIKE '%" . $q . "%')";
     }
     if ($action = $this->getURIIntVal('action')) {
         $man_cond .= " AND i.sort1={$action}";
         //			$this->setPageTitle('СПЕЦИАЛЬНОЕ ПРЕДЛОЖЕНИЕ');
     }
     if ($this->cfg('SHOP_GOODS_IN_STOCK_ONLY') == 'true') {
         //Настройка показывать только в наличии
         $cond .= " AND i.in_stock>0";
     }
     $rs = $ST->select("SELECT name,img,parentid,id,c,cm FROM sc_shop_catalog cat\r\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS c, category FROM sc_shop_item i WHERE  in_stock>-1 {$cond} {$man_cond} GROUP BY category) AS cnt ON cnt.category=cat.id\r\n\t\t\tLEFT JOIN (SELECT COUNT(itemid) AS cm, catid FROM sc_shop_item i, sc_shop_item2cat WHERE in_stock>-1 {$cond} AND itemid=i.id {$man_cond} GROUP BY catid) AS cntm ON cntm.catid=cat.id\t\r\n\t\tWHERE cat.sort>-1  ORDER BY sort,name");
     $menu = array();
     while ($rs->next()) {
         foreach ($rs->getRow() as $k => $v) {
             $item[$rs->get('id')][$k] = $v;
         }
         $item[$rs->get('id')]['name'] = preg_replace('|,\\s*|', ', ', $item[$rs->get('id')]['name']);
         //Фикс пробела после запятой;
         if ($rs->getInt('parentid')) {
             $item[$rs->get('parentid')]['ch'][$rs->getInt('id')] =& $item[$rs->get('id')];
         } else {
             $menu[$rs->get('id')] =& $item[$rs->get('id')];
         }
     }
     $item[0]['ch'] =& $menu;
     $k = 'c';
     if (isset($item[$id]['ch'])) {
         foreach ($item[$id]['ch'] as &$i) {
             $i[$k . "r"] = _recount_cat($i, $k);
         }
     }
     return @$item[$id]['ch'];
 }