-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[GraphQl] 28200 fixed issue with attribute label #29180
Conversation
Hi @Usik2203. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
@magento run all tests |
@magento give me 2.4-develop instance |
Hi @Usik2203. Thank you for your request. I'm working on Magento 2.4-develop instance for you |
@Usik2203 Can you please add tests to cover this scenario. Thanks! |
Hi @Usik2203, here is your Magento instance. |
@Usik2203, Please check and fix the static test failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Usik2203. Thank you for your collaboration. Please, check my recommendations below. Also, is there a chance to have this fix covered by a test?
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php
Outdated
Show resolved
Hide resolved
if ($attributeValue && !($attributeValue instanceof Phrase) ) { | ||
return $attributeValue; | ||
} else { | ||
return isset($productArray[$product->getId()][$field])? $productArray[$product->getId()][$field] : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may simplify this structure with null coalescing operator.
return isset($productArray[$product->getId()][$field])? $productArray[$product->getId()][$field] : null; | |
return $productArray[$product->getId()][$field] ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we will use simplify condition we can get error "Undefined index" in case where product don't have requested attribute. isset()
helps to avoid this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null coalescing operator should not generate the "Undefined Index" notice. Please, double-check it. You may refer to the official doc for more details
https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rogyar , Yes you are right .
I have applied this changes
Thanks
...sts/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithMultiselectAttributeTest.php
Outdated
Show resolved
Hide resolved
…ductWithMultiselectAttributeTest.php
@magento run WebAPI Tests |
...sts/api-functional/testsuite/Magento/GraphQl/Catalog/ProductWithMultiselectAttributeTest.php
Outdated
Show resolved
Hide resolved
…ductWithMultiselectAttributeTest.php
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php
Outdated
Show resolved
Hide resolved
@magento run WebAPI Tests |
@magento run all tests |
@magento run Integration Tests |
Hi @rogyar, thank you for the review. |
@Usik2203 isn't it better to have an array of attributes instead of coma separated values? |
*/ | ||
private function getAttributeValue(Product $product, array $productArray, string $field) | ||
{ | ||
if ($attribute = $product->getResource()->getAttribute($field)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what performance impact will this have
Ideally we would have a collection of all attributes needed in the query, load it once and use it for any product that needs it, like we do with products where first we add to collection and we return a function instead of loading at the same time getResource()->getAttribute($field))
See this code how to do this pattern, it's the same concept: \Magento\ConfigurableProductGraphQl\Model\Resolver\Options::resolve
Also we tried to stay away from $product->getResource()
instead we would inject the resource - this way it will make the performance problem more obvious
I can try to run this to see how much degradation it has, though I don't think we have by default such attributes that we test
if ($attribute = $product->getResource()->getAttribute($field)) { | ||
$attributeValue = $attribute->getFrontend()->getValue($product); | ||
if ($attributeValue && !($attributeValue instanceof Phrase)) { | ||
return $attributeValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this how we translate the label? or what does $attribute->getFrontend()->getValue($product) do?
it's best to inject frontend class ..whatever that class is...
Hope is not luma related..
Hi @Usik2203, thank you for your contribution! |
Description (*)
I am using magento 2.4 with Sample Data
Product for testing with SKU 24-UG07
Result Before Fix
I see option_id of selected product attribute
Result After Fix
I see value of selected product attribute
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)