PHP を使用して XML ドキュメントを解析しようとしています。理由がわからない非常に奇妙なエラーが発生することを除いて、基本的には機能しています。最初の ASIN の XML は次のとおりです。
<?xml version="1.0"?>
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetLowestOfferListingsForASINResult ASIN="1580230032" status="Success">
<AllOfferListingsConsidered>true</AllOfferListingsConsidered>
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>1580230032</ASIN>
</MarketplaceASIN>
</Identifiers>
<LowestOfferListings>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>New</ItemCondition>
<ItemSubcondition>New</ItemSubcondition>
<FulfillmentChannel>Merchant</FulfillmentChannel>
<ShipsDomestically>True</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>2</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>221</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>10.12</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>6.13</Amount>
</ListingPrice>
2 番目の ASIN の XML は次のとおりです。
<GetLowestOfferListingsForASINResult ASIN="0870714376" status="Success">
<AllOfferListingsConsidered>true</AllOfferListingsConsidered>
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>0870714376</ASIN>
</MarketplaceASIN>
</Identifiers>
<LowestOfferListings>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>New</ItemCondition>
<ItemSubcondition>New</ItemSubcondition>
<FulfillmentChannel>Merchant</FulfillmentChannel>
<ShipsDomestically>True</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>2</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>1416</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>18.49</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>14.50</Amount>
</ListingPrice>
ご覧のとおり、これらのそれぞれの金額は異なりますが、プログラムを実行すると、最初の ASIN からのみ金額を取得しています。結果を取得するための私のPHPコードは次のとおりです。
$parsed_xml = amazon_xml($isbn);
$current = $parsed_xml->ListMatchingProductsResult->Products->Product;
$asin = $current->Identifiers->MarketplaceASIN->ASIN;
// get information based on the items ASIN
$price_xml = amazonPrice_xml($asin, $ItemCondition);
$currentPrice = $price_xml ->GetLowestOfferListingsForASINResult->Product->LowestOfferListings->LowestOfferListing;
// check to see if there are values
if(!empty($currentPrice))
{
foreach($currentPrice as $offer){
$totalFeedback = $offer->SellerFeedbackCount;
//if ($totalFeedback >99) {
$condition = $offer->Qualifiers->ItemSubcondition;
//amazon condition matching algorithm (so we can match our condition up against amazons conditions)
switch ($condition) {
case "New":
$amazonCondition = 5;
break;
case "Mint":
$amazonCondition = 4;
break;
case "VeryGood":
$amazonCondition = 3;
break;
case "Good":
$amazonCondition = 2;
break;
case "Acceptable":
$amazonCondition = 1;
break;
default:
$amazonCondition = 0;
}
$lowestAmazonPrice = 0;
$currentPrice = $price_xml ->GetLowestOfferListingsForASINResult->Product->LowestOfferListings;
foreach($currentPrice->LowestOfferListing as $offer){
if( ($ourCondition = $amazonCondition) /*&& ($totalFeedback >= 5000)*/) {
$offerArray[$y] = str_replace('$','',$offer->Price->ListingPrice->Amount);
$y++;
}
}
$lowestAmazonPrice = min($offerArray);
}
if ($fillzPrice > $lowestAmazonPrice ) {
$avgPrice = ($lowestAmazonPrice - ($lowestAmazonPrice * .08));
$source = "Adjusted Fillz Price";
} else {
$avgPrice = $fillzPrice;
$source = "Original Price";
}
// check to make sure we are not going below established floor for prices
if($avgPrice < ($follettPrice * 2.37)){
$avgPrice = $follettPrice * 2.37;
$source = "Follett Pricing";
}
if($avgPrice < ($row['cost'] * 2)){
$avgPrice = $row['cost'] * 2;
$source = "Double Cost";
}
/*if($avgPrice < 5.50){
$avgPrice = 5.50;
$source = "Lowest Base Cost";
}*/
//update fillzPrice
$conn->query("UPDATE inventory SET ourPrice = $avgPrice, upload = '1' WHERE sku=" . $row['sku']);
$pricedSKU[$n] = array('sku' => $row['sku'],
'new price' => number_format($avgPrice, 2, '.', ''),
'price source' => $source,
'Fillz' => $fillzPrice,
'Amazon'=> $lowestAmazonPrice,
'asin'=> $asin,
'condition'=>$ourCondition
);
$n++;
}
}
前述したように、この問題を除いて、ほとんどの出力は正しいものです。結果を確認できるように、ASIN と金額が記載されたメールが送信されてきました。私が間違っていることと、それを修正する方法について何か考えはありますか?