Discussions

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".

Thanks!

Posted: Nov 13, 2013

Comments

joshmiller Josh Miller on November 13, 2013

1) Download the following modules:

https://drupal.org/project/commerce_stock
https://drupal.org/project/ffc
https://drupal.org/project/field_formatter_settings
https://drupal.org/project/imagecache_actions

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!