I am new in Magento 2 and I want to change product visibility after saving product from backend using plugin.
For this I have created custom module and plugin, but I am not sure that we can achieve this using of plugin or not? Or Should I go with Observer?
I am trying something like : -
app/code/Custom/HelloWorld/etc/di.xml
<type name="Magento\Catalog\Model\Product">
<plugin name="Custom-HelloWorld-product-model" type="Custom\HelloWorld\Plugin\ProductPlugin" sortOrder="1" />
</type>
app/code/Custom/HelloWorld/Plugin/ProductPlugin.php
namespace Custom\HelloWorld\Plugin;
class ProductPlugin
{
public function beforeSetVisiblity(\Magento\Catalog\Model\Product $subject, $visiblity)
{
....
}
}
Please suggest. Thanks!