Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php解析XML文档时出现奇怪的结果_Php_Xml_Amazon - Fatal编程技术网

使用php解析XML文档时出现奇怪的结果

使用php解析XML文档时出现奇怪的结果,php,xml,amazon,Php,Xml,Amazon,我正在尝试使用PHP解析XML文档。它基本上是工作,除了我得到一个非常奇怪的错误,我不认为有理由。第一个ASIN的XML如下所示: <?xml version="1.0"?> <GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> <GetLowestOfferListingsForASINResult A

我正在尝试使用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>

真的
ATVPDKIKX0DER
1580230032
新的
新的
商人
真的
0-2天
95-97%
2.
221
美元
10.12
美元
6.13
第二个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>

真的
ATVPDKIKX0DER
0870714376
新的
新的
商人
真的
0-2天
98-100%
2.
1416
美元
18.49
美元
14.50
正如您所看到的,每一个的数量都是不同的,但是当我运行程序时,我只从第一个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++;

}

}
$parsed_xml=amazon_xml($isbn);
$current=$parsed_xml->ListMatchingProductsResult->Products->Products;
$asin=$current->Identifiers->MarketplaceASIN->asin;
//根据ASIN中的项目获取信息
$price\u xml=amazonPrice\u xml($asin$ItemCondition);
$currentPrice=$price_xml->getLowstofferistingsforasinResult->Product->Lowstofferistings->Lowstofferistings;
//检查是否有值
如果(!空($currentPrice))
{  
foreach(当前价格为$offer){
$totalFeedback=$offer->SellerFeedbackCount;
//如果($totalFeedback>99){
$condition=$offer->Qualifiers->ItemSubcondition;
//amazon条件匹配算法(因此我们可以将我们的条件与amazon条件进行匹配)
开关($条件){
案例“新”:
$amazonCondition=5;
打破
“铸币厂”一案:
$amazonCondition=4;
打破
“VeryGood”案:
$amazonCondition=3;
打破
案例“好”:
$amazonCondition=2;
打破
案例“可接受”:
$amazonCondition=1;
打破
违约:
$amazonCondition=0;
}
$lowstamazonprice=0;
$currentPrice=$price_xml->GetLowsTofferStingsForAsInResult->Product->LowsTofferStings;
foreach($currentPrice->LowerStofferList为$offer){
如果($ourCondition=$amazonCondition)/*&($totalFeedback>=5000)*/){
$offerArray[$y]=str_replace(“$”,“$offer->Price->ListingPrice->Amount);
$y++;
}   
}
$lowstamazonprice=min($offerArray);
}
如果($fillzPrice>$lowestAmazonPrice){
$avgPrice=($lowstamazonprice-($lowstamazonprice*.08));
$source=“调整后的Fillz价格”;
}否则{
$avgPrice=$fillzPrice;
$source=“原价”;
}
//检查以确保我们的价格不会低于既定的最低水平
如果($avgPrice<($follettPrice*2.37)){
$avgPrice=$follettPrice*2.37;
$source=“Follett定价”;
}
如果($avgPrice<($row['cost']*2)){
$avgPrice=$row['cost']*2;
$source=“双重成本”;
}
/*如果($avgPrice<5.50){
$avgPrice=5.50;
$source=“最低基本成本”;
}*/
//更新fillzPrice
$conn->query(“更新库存集ourPrice=$avgPrice,上传='1',其中sku=“.$row['sku']);
$pricedSKU[$n]=数组('sku'=>$row['sku'],
“新价格”=>number_格式($avgPrice,2,,,”),
“价格来源”=>$source,
“Fillz”=>fillzPrice美元,
“亚马逊”=>Lowstamazonprice美元,
“asin”=>asin美元,
“条件”=>$ourCondition
);
$n++;
}
}

如前所述,除此之外,大多数输出都是正确的。我收到了一封包含ASIN和金额的电子邮件,以便我可以检查结果。有没有关于我做错了什么以及如何纠正的想法?

如果其他人有此问题,解决方案是添加以下代码行:

 $offerArray = array();
在第一个while语句之后。现在一切都好了