Magento – Programatically set visibility to “Not visible individually” for other store views

multistoreproductproducts-management

When we create / edit product, then we select category and website, for store views whose category is not selected, the visibility should be set to "not visible".

Is it possible by default?

Best Answer

Not possible by default, no. You could try to write an observer for catalog_product_prepare_save, which is dispatched from the product save controller and receives the parameters product and request.

But with a single save, only one store view can be saved, so you cannot achieve what you want with manipulating the product object alone. You have to save the visibility attribute directly. Fortunately, there is a method for it:

addAttributeUpdate($code, $value, $store)

$product->addAttributeUpdate('visibility', false, $storeId);