Volume Pricing is an extension to Spree (a complete open source commerce solution for Ruby on Rails) that uses predefined ranges of quantities to determine the price for a particular product variant. For instance, this allows you to set a price for quantities between 1-10, another price for quantities between (10-100) and another for quantities of 100 or more. If no volume price is defined for a variant, then the standard price is used.
Each VolumePrice contains the following values:
acts_as_list
(Helps keep the volume prices in a defined order.)Add in your Gemfile
:
gem 'spree_volume_pricing', github: 'spree-contrib/spree_volume_pricing'
(run bundle install
)
The extension contains a rails generator that will add the necessary migrations and give you the option to run the migrations, or run them later, perhaps after installing other extensions. Once you have bundled the extension, run the install generator and its ready to use.
rails generate spree_volume_pricing:install
Easily add volume pricing display to your product page:
<%= render partial: 'spree/products/volume_pricing', locals: { product: @product } %>
Ranges are expressed as Strings and are similar to the format of a Range object in Ruby. The lower number of the range is always inclusive. If the range is defined with '..' then it also includes the upper end of the range. If the range is defined with '...' then the upper end of the range is not inclusive.
Ranges can also be defined as "open ended." Open ended ranges are defined with an integer followed by a '+' character. These ranges are inclusive of the integer and any value higher then the integer.
All ranges need to be expressed as Strings and can include or exclude parentheses. "(1..10)" and "1..10" are considered to be a valid range.
Consider the following examples of volume prices:
Variant Name Range Amount Position
-------------------------------------------------------------------------------
Rails T-Shirt 1-5 (1..5) 19.99 1
Rails T-Shirt 6-9 (6...10) 18.99 2
Rails T-Shirt 10 or more (10+) 17.99 3
Cart Contents:
Product Quantity Price Total
----------------------------------------------------------------
Rails T-Shirt 1 19.99 19.99
Cart Contents:
Product Quantity Price Total
----------------------------------------------------------------
Rails T-Shirt 5 19.99 99.95
Cart Contents:
Product Quantity Price Total
----------------------------------------------------------------
Rails T-Shirt 6 18.99 113.94
Cart Contents:
Product Quantity Price Total
----------------------------------------------------------------
Rails T-Shirt 10 17.99 179.90
Cart Contents:
Product Quantity Price Total
----------------------------------------------------------------
Rails T-Shirt 20 17.99 359.80
See corresponding contributing guidelines.
Copyright (c) 2009-2021 Spree Commerce and contributors, released under the New BSD License