skip to Main Content

Can anyone see why the code below only inserts the SKU for non variation SKU’s?

                $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;

the response results show:

<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>

But when I try to insert $value->ItemID and $value->SKU into my database it doesn’t insert the Variable SKU.

The ItemID for all items is inserted and SKU for non-variable items is inserted.

Example:

ItemID 111323665800 is stored SKU CT3012–BON is stored

ItemID 111323665899 is stored but SKU 10117-1 it ommited

Any suggestions?

2

Answers


  1. Chosen as BEST ANSWER

    I have it almost doing what i want but I am stuck with the code below in the two echoes it is outputting the correct results but I am having issues outputting the results $value->SKU and $value->ItemID into the database section of the script.

    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**  /////
    

    }


  2. The XML structure is different for both items in your example. The first item’s SKU is returned as a direct child of the Item array. However, the SKU for the second item is nested within Item->Variations.

    To get the SKU for items with variations, you need to check if Item->Variations exists. If it does, you should loop through each Variation and grab each SKU in a similar way to your example code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search