shopware icon indicating copy to clipboard operation
shopware copied to clipboard

feat: Products with variants should return the variant that match the search term in the product detail page

Open tamvt opened this issue 10 months ago • 8 comments

This pull request introduces functionality to ensure that products with variants return the most relevant variant matching the search term on the product detail page. It includes changes to the backend logic, storefront templates, and styles, along with corresponding unit tests.

Core Functionality Enhancements:

  • Updated ProductDetailRoute in Shopware\Core\Content\Product\SalesChannel\Detail\ProductDetailRoute to handle search terms and return the best-matching variant using a new method, findBestVariantByTerm. This method filters variants based on the search term provided in the request. [1] [2]

  • Before: https://github.com/user-attachments/assets/8f36429b-9b38-43d6-8924-00e695ab107d

  • After: https://github.com/user-attachments/assets/35081912-ce6e-444e-b59f-b8b9db2c0243

Storefront Template Updates:

  • Modified box-standard.html.twig to pass the search term and product ID as route arguments when navigating to the product detail page. [1] [2]

  • Enhanced search-suggest.html.twig to display variant options in the search suggestion results, showing both the product name and its variations.

  • Before: Screenshot 2025-06-05 at 14 47 56

  • After: image

  • The options are only displayed if the variant name is not overridden from its parent Screenshot 2025-06-17 at 10 43 07

  • Enable / Disable in the admin settings image

tamvt avatar Jun 05 '25 04:06 tamvt

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 54.41%. Comparing base (3a9820b) to head (3b5dc28). Report is 2 commits behind head on trunk.

:white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Core/Content/Product/ProductException.php 87.50% 1 Missing :warning:
...9644517AddListingVariantNameSystemConfigOption.php 90.00% 1 Missing :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #10298   +/-   ##
=======================================
  Coverage   54.41%   54.41%           
=======================================
  Files        4710     4711    +1     
  Lines      160066   160101   +35     
  Branches     8808     8808           
=======================================
+ Hits        87101    87125   +24     
- Misses      70376    70387   +11     
  Partials     2589     2589           
Flag Coverage Δ
jest-admin 60.75% <ø> (ø)
jest-storefront 69.49% <ø> (ø)
phpunit-migration 45.53% <90.00%> (+0.06%) :arrow_up:
phpunit-unit 47.46% <65.62%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 05 '25 04:06 codecov[bot]

hey @tamvt

this seems to be an improvement and not a bugfix. so we should not consider it for a backport

mitelg avatar Jun 05 '25 07:06 mitelg

Please show some screenshots of

Enhanced search-suggest.html.twig to display variant options in the search suggestion results, showing both the product name and its variations.

vienthuong avatar Jun 05 '25 07:06 vienthuong

It could be a UI break for themes when introducing the variant option under the name, my suggestion is adding a option in admin#/sw/settings/listing/index to indicate if they want to show variant name in search result (default is false)

vienthuong avatar Jun 11 '25 04:06 vienthuong

Closes #8812

vienthuong avatar Jun 13 '25 07:06 vienthuong

Closes #10296

vienthuong avatar Jun 13 '25 07:06 vienthuong

@tamvt Could you check if the options is only displayed if the variant name is not overrided from its parent?

vienthuong avatar Jun 13 '25 07:06 vienthuong

@tamvt please check the UI when advanced search is installed and redirect to variant function works with advanced search

vienthuong avatar Jun 13 '25 07:06 vienthuong