Magento2 Product Attribute – Fix Global Product Attribute Empty on Store View Level

attributesconfigurationproduct-attribute

We have a strange situation. A global product attribute that is populated at the default config level is empty on store view level. The attribute scope is ofcourse set to global. See the image below to demonstrate.

Now I must admit that we needed to tweak the database eav_attribute: because we had defined these attributes as text when they should be dropdown.

The problem arises on the frontend where these attributes default to NO,NO NO as their values. And another interesting fact is that this only happens to configurable products that have been with us for some years. The lower SKU's ….

Store set-up

-- Main config 
|---- Store view 1 (current) 
|---- Store view 2 (new)

For example: Main config has a (global) setting with value A. Store view 2 shows this value A. But Store view 1 shows value "empty".

Question: anyone encountered this before?

Can it be that a value already existed on a store view level? [but manually changing and saving it on the store view level does nothing. They stay empty]

On default config level
enter image description here

On store view level
enter image description here

Best Answer

Here is a quick fix.
you need to identify the attribute ids for all global attributes then delete all the values from the catalog_product_entity_* tables that have the attribute id one of those identified above and the store id field not zero.

DELETE FROM `catalog_product_entity_int` 
WHERE
   store_id <> 0 AND
   attribute_id IN (
           SELECT attribute_id 
           FROM catalog_eav_attribute 
           WHERE is_global = 1

   )

Do the same for the tables catalog_product_entity_varchar, catalog_product_entity_text, catalog_product_entity_datetime, catalog_product_entity_decimal.

Rebuild your indexes when your are done.

Note: The select from catalog_eav_attribute in the way I wrote it will give you attribute ids for the global category attributes also, but that's not important since in the product tables you don't have category attributes references.

Also, before trying this, backup your database in case I missed something.