magento / pwa-studio

🛠Development tools to build, optimize and deploy Progressive Web Applications for Magento 2.
https://developer.adobe.com/commerce/pwa-studio/
Open Software License 3.0
1.07k stars 683 forks source link

[bug]: Filterable product attributes wrong language/store #2442

Closed danlupo closed 4 years ago

danlupo commented 4 years ago

Describe the bug Have multiple storefronts in different languages (default english + french). Create a custom searchable/filterable product attribute and configure it's different labels.

In PWA Studio will access the default/english store, however the labels are french

To reproduce Steps to reproduce the behavior:

  1. Go to category listing page
  2. Click on filters
  3. Scroll down to see your filter options
  4. See labels in wrong language

Expected behavior Labels should be in the same language as the store

Screenshots Screen Shot 2020-05-29 at 4 22 18 PM Screen Shot 2020-05-29 at 4 39 51 PM

Additional context We've applied the elasticsearch patch described here also, but it seems unrelated. We suspect that it might be a graphql bug.

Please complete the following device information:

Please let us know what packages this bug is in regards to:

m2-assistant[bot] commented 4 years ago

Hi @danlupo. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


tjwiebell commented 4 years ago

@danlupo - thank you for the report. We have not yet implemented store switching into the app, so I would expect GraphQL to return whatever language the default storeview is. I believe your suspicion is correct, if you're not seeing that response from GraphQL, we'll need to create a bug for Magento core over in magento/magento2.

If you have implemented your own store switching, and you had previously fetched filters in French, you should be mindful of the Apollo cache. If you switched back to English, but didn't purge the Apollo cache, your cache would still have French filters and return those, instead of hitting the network. You can confirm this by deleting the apollo-cache-persist entry in LocalStorage and refreshing; if filters then return to english, the cache was your problem.

Closing this out as not a bug in Venia since we're just consumers of the GraphQL, but please re-open if there's something specific to Venia that's blocking you.

lano-vargas commented 4 years ago

@danlupo I have the same issue! I have 5 store view and I played around with the labels with store view when I leave all of them empty it will pick the Admin Value. But What I notice if I started adding them back one at the time and loading the PWA I noticed that it seem to be picking it up some sort of alphabetically order.

I've added for IE store view and here is the setup:

Screenshot 2020-08-18 at 11 11 26

Here is the result on PWA :

Screenshot 2020-08-18 at 11 14 35

Next I've added for German de store view see the results:

Screenshot 2020-08-18 at 11 18 26 Screenshot 2020-08-18 at 11 16 45

Now DE store view shows in the filter hmmm interesting de as d comes f4 the letter i fro ie store view it seems picking it up alphabetically.

Next NL reload the page and guess. it still showing DE label. see result:

Screenshot 2020-08-18 at 11 23 58 Screenshot 2020-08-18 at 11 24 39

NOTES: Clear Cache, and reload PWA in incognito every time testing it!

Results from graphiql playground: Screenshot 2020-08-18 at 12 05 21

I think this should be re-open to look at it again is seem and issue with query Order By or something else.

UPDATED: I've done a bit More investigation and the querry results is bellow:

SELECTa.attribute_id,a.attribute_code,a.frontend_labelASattribute_label,option_value.valueASoption_label,option_value.option_idFROMeav_attributeASaLEFT JOINeav_attribute_optionASoptionsON a.attribute_id = options.attribute_id LEFT JOINeav_attribute_option_valueASoption_valueON options.option_id = option_value.option_id WHERE (option_value.option_id IN (5431, 5432)) OR (a.attribute_code in ('color') AND a.frontend_input = 'boolean');

Screenshot 2020-08-18 at 12 42 50

It looks like to me is displaying the last result !

danlupo commented 4 years ago

@lano-vargas we actually moved this issue to magento support as it was not a PWA studio issue. Moreover we found the source and provided a patch there. Please check it out below. I hope this helps solve your issue.

--- a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php   2020-06-22 14:52:49.421201000 +0000
+++ b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php   2020-06-22 14:52:41.762499000 +0000
@@ -71,7 +71,7 @@
      */
     public function build(AggregationInterface $aggregation, ?int $storeId): array
     {
-        $attributeOptions = $this->getAttributeOptions($aggregation);
+        $attributeOptions = $this->getAttributeOptions($aggregation, $storeId);

         // build layer per attribute
         $result = [];
@@ -133,10 +133,11 @@
      * Get list of attributes with options
      *
      * @param AggregationInterface $aggregation
+     * @param int $storeId
      * @return array
      * @throws \Zend_Db_Statement_Exception
      */
-    private function getAttributeOptions(AggregationInterface $aggregation): array
+    private function getAttributeOptions(AggregationInterface $aggregation, int $storeId): array
     {
         $attributeOptionIds = [];
         $attributes = [];
@@ -154,6 +155,6 @@
             return [];
         }

-        return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $attributes);
+        return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $storeId, $attributes);
     }
 }

--- a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php 2020-06-22 14:56:58.633549000 +0000
+++ b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php 2020-06-22 14:53:00.977201000 +0000
@@ -41,11 +41,12 @@
      * Get option data. Return list of attributes with option data
      *
      * @param array $optionIds
+     * @param int $storeId
      * @param array $attributeCodes
      * @return array
      * @throws \Zend_Db_Statement_Exception
      */
-    public function getOptions(array $optionIds, array $attributeCodes = []): array
+    public function getOptions(array $optionIds, int $storeId, array $attributeCodes = []): array
     {
         if (!$optionIds) {
             return [];
@@ -76,6 +77,7 @@
             );

         $select->where('option_value.option_id IN (?)', $optionIds);
+        $select->where('option_value.store_id = ?', $storeId);

         if (!empty($attributeCodes)) {
             $select->orWhere(
sduif commented 4 years ago

Thanks! That fix is working for me!