Can anyone provide a working example for creating a visual swatch (or even a text swatch) attribute as part of a setup script.
I've tried the example on Magento 2 create custom swatch attribute programmatically but it doesn't work for me.
The issue I've ran into there is that the the attribute repository cannot find the new attribute that was created. I tried putting some cache clearing in between but no luck.
Thanks.
Best Answer
Disclaimer: Parts of this code were taken from
Magento_SwatchesSampleData
core module. Also you might not needcolorMap
but I just put it there.This code was tested on Magento 2.1.4.
I assume you have an extension called
Goivvy_Custom
. I also assume you know how to install the extension and have magento run install scripts.The code below will create
new_swatch_attribute
Visual Swatch.Here is
Goivvy/Custom/Setup/InstallData.php
:Here is how it looks in Magento 2.1.4:
Any questions - let me know.