2017-03-10 170 views
2

這是我的代碼,但它返回從第三方賣家的最低價格,我做錯了什麼?我使用響應組提供,因爲它似乎是根據文檔獲取結果的方式。如何檢索亞馬遜api產品價格只爲亞馬遜merchantID

function getAmazonPrice($region, $asin) { 

    $xml = aws_signed_request($region, array(
     "Operation" => "ItemLookup", 
     "ItemId" => $asin, 
     "IncludeReviewsSummary" => False, 
     "ResponseGroup" => "Medium, Offers", 
     "MerchantId" => "Amazon", 
    )); 

    $item = $xml->Items->Item; 
    $title = htmlentities((string) $item->ItemAttributes->Title); 
    $url = htmlentities((string) $item->DetailPageURL); 
    $image = htmlentities((string) $item->MediumImage->URL); 
    $price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount); 
    $code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode); 
    $qty = htmlentities((string) $item->OfferSummary->TotalNew); 

    if ($qty !== "0") { 
     $response = array(
      "code" => $code, 
      "price" => number_format((float) ($price/100), 2, '.', ''), 
      "image" => $image, 
      "url" => $url, 
      "title" => $title 
     ); 
    } 

    return $response; 
} 

回答

0

我有同樣的問題。

我所做的,當亞馬遜提供的折扣是假設,它是在SalePrice:

$ SalePrice = $ xmlProduct->項 - >用品 - >優惠 - >優惠 - > OfferListing-> SalePrice->金額;

如果犯規存在該節點,那麼就沒有折扣,只是用上市價格:$ xmlProduct->項 - >用品 - >優惠 - >優惠 - > OfferListing->價格 - >金額