$category = array_sort($category, 'count', 'desc'); //最多取8个分类的商品,并且每个分类下的产品数量要大于4 $step = count($category) < 8 ? count($category) : 8; $category = array_slice($category, 0, $step); $catids = ""; foreach ($category as $key => $value) { if ($value['count'] > 4) { $catids .= $value['category_id'] . ','; } } $category = Sp_Taobao_Goods::getItemcats($catids); if (!is_array(@$category[0])) { $cat[] = $category; $category = $cat; } //取每个分类的商品 foreach ($category as $key => $value) { $goods = Sp_Taobao_Goods::getShopItems($nick, $value['cid'], 1, 40); //从40个商品中随机取8个 shuffle($goods['item_search']['items']['item']); $goods['item_search']['items']['item'] = array_slice($goods['item_search']['items']['item'], 0, 8); $category[$key]['items'] = $goods['item_search']['items']['item']; } $shop["shop"] = array('items' => $category, 'info' => $shop_info['shop']); //print_r($shop); Config::load($shop); $sp_view->setConfig(Config::get()); $sp_view->addStyle('shop.css'); $sp_view->setTitle(strip_tags($shop_info['shop']['title'])); //print_r($sp_view); $sp_view->display("shop.html");
$goods_detail = Sp_Taobao_Goods::getItemDetail($num_iid); //淘宝客点击url $url = Sp_Taobao_Taobaoke::getItemConvert($num_iid, Config::get('taoke.pid_short')); $cid = $goods_detail["item"]['cid']; $props = $goods_detail["item"]['props']; //商品属性 $props = Sp_Taobao_Goods::getItemPropValues($cid, $props); //商品分类信息 $catgory = Sp_Taobao_Goods::getItemcats($cid); //当前分类的推荐商品 $cat_goods = Sp_Taobao_Goods::getCategoryItems($cid, 40, Config::get('taoke.pid_short')); //从40个商品中随机取8个 shuffle($cat_goods['taobaoke_items']['taobaoke_item']); $cat_goods['taobaoke_items']['taobaoke_item'] = array_slice($cat_goods['taobaoke_items']['taobaoke_item'], 0, 8); //商品的评价信息 $rates = Sp_Taobao_Goods::getItemsTraderates($goods_detail['item']['num_iid'], $goods_detail['item']['nick']); if ($rates['total_results'] > 0) { $rates = $rates['trade_rates']['trade_rate']; } else { $rates = null; } $goods["goods"] = array("item" => $goods_detail['item'], "cat_items" => $cat_goods['taobaoke_items']['taobaoke_item'], "taobaoke" => $url["taobaoke_items"]["taobaoke_item"], "props" => $props, "category" => $catgory, "rates" => $rates); Config::load($goods); $sp_view->setConfig(Config::get()); $sp_view->addStyle('goods.css'); $sp_view->setTitle($goods_detail['item']['title']); $sp_view->caching = true; $sp_view->cache_lifetime = 86400; $sp_view->cache_id = $cache_id; } $sp_view->display("goods.html", $cache_id);