Skip to main content

同步店铺分类


<?php
set_time_limit(0);
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require_once(dirname(__FILE__) . '/includes/lib_taobao.php');

echo "<pre>";

/** 同步店铺分类 **/

/** 0.清空数据库中店铺分类id **/
$sql = 'TRUNCATE taobao_seller_cats';
$GLOBALS['db']->query($sql);

/** 1.取店铺分类id **/
$seller_cats = taobao_sellercats_list_get('浪痕歌伤');

/** 2.入库 **/
insert_taobao_data_one($seller_cats,0);
unset($seller_cats);

/** 3.录入一级分类 **/
$sql = "SELECT * FROM taobao_seller_cats WHERE parent_cid = 0 ORDER BY sort_order ASC";
$seller_cats = $GLOBALS['db']->getAll($sql);
foreach( $seller_cats as $seller_cat)
{
sleep(1);
taobao_sellercats_list_add($seller_cat);
}
unset($seller_cats);

/** 4.取自己分类id **/
$seller_cats = taobao_sellercats_list_get($_CFG['taobao_nick']);
//print_r($seller_cats);

/** 5.根据排序,读取数据库中分类id,并添加。 **/
if( $seller_cats['seller_cats']['@attributes']['list'] == 'true' )
{
foreach( $seller_cats['seller_cats']['seller_cat'] as $seller_cat)
{
$cid = $seller_cat['cid'] ;
$date = $seller_cat['sort_order'] ;

$sql = "SELECT cid FROM taobao_seller_cats WHERE parent_cid = 0 AND sort_order = ".$seller_cat['sort_order']." ORDER BY sort_order ASC";
$temp_cid= $GLOBALS['db']->getOne($sql);

if( !empty($temp_cid) )
{
$sql = "SELECT * FROM taobao_seller_cats WHERE parent_cid = $temp_cid ORDER BY sort_order ASC";
$temp_seller_cats = $GLOBALS['db']->getAll($sql);

foreach($temp_seller_cats as $temp_seller_cat)
{
sleep(1);
$temp_seller_cat['parent_cid'] = $cid;
taobao_sellercats_list_add($temp_seller_cat) ;
}
}
}
}

?>