Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in GetMatchingProductForId, I cannot get which id type's api response. #193

Open
arammarm opened this issue Sep 23, 2019 · 2 comments
Labels

Comments

@arammarm
Copy link

When i make request

$upc = ['190021324893', '796201587166', '32323231111', '211212122'];
$product_list = new AmazonProductList( 'store1' );
$product_list->setIdType( "UPC" );
$product_list->setProductIds( $upc );
$product_list->fetchProductList();
$product_list->getProduct();

I don't understand which results is which upc's, also i cannot get by order because when wrong upc it's return just response with 'error' array key. when it more than one error it's replace the previous error response. so hard to match the response with upc.

@Peardian
Copy link
Collaborator

You're right, it seems I had not accounted for there being more than one error. Storing the errors in an array seems like it would be the best solution. Thank you for reporting this.

@Peardian Peardian added the bug label Sep 23, 2019
@arammarm
Copy link
Author

Now i modified the parseXML function on /src/AmazonProductsCore.php

protected function parseXML($xml)
    {
        if (!$xml) {
            return false;
        }

        foreach ($xml->children() as $x) {
            if ($x->getName() == 'ResponseMetadata') {
                continue;
            }
            $temp = (array)$x->attributes();
            if (isset($temp['@attributes']['status']) && $temp['@attributes']['status'] != 'Success') {
                $this->log("Warning: product return was not successful", 'Warning');
            }
            if (isset($x->Products)) {
                foreach ($x->Products->children() as $z) {
                    $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode,
                        $this->mockFiles);
                    $this->index++;
                }
            } else {
                if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult') {
                    $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode,
                        $this->mockFiles);
                    $this->index++;
                } else {
                    foreach ($x->children() as $z) {
                        if ($z->getName() == 'Error') {
                            $error = (string)$z->Message;
                            $this->productList[$this->index]['Error'] = $error;
                            $this->log("Product Error: $error", 'Warning');
	                        $this->index++;
                        } elseif ($z->getName() != 'Product') {
                            $this->productList[$this->index][$z->getName()] = (string)$z;
                            $this->log("Special case: " . $z->getName(), 'Warning');
	                        $this->index++;
                        } else {
                            $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode,
                                $this->mockFiles);
                            $this->index++;
                        }
                    }
                }
            }
        }
    }

Now i can get response by given order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants