Show a sale price and discount percentage in Commerce 2

by Patrick Kenny   Last Updated November 13, 2017 16:07 PM

I want to show the original/list price and sale price (actual price) in my store as well as the discount percentage: N% off!

In Drupal 7, there is the excellent Commerce Price Savings Formatter module-- just install the module, set the prices, and you're done.

What can I do in Drupal 8? I have tried to use the built-in promotion feature in Commerce 2, but as far as I can tell the promotion UI can only be used to create coupons, not discounts that automatically apply to the relevant orders. (based on a reading of the documentation and experimenting with the module).

Answers 1

Here's a basic way to implement this in Commerce 2 if you don't need everything done automatically.

  1. Go to the "product type" admin page for the relevant product type and choose Manage fields.
  2. Add a price field, list price. Make sure to check the box for the right currency; I couldn't get the form to save without doing so.
  3. Add an integer field, set the min value 0 and the max value 100, and then the suffix as %.
  4. Use Views or a theme template to add some CSS classes to theme it nicely.
Patrick Kenny
Patrick Kenny
November 13, 2017 16:03 PM

Related Questions

Find number of downloads in drupal commerce

Updated July 14, 2015 14:03 PM

Add multiple cart in drupal 7

Updated August 15, 2015 17:03 PM