Commerce pre-calculated price field
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
This module for Drupal Commerce allows to store and get access to calculated price (sell price) from database.
Features
- Ability to sort products by price including discounts
- Ability to create a view with list of discounted products
Prelude
The problem is that by default Drupal Commerce stores only base price without any sell price calculations so we can only view the price when it's shown on Product Display page and it's calculated dynamically. The most common problem comes up when we need to filter/sort by a such of prices. For example, if we have couple of products with prices $10 and $7, and after applying a discount 50% off for first product only, we'll have 2 products $5 and $7. But if we start to sort them by price we'll see that $7 goes before $5. Commerce Pre-calculated Field module fixes this problem. When you have calculated price as separate field for each of your product, you can work with it from Views or from you sql queries. So in this example we just need to sort by "calculated price" field to see $5 - $7 order.
Installation
1. Install as usual.
2. Just after installing go to Configure page of module (it will be proposed in message after enabling module). (admin/commerce/config/product-pricing/pre-calculation-field).
3. Here you need to pick Product types where field should be created and submit a form.
4. When you have products created - click on Generate pre-calculated prices button to fill up empty fields with calculated sell price.
5. Also click on Generate pre-calculated prices button every time you add/edit rules that affect on sell price, for example Discount rules.
After creating/updating products of selected types the sell price will be generated as well and ready to use.
Usage with Views
Sorting by price
- Open a view form and click on Add link in SORT CRITERIA section
- Find and pick Commerce Product: Calculated price (field_calculated_price:amount)
Discounts view
- Install 7.x-3.8 or higher version of Views module
- Open a view form and click on Add link in FILTER CRITERIA section
- Find and pick GLOBAL: Fields comparison
- Left field setup as Commerce Product: Price, Right field setup as Commerce Product: Calculated Price and Operator as Is not equal to
