Image style depending on stock level

How can i change the image style for a product (variation) when the stock level has reached "Out of stock" level? Would be great to add a badge to the product image saying "SOLD".


Posted: Nov 13, 2013


joshmiller Josh Miller on November 13, 2013

1) Download the following modules:


2) Enable the following modules:

Commerce Stock UI
Commerce Simple Stock
Commerce Simple Stock Rules
Imagecache Actions
Imagecache Canvas Actions
Field formatter conditions
Field formatter settings API

Or run this drush command:

$ drush en imagecache_canvasactions, commerce_stock_ui, ffc -y

** Don't forget to manually enable Commerce Simple Stock and Commerce Simple Stock Rules

3) Configure your product so it has images and real stock values

4) Create a new image style

5) Add a rule that reacts on the event "field is being rendered" and has a condition of "data comparison" on the product's commerce_stock field and an action of "change image style."

6) Change the image style formatter to have a condition of "use an event rule" and then select your new rule that you created.

7) Profit!