Event-Observer for whenever the stock status of product changes

You can use catalog_product_save_after, checkout_submit_all_after ,cataloginventory_stock_revert_products_sale, sales_order_item_cancel(Depending ) and get the stock status. You can even check for that product attribute value is as desired out of stock and that out of stock do nothing else update the attribute value .
Put this events.xml in below path

app\code\YOUR_NAMESPACE\YOURMODULE\etc\



    
        
    

And put your Productsaveafter.php in below path

app\code\YOUR_NAMESPACE\YOURMODULE\Observer\

getProduct(); // you will get product object and you can check for stock and attribute values here

    }   
}

你可能感兴趣的:(magento2)