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] Webapi product custom attribute preprocessor #38633
Comments
Hi @gustavosolomon. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
I found that if I send "custom_attributes" data as object instead of array of objects, it works.. So if I send like this, it works: {
"custom_attributes": {
"manufacturer": "test"
}
} that's because but if I send like this, it doesn't: {
"custom_attributes": [
{
"attribute_code": "manufacturer",
"value": "test"
}
]
} because so that's why I think we should change the |
Hi @engcom-Hotel. Thank you for working on this issue.
|
Hello @gustavosolomon, Thanks for the report and collaboration! We have referred to the redocly on the below URL: https://developer.adobe.com/commerce/webapi/rest/quick-reference/ According to the documentation of API
Please refer to the below screenshot for reference: Thanks |
Hi @engcom-Hotel ! Thanks for your review. Yes, that seems correct. So let's just stick with this API documentation example. And that's the one where the described problem happens. Maybe I could send a PR so you can better visualize where the problem occurs? |
Sure @gustavosolomon, We will wait for the PR. |
Hey @engcom-Hotel, I sent the PR so you can take a look. Some points to look at while analyzing the changes:
And since Reference (This is from my PR): magento2/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php Lines 362 to 364 in 71cef67
|
Thanks @gustavosolomon for the PR, I am marking this issue as a Thanks |
Hi @engcom-Hotel, thanks for the update. I just sent another PR, which should be good to go. Can you please take a look? Thanks! |
Description
This issue happens when you add a pre-processor object in "customAttributePreprocessors" array to "Magento\Framework\Webapi\ServiceInputProcessor" class by using di.xml.
The injected processors should implement the interface "Magento\Framework\Webapi\CustomAttribute\PreprocessorInterface".
The issue is: The added processor simply doesn't run. Because it looks there's an issue on how those processors are "validated" before run.
For what I've checked, this Webapi input pre-processors is not commonly used. Actually, is not used by Magento Community modules at all (at least for modules I have installed), but, is supported by the Magento codebase, so I guess it should be working correctly.
Preconditions
Pre-processor code example:
Steps to reproduce
manufacturer
value insidecustom_attributes
dataExpected result
custom_attributes
node data.Actual result
For what I've checked, the "issue" is happening in this context:
magento2/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php
Lines 359 to 363 in e1babcf
I think it should be called after the following line:
list($customAttributeCode, $customAttributeValue) = $this->processCustomAttribute($customAttribute);
Instead of calling the
runCustomAttributePreprocessors
function using$key
, like this:$this->runCustomAttributePreprocessors($key, $customAttribute);
it should be calling it using
$customAttributeCode
, like this:$this->runCustomAttributePreprocessors($customAttributeCode, $customAttribute);
Because
$key
here, refers to the sort order of the attribute inside "custom_attributes" data, when it should be based onattribute_code
.This will ensure that validator mechanism (which relies on attribute code) works correctly and runs the processor.
Additional code reference on how Magento validates those processors run:
magento2/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php
Lines 405 to 416 in e1babcf
The text was updated successfully, but these errors were encountered: