数据Feed包含三种文件:数据索引文件、自定义类目文件,商品数据文件。其中索引文件分为全量索引和增量索引两种类型。
数据索引文件:用以实现对商品的信息的更新,全量索引更新所有商品(即清除前一个索性的商品,上传最新索性中包含的商品),增量索引的则只针对部分需要修改信息的商品。
自定义类目文件:用以说明商家自定义的类目结构,支持2级分类;
商品数据文件:包含商品信息的xml文件,文件中包含商品图片的绝对地址。数据索引文件
全量索引 示例:FullIndex.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<cat_url>http://www.daermao.com/taobao/SellerCats.xml</cat_url>
<!--商家自定义类目结构文件地址-->
<dir>http://www.daermao.com/taobao/item/</dir>
<!—商品数据xml文件所在目录地址-->
<item_ids>
<outer_id action="upload">10243</outer_id>
<outer_id action="upload">14954</outer_id>
<outer_id action="delete">10001</outer_id>
<!—全量只允许upload更新商品-->
</item_ids>
<root>增量索引 示例:IncrementIndex.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<cat_url>http://www.daermao.com/taobao/SellerCats.xml</cat_url>
<!--商家自定义类目结构文件地址-->
<dir>http://www.daermao.com/taobao/item/</dir>
<!--增量数据文件目录与全量数据文件目录相同-->
<item_ids>
<outer_id action="delete">10243</outer_id>
<outer_id action="upload">14954</outer_id>
<!--delete下架商品、upload更新及上架商品-->
</item_ids>
</root>自定义类目文件 示例:SellerCats.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间,淘宝用来辨别是否已采集-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<seller_cats><!--商家自定义的类目结构,支持2级分类-->
<cat>
<scid>100</scid>
<name>玩具</name>
<cats>
<cat>
<scid>101</scid>
<!--商家子定义的类目ID-->
<name>益智玩具</name>
<!--类目名称-->
</cat>
<cat>
<scid>102</scid>
<name>毛绒玩具</name>
</cat>
</cats>
</cat>
<cat>
<scid>200</scid>
<name>童装</name>
<cats>
<cat>
<scid>201</scid>
<name>儿童服装</name>
</cat>
<cat>
<scid>202</scid>
<name>亲子套装</name>
</cat>
</cats>
</cat>
</seller_cats>
</root><?xml version="1.0" encoding="utf-8"?>
<item>
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<outer_id>14954</outer_id>
<!--商家自定义的商品ID-->
<title>好时光/Tinytime BIBI小熊折叠收纳袋/挂袋收纳袋/杂物挂袋 83CM(棕色)</title>
<!--商品标题,不超过60个字节-->
<type>fixed</type>
<!--商品类型,一口价(fixed 默认)、团购(group)、打折(discount),如果类型设为discount则discount字段必填-->
<available>0</ available >
<!--商品是否有货,默认为0,表示无货,1标示有货,必填-->
<price>62.00</price>
<!--商品价格,格式:5.00;单位:元;精确到:分;取值范围:0-100000000-->
<discount>
<start>2011-01-17-12:00</start>
<!--折扣开始时间, 格式:2011-01-17-12:00,二十四小时制,精确到分钟-->
<end>2011-01-18-21:00</end>
<!--折扣结束时间, 格式:2011-01-17-12:00,二十四小时制,精确到分钟-->
<dprice>49.60</dprice>
<!--折后价, 商品打折后的价格,与打折率选填一项,填写打折信息时必填一项。格式:5.00;单位:元;精确到:分;取值范围:0-100000000-->
<drate>0.80</drate>
<!--折扣率, 表示商品在原有价格基础上乘的系数,格式:0.80,精确到0.01,比如八折就是0.80-->
<ddesc>本次打折,优惠力度很大,机不可失,失不再来</ddesc>
<!--打折信息描述, 不超过300个字节-->
</discount>
<desc>一个BIBI小熊公仔搭配棉质的隔层,简单中透着浪漫</desc>
<!--商品简描述, 不超过1000个字节-->
<brand>好时光</brand>
<!--商品品牌,不超过30个字符-->
<tags>好时光\Tinytime</tags>
<!--商品Tag标签,有助于搜索,不超过5个标签-->
<image>http://www.xiaozhuren.com/pic/0001.jpg</image>
<!--商品主图片的绝对地址,图片类型:jpg、jpeg、png,不支持gif;最大:500k-->
<more_images>
<img>http://www.xiaozhuren.com/pic/0002.jpg</img>
<img>http://www.xiaozhuren.com/pic/0003.jpg</img>
<img>http://www.xiaozhuren.com/pic/0004.jpg</img>
<img>http://www.xiaozhuren.com/pic/0005.jpg</img>
</more_images>
<!--商品更多辅助图片的绝对地址,图片类型:jpg、jpeg、png,不支持gif;最大:500k-->
<scids>101,102</scids>
<!--商户自定义类目ID,一个商品可以属于多个类目,半角逗号分隔-->
<post_fee>0</post_fee>
<!--邮费价格,精确到2位小数;单位:元;卖家承担运费邮费即为0-->
<props>颜色:棕色,白色;</props>
<!--SKU属性项、属性值,不同属性项间以分号分隔,不同属性值间以逗号分隔-->
<showcase>true</showcase>
<!--不填默认不推荐,true/false-->
<href>http://www.xiaozhuren.com/goods.php?id=14954</href>
<!--商品链接绝对地址-->
</item>增量索引与全量索引中对商品的升级操作:
增量文件中,对每个item都有一个操作指令,指令动作包含删除(delete)、上传(upload)2种操作;
全量文件只允许对item执行一种指令动作,上传(upload);
比如: <outer_id action="delete">10001</outer_id> 删除10001商品
<outer_id action="upload">10243</outer_id> 上传10243商品目录结构示例
全量更新与增量更新的区别:
全量更新每24小时发生一次,会清除之前的所有数据,清除后且只允许上传商品upload);
增量更新则每半个小时发生一次,不会清除之前的所有数据,而是在现有的数据上做数据更新(delete,upload),此处的upload相当于update。
数据索引文件:用以实现对商品的信息的更新,全量索引更新所有商品(即清除前一个索性的商品,上传最新索性中包含的商品),增量索引的则只针对部分需要修改信息的商品。
自定义类目文件:用以说明商家自定义的类目结构,支持2级分类;
商品数据文件:包含商品信息的xml文件,文件中包含商品图片的绝对地址。数据索引文件
全量索引 示例:FullIndex.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<cat_url>http://www.daermao.com/taobao/SellerCats.xml</cat_url>
<!--商家自定义类目结构文件地址-->
<dir>http://www.daermao.com/taobao/item/</dir>
<!—商品数据xml文件所在目录地址-->
<item_ids>
<outer_id action="upload">10243</outer_id>
<outer_id action="upload">14954</outer_id>
<outer_id action="delete">10001</outer_id>
<!—全量只允许upload更新商品-->
</item_ids>
<root>增量索引 示例:IncrementIndex.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<cat_url>http://www.daermao.com/taobao/SellerCats.xml</cat_url>
<!--商家自定义类目结构文件地址-->
<dir>http://www.daermao.com/taobao/item/</dir>
<!--增量数据文件目录与全量数据文件目录相同-->
<item_ids>
<outer_id action="delete">10243</outer_id>
<outer_id action="upload">14954</outer_id>
<!--delete下架商品、upload更新及上架商品-->
</item_ids>
</root>自定义类目文件 示例:SellerCats.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<version>1.0</version>
<!--Feed数据格式的版本号-->
<modified>2010-11-30 12:00:00</modified>
<!--Feed数据文件最近修改时间,淘宝用来辨别是否已采集-->
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<seller_cats><!--商家自定义的类目结构,支持2级分类-->
<cat>
<scid>100</scid>
<name>玩具</name>
<cats>
<cat>
<scid>101</scid>
<!--商家子定义的类目ID-->
<name>益智玩具</name>
<!--类目名称-->
</cat>
<cat>
<scid>102</scid>
<name>毛绒玩具</name>
</cat>
</cats>
</cat>
<cat>
<scid>200</scid>
<name>童装</name>
<cats>
<cat>
<scid>201</scid>
<name>儿童服装</name>
</cat>
<cat>
<scid>202</scid>
<name>亲子套装</name>
</cat>
</cats>
</cat>
</seller_cats>
</root><?xml version="1.0" encoding="utf-8"?>
<item>
<seller_id>小主人官网</seller_id>
<!--给合作商家创建的淘宝会员账号-->
<outer_id>14954</outer_id>
<!--商家自定义的商品ID-->
<title>好时光/Tinytime BIBI小熊折叠收纳袋/挂袋收纳袋/杂物挂袋 83CM(棕色)</title>
<!--商品标题,不超过60个字节-->
<type>fixed</type>
<!--商品类型,一口价(fixed 默认)、团购(group)、打折(discount),如果类型设为discount则discount字段必填-->
<available>0</ available >
<!--商品是否有货,默认为0,表示无货,1标示有货,必填-->
<price>62.00</price>
<!--商品价格,格式:5.00;单位:元;精确到:分;取值范围:0-100000000-->
<discount>
<start>2011-01-17-12:00</start>
<!--折扣开始时间, 格式:2011-01-17-12:00,二十四小时制,精确到分钟-->
<end>2011-01-18-21:00</end>
<!--折扣结束时间, 格式:2011-01-17-12:00,二十四小时制,精确到分钟-->
<dprice>49.60</dprice>
<!--折后价, 商品打折后的价格,与打折率选填一项,填写打折信息时必填一项。格式:5.00;单位:元;精确到:分;取值范围:0-100000000-->
<drate>0.80</drate>
<!--折扣率, 表示商品在原有价格基础上乘的系数,格式:0.80,精确到0.01,比如八折就是0.80-->
<ddesc>本次打折,优惠力度很大,机不可失,失不再来</ddesc>
<!--打折信息描述, 不超过300个字节-->
</discount>
<desc>一个BIBI小熊公仔搭配棉质的隔层,简单中透着浪漫</desc>
<!--商品简描述, 不超过1000个字节-->
<brand>好时光</brand>
<!--商品品牌,不超过30个字符-->
<tags>好时光\Tinytime</tags>
<!--商品Tag标签,有助于搜索,不超过5个标签-->
<image>http://www.xiaozhuren.com/pic/0001.jpg</image>
<!--商品主图片的绝对地址,图片类型:jpg、jpeg、png,不支持gif;最大:500k-->
<more_images>
<img>http://www.xiaozhuren.com/pic/0002.jpg</img>
<img>http://www.xiaozhuren.com/pic/0003.jpg</img>
<img>http://www.xiaozhuren.com/pic/0004.jpg</img>
<img>http://www.xiaozhuren.com/pic/0005.jpg</img>
</more_images>
<!--商品更多辅助图片的绝对地址,图片类型:jpg、jpeg、png,不支持gif;最大:500k-->
<scids>101,102</scids>
<!--商户自定义类目ID,一个商品可以属于多个类目,半角逗号分隔-->
<post_fee>0</post_fee>
<!--邮费价格,精确到2位小数;单位:元;卖家承担运费邮费即为0-->
<props>颜色:棕色,白色;</props>
<!--SKU属性项、属性值,不同属性项间以分号分隔,不同属性值间以逗号分隔-->
<showcase>true</showcase>
<!--不填默认不推荐,true/false-->
<href>http://www.xiaozhuren.com/goods.php?id=14954</href>
<!--商品链接绝对地址-->
</item>增量索引与全量索引中对商品的升级操作:
增量文件中,对每个item都有一个操作指令,指令动作包含删除(delete)、上传(upload)2种操作;
全量文件只允许对item执行一种指令动作,上传(upload);
比如: <outer_id action="delete">10001</outer_id> 删除10001商品
<outer_id action="upload">10243</outer_id> 上传10243商品目录结构示例
全量更新与增量更新的区别:
全量更新每24小时发生一次,会清除之前的所有数据,清除后且只允许上传商品upload);
增量更新则每半个小时发生一次,不会清除之前的所有数据,而是在现有的数据上做数据更新(delete,upload),此处的upload相当于update。
JAVA:
fullIndexs.append("<?xml version=\"1.0\" encoding=\"GBK\"?>"+endLine);
fullIndexs.append("<root>"+endLine);
fullIndexs.append("<version>1.0</version>"+endLine);
fullIndexs.append("<modified>"+curDate+"</modified>"+endLine);
fullIndexs.append("<seller_id>XX官方网上商城</seller_id>"+endLine);
fullIndexs.append("<cat_url>"+showurl+"/taobao/SellerCats.xml</cat_url>"+endLine);
fullIndexs.append("<dir>"+showurl+"/taobao/item/</dir>"+endLine);
fullIndexs.append("<item_ids>"+endLine);
for(int i=0; i<prorows; i++){
dsproData.goToRow(i);
String productid = dsproData.getValue("productid");
String pm = dsproData.getValue("pm");
String x_price = dsproData.getValue("x_price");
String color = dsproData.getValue("color");
String s_gid = dsproData.getValue("s_gid");//商品详情id
String on_shelves = dsproData.getValue("on_shelves");//上架情况
if(on_shelves.equals("0"))
fullIndexs.append("<outer_id action=\"delete\">"+cpid+"</outer_id>"+endLine);
else
fullIndexs.append("<outer_id action=\"upload\">"+cpid+"</outer_id>"+endLine);
//上架商品生成商品信息数据
if(!on_shelves.equals("0")){
createProinfo(cpid,pm,x_price,s_gid,color,showurl);
}
}
fullIndexs.append("</item_ids>"+endLine);
fullIndexs.append("</root>");
}
String strinfo = incrementIndexs.length() > 0 ? incrementIndexs.toString() : fullIndexs.toString();
try {
String path = rootpath+"taobao/"+ (incrementIndexs.length() > 0 ? "IncrementIndex.xml" : "FullIndex.xml");//文件保存路径,名字
File file = new File(path);
BufferedWriter ow = new BufferedWriter(new FileWriter(file));
ow.write(strinfo);
ow.close();
}catch(Exception e){
e.printStackTrace();
}
PHP:
<?php/**
* 生成淘宝搜索feed文件
*/set_time_limit('300');//设置为300秒
define('IN_ECS', true);
require(dirname(__FILE__) . '/../includes/init.php');
@ini_set('display_errors', 1);
define('LM_TAOBAO_UESER_NAME', 'XX官网');$action = !empty($_REQUEST['act']) ? trim($_REQUEST['act']) : '';
//http://www.xxxxxx.com/taobao/feed/taobao_xml.php?act=genGoods
//http://www.xxxxxx.com/taobao/feed/taobao_xml.php?act=gencat
$feed_header = '<?xml version="1.0" encoding="utf-8"?>';if (strtolower($action) == 'gencat')
{
feed_genSellerCatsXml();
echo "<a href='SellerCats.xml'> 查看</a>";
exit;
}if (strtolower($action) == 'gengoods')
{
feed_genIncrementIndexXml();
echo "<a href='IncrementIndex.xml'> 查看</a>";
exit;
}/**
*
* 获取上一次生成的商品信息目录
*/
function feed_taobao_last_goods_list()
{
$t = array();
if (file_exists('log.xml'))
{
$xml = new DOMDocument();
$xml->load('log.xml');
$main = $xml->getElementsByTagName('item_ids');
foreach($main as $main)
{
$list = $main->getElementsByTagName( "outer_id" );
foreach ($list as $list)
{
$value = $list->firstChild->nodeValue;
//$attr = $list->getAttribute('action');
$t[] = $value;
}
}
}
asort($t);
return $t;
}/**
*
* 自定义类目文件
*/
function feed_genSellerCatsXml()
{
global $smarty, $feed_header;
$cats = cat_list(0, 0, false);
if (empty($cats))
{
return false;
} $pr = array();
foreach ($cats as $key => $val)
{
if(empty($val['parent_id']))
{
$pr[$key]['cat_id'] = $val['cat_id'];
$pr[$key]['cat_name'] = feed_replace($val['cat_name']);
}
}
foreach ($pr as $k => $v)
{
$pr[$k]['child'] = feed_gen($v['cat_id'], $cats);
}
$smarty->assign('seller_id', LM_TAOBAO_UESER_NAME);
$smarty->assign('date', local_date("Y-m-d H:i:s", gmtime()));
$smarty->assign('cats', $pr);
$xml = $smarty->fetch('xml/taobao/SellerCats.xml'); @file_put_contents('SellerCats.xml', $feed_header.$xml);
}function feed_replace($str)
{
$html = htmlspecialchars($str, ENT_QUOTES);
return $html;
}function feed_gen($cat_id, $array)
{
$cat_id = intval($cat_id);
$b = array();
foreach ($array as $k => $v)
{
if (intval($v['parent_id']) == $cat_id)
{
$b[$k]['cat_id'] = $v['cat_id'];
$b[$k]['cat_name'] = feed_replace($v['cat_name']);
}
}
return $b;
}function feed_write($filename, $data)
{
if (is_writable($filename))
{
if (!$handle = fopen($filename, 'a'))
{
echo "不能打开文件 $filename";
exit;
}
if (fwrite($handle, $data) === FALSE)
{
echo "不能写入到文件 $filename";
exit;
}
echo "成功地将 $data 写入到文件$filename";
fclose($handle);
}
else
{
echo "文件 $filename 不可写";
}
}
/**
*
* 生成数据索引文件(有两种1、全量索引2、增量索引 我们使用全量索引)和生成商品数据包
*/
function feed_genIncrementIndexXml()
{
global $smarty, $feed_header;
$gls = new GoodsListService();
$onsale = $gls->onsale();
$last = feed_taobao_last_goods_list();
$newadd = feed_check_userable_goods($last, $onsale);//新增的商品
$newadd = feed_get_not_onsale($last, $onsale, $newadd);
//var_dump($goods_list);exit;
$smarty->assign('seller_id', LM_TAOBAO_UESER_NAME);
$smarty->assign('cat_url', 'http://www.xxxxxx.com/taobao/SellerCats.xml');
$smarty->assign('dir', 'http://www.xxxxxx.com/taobao/item/');
$smarty->assign('date', local_date("Y-m-d H:i:s", gmtime()));
$smarty->assign('goods', $newadd);
$xml_f = $smarty->fetch('xml/taobao/IncrementIndex.xml');
file_put_contents('IncrementIndex.xml', $feed_header.$xml_f);
dataFormat::deldir('item');
if (!file_exists('item'))
{
mkdir('item');
}
if (!empty($newadd))
{
foreach ($newadd as $key => $va)
{
if (empty($va))
{
continue;
}
//图片
$images = get_gallery_inf($va['goods_id']);
//尺码
$goods_spec = get_goods_properties($va['goods_id']);
$goods_size = $gls->get_goods_size($goods_spec['spe'][1]['values']);
//颜色
$goods_color = get_colour($va['goods_id']);
$color = $goods_color[0]['img_desc'];
$c = !empty($color) ? '颜色:'.$color.';' : '';
$s = !empty($goods_size) ? '尺码:'.$goods_size.';' : '';
$smarty->assign('seller_id', LM_TAOBAO_UESER_NAME);
$smarty->assign('goods', $va);
$smarty->assign('images', $images);
$smarty->assign('property', $c.$s);
$xml_g = $smarty->fetch('xml/taobao/goods.xml');
file_put_contents('item/'.$va['goods_id'].'.xml', $feed_header.$xml_g);
//var_dump($va);exit;
}
feed_log_write($onsale);
}
}/**
*
* 删除下架商品
* @param array $g1 上一次的收录的商品id
* @param array $g2 当前上架商品信息
* @param array $g3 新增的商品信息
*/
function feed_get_not_onsale($g1, $g2, $g3)
{
if (empty($g1))
{
return $g3;
}
$n = array();
$b = array();
foreach ($g2 as $key => $val)
{
$n[] = $val['goods_id'];
}
foreach ($g1 as $k => $val)
{
if(!in_array($val, $n))
{
$b['goods_id'] = $n;
$b['is_delete'] = 1;
}
}
array_push($g3, $b);
return $g3;
}function feed_log_write($goods)
{
global $smarty, $feed_header;
$smarty->assign('date', local_date("Y-m-d H:i:s", gmtime()));
$smarty->assign('amount', count($goods));
$smarty->assign('goods', $goods);
$xml = $smarty->fetch('xml/taobao/log.xml');
file_put_contents('log.xml', $feed_header.$xml);
}/**
*
* 检查哪些商品可以提供
* @param $last 上一次提供的上架商品id数组
* @param $n 本次所有上架商品
*/
function feed_check_userable_goods($last, $n)
{
if (empty($last) && empty($n))
{
return false;
} if (empty($last) && !empty($n))
{
//echo 'ddd';exit;
return $n;//如果是第一次则全部生成
}
foreach ($n as $k=>$v)
{
if (in_array($v['goods_id'], $last))
{
unset($n[$k]);
}
} return $n;
}?>