有人能理解为什么下面的代码只为非变体SKU插入SKU吗?
$client = new eBaySOAP($session);
$params = array(
'Version' => $Version,
'DetailLevel' => "ItemReturnDescription",
// 'GranularityLevel' => "Coarse",
'IncludeVariations' => "true",
'InventoryTrackingMethod' => "true",
'OutputSelector' => "SKU,ItemID,Title,Quantity,PaginationResult",
'EndTimeFrom' => date("c", mktime(date("H"), date("i")+10, date("s"), date("n"), date("j"), date("Y"))),
'EndTimeTo' => date("c", mktime(date("H"), date("i"), date("s"), date("n"), date("j")+120, date("Y"))),
'Pagination' => array(
'PageNumber' => $_GET['linkebaynum'],
'EntriesPerPage' => "20"
)
);
$results = $client->GetSellerList($params);
print "Response:<br>".ebay_formatxmlstring($client->__getLastResponse())."<br><br>";
if($results->Ack == "Success")
{
echo "updating page ".$_GET['linkebaynum']." of ".$results->PaginationResult->TotalNumberOfPages."...<br>";
foreach($results->ItemArray->Item as $key => $value) {
echo '>>>>>>>>>>>>>>val>>' . $value->SKU;
响应结果显示:
<Ack>Success</Ack>
<Version>867</Version>
<Build>E867_INTL_APISELLING_16763909_R1</Build>
<PaginationResult>
<TotalNumberOfPages>133</TotalNumberOfPages>
<TotalNumberOfEntries>2655</TotalNumberOfEntries>
</PaginationResult>
<ItemArray>
<ItemID>111323665800</ItemID>
<Quantity>1</Quantity>
<SellingStatus/>
<ShippingDetails/>
<Title>Oil And Water Drain Pan 16 Litre Galvanised</Title>
<SKU>CT3012--BON</SKU>
</Item>
<Item>
<ItemID>111323665899</ItemID>
<Quantity>5</Quantity>
<SellingStatus/>
<ShippingDetails/>
<Title>Cross Pein Hammer 4oz Wooden Handle</Title>
<Variations>
<Variation>
<SKU>10117-1</SKU>
<Quantity>1</Quantity>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-24</SKU>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-48</SKU>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-10</SKU>
<Quantity>1</Quantity>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-4</SKU>
<Quantity>1</Quantity>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-6</SKU>
<Quantity>1</Quantity>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-2</SKU>
<Quantity>1</Quantity>
<SellingStatus/>
</Variation>
<Variation>
<SKU>10117-12</SKU>
<SellingStatus/>
</Variation>
</Variations>
</Item>
<Item>
但是,当我尝试将$value->ItemID和$value->SKU插入数据库时,它不会插入变量SKU。
将插入所有项目的ItemID,并插入非可变项目的SKU。
示例:
ItemID 111323665800存储在SKU CT3012-BON存储在
ItemID 111323665899已存储,但SKU 10117-1已提交
有什么建议吗?
示例中这两项的XML结构不同。第一个项目的SKU将作为项目数组的直接子项返回。但是,第二个项目的SKU嵌套在项目->变体中。
要获取带有变体的商品的SKU,您需要检查商品->变体是否存在。如果是这样,您应该循环浏览每个变体,并以与示例代码类似的方式获取每个SKU。
我几乎让它做我想做的事,但我被下面的代码卡住了在两个回波中,它输出了正确的结果,但我在将结果$value->SKU和$value->ItemID输出到脚本的数据库部分时遇到了问题。
foreach($results->ItemArray->Item as $key=>$value){
if (isset($value->Variations->Variation)){
foreach($value->Variations->Variation as $key=>$var){
$value->SKU = $var->SKU;
$value->Quantity = $var->Quantity;
if($var->Quantity == ''){
$value->Quantity = '0';
}
echo 'Variation SKU = ' . $value->SKU . ' for ItemID - ' .$value->ItemID . ' - Qty = ' . $value->Quantity . '<br>';
}
}else{
echo 'Single SKU = ' . $value->SKU . ' for ItemID - ' .$value->ItemID . ' - Qty = ' . $value->Quantity . '<br>';
}
/////// **database inserts here insert $value->SKU ... Insert Value->ItemID** /////
}