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

[GraphQl] 28200 fixed issue with attribute label #29180

Closed
wants to merge 25 commits into from

Conversation

Usik2203
Copy link
Contributor

Description (*)

I am using magento 2.4 with Sample Data
Product for testing with SKU 24-UG07
Screenshot 2020-07-16 at 20 37 46

Result Before Fix

I see option_id of selected product attribute
Screenshot 2020-07-16 at 20 41 28

Result After Fix

I see value of selected product attribute
Screenshot 2020-07-16 at 20 43 51

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Graphql products query returns only ids for dropdows or multiselect fields #28200>

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 16, 2020

Hi @Usik2203. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

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.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 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-engcom-team magento-engcom-team added Component: CatalogGraphQl Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Jul 16, 2020
@Usik2203
Copy link
Contributor Author

@magento run all tests

@Usik2203
Copy link
Contributor Author

@magento run all tests

@Usik2203
Copy link
Contributor Author

@magento give me 2.4-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @Usik2203. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@prabhuram93
Copy link
Contributor

@Usik2203 Can you please add tests to cover this scenario. Thanks!

@magento-engcom-team
Copy link
Contributor

Hi @Usik2203, here is your Magento instance.
Admin access: https://i-29180-2-4-develop.instances.magento-community.engineering/admin_424e
Login: 43548653 Password: e2197132f81f
Instance will be terminated in up to 3 hours.

@avattam06
Copy link
Contributor

@Usik2203, Please check and fix the static test failures.

@rogyar rogyar self-assigned this Jul 18, 2020
Copy link
Contributor

@rogyar rogyar left a 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?

if ($attributeValue && !($attributeValue instanceof Phrase) ) {
return $attributeValue;
} else {
return isset($productArray[$product->getId()][$field])? $productArray[$product->getId()][$field] : null;
Copy link
Contributor

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.

Suggested change
return isset($productArray[$product->getId()][$field])? $productArray[$product->getId()][$field] : null;
return $productArray[$product->getId()][$field] ?? null;

Copy link
Contributor Author

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

Copy link
Contributor

@rogyar rogyar Aug 3, 2020

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

Copy link
Contributor Author

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

@Usik2203
Copy link
Contributor Author

@magento run WebAPI Tests

@Usik2203
Copy link
Contributor Author

@magento run WebAPI Tests

@Usik2203
Copy link
Contributor Author

@magento run all tests

@Usik2203
Copy link
Contributor Author

@magento run Integration Tests

@magento-engcom-team
Copy link
Contributor

Hi @rogyar, thank you for the review.
ENGCOM-8410 has been created to process this Pull Request

@cpartica
Copy link
Contributor

@Usik2203
https://user-images.githubusercontent.com/13517181/87704280-d9270b00-c7a4-11ea-933c-0ea3856fb9f3.png

isn't it better to have an array of attributes instead of coma separated values?
In the very near we are supposed to not have these attributes in the same level as static
check this out https://github.com/magento/architecture/pull/456/files

*/
private function getAttributeValue(Product $product, array $productArray, string $field)
{
if ($attribute = $product->getResource()->getAttribute($field)) {
Copy link
Contributor

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;
Copy link
Contributor

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..

@gabrieldagama
Copy link
Contributor

Hi @Usik2203, thanks for contributing!

Closing this one in favor of #31622 which implements a key-value approach, more suitable for this problem.

@m2-assistant
Copy link

m2-assistant bot commented Mar 23, 2021

Hi @Usik2203, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage Component: CatalogGraphQl Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Project: GraphQL Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graphql products query returns only ids for dropdows or multiselect fields
8 participants