ebay api不允许我存储变化sku

时间:2014-04-17 10:01:49

标签: php xml api soap-client oscommerce

有谁可以看到为什么下面的代码只为非变异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-&gt; ItemID和$ value-&gt; SKU插入我的数据库时,它不会插入变量SKU。

插入所有项目的ItemID,并插入非变量项目的SKU。

示例:

ItemID 111323665800存储SKU CT3012 - 存储BON

存储了ItemID 111323665899但是它存在了SKU 10117-1

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

示例中的两个项的XML结构都不同。第一项的SKU作为Item数组的直接子项返回。但是,第二项的SKU嵌套在Item-&gt; Variations中。

要获取具有变体的商品的SKU,您需要检查Item-&gt; Variations是否存在。如果是,则应循环遍历每个Variation并以与示例代码类似的方式获取每个SKU。

答案 1 :(得分:0)

我几乎做了我想做的事,但我坚持使用下面的代码 在两个回声中,它输出正确的结果,但我在将结果$ value-&gt; SKU和$ value-&gt; 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**  /////

}