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

ItemSearchResults __construct fails, if the response misses the pagination information #740

Closed
KhorneHoly opened this issue Jun 24, 2024 · 3 comments

Comments

@KhorneHoly
Copy link

KhorneHoly commented Jun 24, 2024

Example response:

{
    "items": [
        {
            "asin": "3465018532",
            "attributes": {
                "binding": [
                    {
                        "marketplace_id": "A1PA6795UKMFR9",
                        "value": "hardcover"
                    }
                ],
                "externally_assigned_product_identifier": [
                    {
                        "marketplace_id": "A1PA6795UKMFR9",
                        "type": "isbn",
                        "value": "3465018532"
                    },
                    {
                        "marketplace_id": "A1PA6795UKMFR9",
                        "type": "ean",
                        "value": "9783465018537"
                    }
                ],
                "item_name": [
                    {
                        "language_tag": "de_DE",
                        "marketplace_id": "A1PA6795UKMFR9",
                        "value": "Revolution, Reform, Restauration. Formen der Veränderung von Recht und Gesellschaft"
                    }
                ],
                "product_site_launch_date": [
                    {
                        "marketplace_id": "A1PA6795UKMFR9",
                        "value": "2007-01-30T02:57:53-00:00"
                    }
                ],
                "recommended_browse_nodes": [
                    {
                        "marketplace_id": "A1PA6795UKMFR9",
                        "value": "3355581"
                    }
                ]
            },
            "dimensions": [
                {
                    "marketplaceId": "A1PA6795UKMFR9"
                }
            ],
            "identifiers": [
                {
                    "identifiers": [
                        {
                            "identifier": "9783465018537",
                            "identifierType": "EAN"
                        },
                        {
                            "identifier": "3465018532",
                            "identifierType": "ISBN"
                        }
                    ],
                    "marketplaceId": "A1PA6795UKMFR9"
                }
            ],
            "images": [
                {
                    "images": [],
                    "marketplaceId": "A1PA6795UKMFR9"
                }
            ],
            "salesRanks": [
                {
                    "classificationRanks": [],
                    "displayGroupRanks": [],
                    "marketplaceId": "A1PA6795UKMFR9"
                }
            ],
            "summaries": [
                {
                    "adultProduct": false,
                    "autographed": false,
                    "browseClassification": {
                        "classificationId": "143",
                        "displayName": "Politik & Geschichte"
                    },
                    "itemClassification": "BASE_PRODUCT",
                    "itemName": "Revolution, Reform, Restauration. Formen der Veränderung von Recht und Gesellschaft",
                    "marketplaceId": "A1PA6795UKMFR9",
                    "memorabilia": false,
                    "tradeInEligible": false,
                    "websiteDisplayGroup": "book_display_on_website",
                    "websiteDisplayGroupName": "Book"
                }
            ]
        }
    ],
    "numberOfResults": 1
}

This triggers the following error:
request.CRITICAL: Uncaught PHP Exception ArgumentCountError: "SellingPartnerApi\Seller\CatalogItemsV20220401\Responses\ItemSearchResults::__construct(): Argument #2 ($pagination) not passed" at ItemSearchResults.php line 29

Same issue is true for the refinements. By the documentation both are required in the response, but truth is that both might be missing. Just do a search with a single ASIN to force a response with a single item found.

Since this is a generated class, how would be go about solving this issue? Manually changing the JSON used for generation doesn't seem future proof to me.

@jlevers
Copy link
Owner

jlevers commented Jun 24, 2024

This is the purpose of the modifications.json file, which is documented here. I'd use that to handle this issue. If you need more guidance after taking a look at those links, let me know :)

@KhorneHoly
Copy link
Author

This is the purpose of the modifications.json file, which is documented here. I'd use that to handle this issue. If you need more guidance after taking a look at those links, let me know :)

Thanks, didn't noticed that, sorry. Created a pull request.

Note: The generation method touched multiple dozens of files, while one one did in fact change.
I needed to revert a lot of changes done by the process.

All of that changes were changes in formatting. Spaces to intend were changed, the placement of the curly brackets was changed a bit, spaces within the Docblock were changed a bit.

Example constructor before the generation:

public function __construct(
        protected array $marketplaceIds,
        protected ?array $identifiers = null,
        protected ?string $identifiersType = null,
        protected ?array $includedData = null,
        protected ?string $locale = null,
        protected ?string $sellerId = null,
        protected ?array $keywords = null,
        protected ?array $brandNames = null,
        protected ?array $classificationIds = null,
        protected ?int $pageSize = null,
        protected ?string $pageToken = null,
        protected ?string $keywordsLocale = null,
    ) {}

After generation:

public function __construct(
		protected array $marketplaceIds,
		protected ?array $identifiers = null,
		protected ?string $identifiersType = null,
		protected ?array $includedData = null,
		protected ?string $locale = null,
		protected ?string $sellerId = null,
		protected ?array $keywords = null,
		protected ?array $brandNames = null,
		protected ?array $classificationIds = null,
		protected ?int $pageSize = null,
		protected ?string $pageToken = null,
		protected ?string $keywordsLocale = null,
	) {}

Also, the changes we had done to the Deserialies.php Trait were reverted back to the faulty state. The file doesn't state that it is auto generated, but it changes with the schema:generate command.

I'm a bit in a hurry right now, so I can't dig deeper into this, but I wanted to let you know about that. Maybe there's something missing to unify the generation.

@jlevers
Copy link
Owner

jlevers commented Jul 9, 2024

I think we resolved in this in the PR, but those changes were because the current flow assumes composer lint will be run after codegen. Maybe I'll update the build process to automatically run the linter.

@jlevers jlevers closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants