magento2-akeneo-bundle icon indicating copy to clipboard operation
magento2-akeneo-bundle copied to clipboard

How to make "Unset Website when empty Product Attribute Mapping" work

Open thanninger opened this issue 3 months ago • 4 comments

Hey there,

I'm trying to understand how I can get the function "Unset Website when empty Product Attribute Mapping" to work. I found it in the Akeneo Connector Products section but there it shows two input fields for "Akeneo" and "Adobe Commerce". We have an Akeneo Simple select attribute (scopable and localizable) which I entered in the Akeneo input field, ran the import but it did not unset the product from the websites where the attribute was empty (no selection made). I also entered the attribute in both input fields, but again it did nothing.

Has the feature certain constraints that are not mentioned anywhere? Does it for example only work for Text or Metric attributes? Or does it not work for localizable attributes? (in that case it would be tragic, since we map the different locales from one Akeneo channel "shop" to multiple Magento Websites based on the locale.

Thanks in advance for your help! I really appreciate it! Christian

thanninger avatar Mar 22 '24 20:03 thanninger

This specific use case was for Akeneo Text / varchar attributes. This functionality was once created to ensure that the name is always filled in. As soon as this is not the case, the product is not added to the website. Magento will give error messages on the front-end when a name is not filled in.

However, this has been a bit of a thinking error, given that it also has an effect when someone in Akeneo suddenly adds a required attribute to a family and this is not filled in for a large part of the products in this family. Then the product is removed from the website and you get a lot of 404's.

I do not recommend using it, when working with multisite, please find other ways to manage the website_association attribute in Akeneo.

pimruiter avatar Mar 27 '24 21:03 pimruiter

Hi, thanks a lot for your response but I still don't understand it completely.

You and the configuration info say that each of the required attributes will be checked. So this refers to the required attributes that are declared in the Akeneo family, right? But when that's the case, why is there a field in the magento configuration where you can specify the attribute? I don't get the relation between these attribute fields in the magento config and the required attributes within akeneo.

And you say it only works for Akeneo text / varchar attributes - for no other attribute type? Thanks again!

thanninger avatar Apr 08 '24 07:04 thanninger

Since this feature may solve a big problem for us, it's important for me to understand it fully.

thanninger avatar Apr 08 '24 07:04 thanninger

@thanninger the required attributes that are defined in the Magento configuratie will each be checked. We use the akeneo code later on to determine if the attribute is localizable by getting this information from Akeneo. https://github.com/justbetter/magento2-akeneo-bundle/blob/master/Plugin/CheckWebsiteAssociation.php#L128

If the attribute is localizable we have to check multiple column's in the Akeneo tmp table to verify if the value has been set. If that's not the case for a specific locale we unset the website for the specific website / channel that locale belongs to. If the attribute is not localizable we check the one column that (possibly) holds a value for that attribute and then unsets website /channel if it's empty.

The reason we made this a separate Magento configuration instead of relying on the Akeneo configuration was to give more control over what attributes are required by Magento.

For example a Name attribute could be made a non-required attribute for a specific family which could (and will) influence completeness levels of that product.

Also the Product Completeness value in the Akeneo Connector configuration could be set lower then 100% which could results in the product being imported despite missing crucial attributes required by Magento to function.

I hope this information and backstory brings a bit of clarity. I must say I have not tested this with a select attribute but if you think this still suits your needs you could try it out in developer mode.

rbnmulder avatar Apr 11 '24 11:04 rbnmulder