Smart attribute modifiers for Google Merchant Center
In certain situations it is necessary to modify the value of an attribute before it gets updated in Merchant Center. If you sell jeans for example, often the size attribute is a combination between the waist size and length size. It is not uncommon to have these two as separate attributes in your Magento 2 store which makes it very difficult to maintain. A size attribute in Merchant Center may be a combination of these both e.g. W34/L33.
Our smart modifiers come to the rescue. Smart modifiers is a special feature of our Google Merchant API extension for Magento 2 that allow you to modify the value of an attribute based on a condition or a combination of conditions. Modifications possible vary from changing to fix value to applying a mathematical operation.
We call them smart modifiers because you can type the desired modification as simple text and the extension will automatically decide what type of modification is required. To best describe how modifiers work, find below a few common examples:
Modifier: +10
In this case, a fixed 10 will be added to the value of an attribute. It will check if the attribute is a numeric value first. Also, the extension won't allow for value to drop below 0 in case of negative sign e.g. -100
Modifier: +20%
In this case, the value of the attribute will be increased with 20%. It is possible to use a negative sign as well e.g. -20%
Modifier: price,cost
In this case, the value of the attribute will be replaced with the sum of the values of price and cost attributes
Modifier: price,20%
In this case, the value of the attribute will be calculated by incrementing the value of the price attribute with 20%
Modifier: 10,+20%
In this case, the value of the attribute will be increased first with fixed 10, then the calculated value will be increased with 20%
These are just a few examples of most common modifications possible with our smart modifiers.
MORE COMPLEX OPERATIONS
We have designed the extension in such way that developers can easily add more complex attribute modifications by hooking to myriad of custom Magento 2 events dispatched by the extension.
General event that fires always
merchant_center_set_attribute
Attribute specific event that fires for specific attributes
merchant_center_set_[attribute] ... [attribute] can be any of the attributes available in Merchant Center + Customer Attributes from the EAV system of Magento 2