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

fix(core): Add product translation to product variant entity resolver #2644

Conversation

oliverqx
Copy link
Contributor

@oliverqx oliverqx commented Jan 23, 2024

/claim #2171

Description

This fixes any custom fields of type LocaleString to return null on a collection query. Bug comes from product variant entity resolver not translating the product when its given productVariant argument has product already defined

productVariant gets its product property from a call to listQueryBuilder, which means its not translated.

(sorry about the double pr, wont happen again!)

Breaking changes

No breaking changes

Screenshots

You can add screenshots here if applicable.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

netlify bot commented Jan 23, 2024

Deploy Preview for effervescent-donut-4977b2 canceled.

Name Link
🔨 Latest commit 368a9fc
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-donut-4977b2/deploys/65b2c4061e9f0e000867d38c

@oliverqx oliverqx changed the title fix(product-variant-entity-resolver): Add product translation fix(core): Add product translation to product variant entity resolver Jan 23, 2024
Copy link
Member

@michaelbromley michaelbromley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on the resolver code. Also, do you think you'd be able to create a failing e2e test in this suite that demonstrates the bug & fix?

return this.requestContextCache.get(
ctx,
`ProductVariantEntityResolver.product(${productVariant.productId})`,
() => this.productVariantService.translateProduct(ctx, productVariant.product),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to create a brand new method .translateProduct() for this purpose. We can reuse getProductForVariant() which is already doing the translation step.

Which then would make both branches do the same thing, which also doesn't make sense. So there must be a logical branch in which this additional lookup/translation does not need to be done - that would be if the product is already translated. This can be tested by inspecting productVariant.product.name to see if it is defined. If so, we should be ok to just return it as-is like in the original version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, both branches are doing almost the same thing. I just pushed some changes. Also added the test.

To see the bug:

  1. Check out commit ac26c4a
  2. yarn build
  3. yarn e2e
  4. test fails

Fix:

  1. Checkout commit 368a9fc
  2. yarn build
  3. yarn e2e
  4. test does not fail

@michaelbromley michaelbromley merged commit 9289a1c into vendure-ecommerce:master Jan 26, 2024
17 of 18 checks passed
@michaelbromley
Copy link
Member

@oliverqx thank you! Can you contact me at m.bromley [at] vendure.io about the bounty payment?

@oliverqx
Copy link
Contributor Author

oliverqx commented Jan 26, 2024

@michaelbromley will do, thanks!

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

Successfully merging this pull request may close these issues.

2 participants