feat: Products with variants should return the variant that match the search term in the product detail page
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
ProductDetailRouteinShopware\Core\Content\Product\SalesChannel\Detail\ProductDetailRouteto 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.twigto pass the search term and product ID as route arguments when navigating to the product detail page. [1] [2] -
Enhanced
search-suggest.html.twigto display variant options in the search suggestion results, showing both the product name and its variations. -
Before:
-
After:
-
The options are only displayed if the variant name is not overridden from its parent
-
Enable / Disable in the admin settings
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.
hey @tamvt
this seems to be an improvement and not a bugfix. so we should not consider it for a backport
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.
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)
Closes #8812
Closes #10296
@tamvt Could you check if the options is only displayed if the variant name is not overrided from its parent?
@tamvt please check the UI when advanced search is installed and redirect to variant function works with advanced search