When searching through the XML that amazon gives me in return some products don't have an amount or package dimensions. The code the I have written so far to check that is this :
if($items->Products->Product->AttributeSets->children('ns2',TRUE)->ItemAttributes->ListPrice->Amount === null){ $amount = '0.00'; } elseif (isset($items->Products->Product->AttributeSets->children('ns2',TRUE)->ItemAttributes->ListPrice->Amount) === False){ $amount = $items->Products->Product->AttributeSets->children('ns2',TRUE)->ItemAttributes->ListPrice->Amount; }else{ $amount = '0.00'; } This code is the same for all of the problems. If I do not have these attributes set to null in the first if statement, then an error children() on null occurs. Which it would be if the attribute Amount was not found.
Example of Amount not being an attribute:
<GetMatchingProductForIdResult Id="082686074551" IdType="UPC" status="Success"> <Products> <Product> <Identifiers> <MarketplaceASIN> <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> <ASIN>B000UUZVI6</ASIN> </MarketplaceASIN> </Identifiers> <AttributeSets> <ns2:ItemAttributes xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd" xml:lang="en-US"> <ns2:Binding>Toy</ns2:Binding> <ns2:Brand>Rubie's</ns2:Brand> <ns2:Color>White</ns2:Color> <ns2:Department>unisex-child</ns2:Department> <ns2:Feature>Size : For ages 4 and up</ns2:Feature> <ns2:Label>Rubie's</ns2:Label> <ns2:Manufacturer>Rubie's</ns2:Manufacturer> <ns2:ProductGroup>Toy</ns2:ProductGroup> <ns2:ProductTypeName>TOYS_AND_GAMES</ns2:ProductTypeName> <ns2:Publisher>Rubie's</ns2:Publisher> <ns2:SmallImage> <ns2:URL>http://ecx.images-amazon.com/images/I/41u1YTVvESL._SL75_.jpg</ns2:URL> <ns2:Height Units="pixels">75</ns2:Height> <ns2:Width Units="pixels">67</ns2:Width> </ns2:SmallImage> <ns2:Studio>Rubie's</ns2:Studio> <ns2:Title>Child Rose Print White Tights Stocking Costume</ns2:Title> </ns2:ItemAttributes> </AttributeSets> <Relationships/> <SalesRankings/> </Product> <Product> </GetMatchingProductForIdResult> With the Amount Attribute:
<GetMatchingProductForIdResult Id="082686075824" IdType="UPC" status="Success"> <Products> <Product> <Identifiers> <MarketplaceASIN> <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> <ASIN>B001R4FMEW</ASIN> </MarketplaceASIN> </Identifiers> <AttributeSets> <ns2:ItemAttributes xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd" xml:lang="en-US"> <ns2:Binding>Toy</ns2:Binding> <ns2:Brand>Rubie's</ns2:Brand> <ns2:Color>Black</ns2:Color> <ns2:Department>teen-girls</ns2:Department> <ns2:Feature>Fun costumes for kids and adults</ns2:Feature> <ns2:Feature>Whether it's for Halloween, a themed party, or even for giggles</ns2:Feature> <ns2:Feature>Beautiful colors, hand-wash needed, excellent for dress up</ns2:Feature> <ns2:ItemDimensions> <ns2:Height Units="inches">8.00</ns2:Height> <ns2:Length Units="inches">15.00</ns2:Length> <ns2:Width Units="inches">8.00</ns2:Width> </ns2:ItemDimensions> <ns2:Label>Pro-Motion Distributing - Direct</ns2:Label> <ns2:ListPrice> <ns2:Amount>3.99</ns2:Amount> <ns2:CurrencyCode>USD</ns2:CurrencyCode> </ns2:ListPrice> <ns2:Manufacturer>Pro-Motion Distributing - Direct</ns2:Manufacturer> <ns2:ManufacturerMaximumAge Units="months">96.0</ns2:ManufacturerMaximumAge> <ns2:ManufacturerMinimumAge Units="months">18.0</ns2:ManufacturerMinimumAge> <ns2:Model>RUB7582ACC</ns2:Model> <ns2:PackageDimensions> <ns2:Height Units="inches">0.50</ns2:Height> <ns2:Length Units="inches">8.00</ns2:Length> <ns2:Width Units="inches">6.00</ns2:Width> <ns2:Weight Units="pounds">0.20</ns2:Weight> </ns2:PackageDimensions> <ns2:PackageQuantity>1</ns2:PackageQuantity> <ns2:PartNumber>RUB7582ACC</ns2:PartNumber> <ns2:ProductGroup>Toy</ns2:ProductGroup> <ns2:ProductTypeName>TOYS_AND_GAMES</ns2:ProductTypeName> <ns2:Publisher>Pro-Motion Distributing - Direct</ns2:Publisher> <ns2:Size>Teen</ns2:Size> <ns2:SmallImage> <ns2:URL>http://ecx.images-amazon.com/images/I/41A%2BY200WLL._SL75_.jpg</ns2:URL> <ns2:Height Units="pixels">75</ns2:Height> <ns2:Width Units="pixels">34</ns2:Width> </ns2:SmallImage> <ns2:Studio>Pro-Motion Distributing - Direct</ns2:Studio> <ns2:Title>Rubie's Costume Co Skull Tights-White/Black Costume</ns2:Title> <ns2:Warranty>30 day warranty against manufacturer defects</ns2:Warranty> </ns2:ItemAttributes> </AttributeSets> <Relationships/> <SalesRankings> <SalesRank> <ProductCategoryId>toy_display_on_website</ProductCategoryId> <Rank>1121721</Rank> </SalesRank> <SalesRank> <ProductCategoryId>251975011</ProductCategoryId> <Rank>7203</Rank> </SalesRank> <SalesRank> <ProductCategoryId>251940011</ProductCategoryId> <Rank>10177</Rank> </SalesRank> </SalesRankings> </Product> </Products> </GetMatchingProductForIdResult> I don't understand what the problem could possibly be. I appreciate the help in advance.
No comments:
Post a Comment