Shipping calculators

Solidus comes with a set of default calculators that account for typical shipping scenarios:

All of Solidus's shipping calculators inherit from the Spree::ShippingCalculator class.

If the built-in calculators are not suitable for your store, you can create custom shipping calculators. For more information, see the Custom shipping calculators article.

The rest of this article summarizes the functionality of Solidus's built-in shipping calculators. Note that the code examples use preferred methods to set preference values. You can use these methods to update any preference. For example:

Ruby
    
      Spree::Calculator.find(1).update(preferred_currency: "EUR")

    
  

Flat percent

The Spree::Calculator::Shipping::FlatPercentItemTotal calculator has one preference, flat_percent, that takes an integer.

For each package that is shipped, this calculator takes the package's total and charges a percentage of it. For example:

  • An order has one shipment that includes three items.
  • The total of the three items is $190.
  • The calculator's flat_percent value is set to 10.
  • The shipping is calculated as 10% of $190: $190 * (10 / 100).

Flat rate

The Spree::Calculator::Shipping::FlatRate calculator can be used to provide a flat rate discount. It has the following preferences:

  • amount: The amount per item to calculate.
  • currency: The currency. This value must match an available shipping method. The default value is your store's default currency setting.

The currency for this calculator is used to check to see if a shipping method is available for an order. If an order's currency does not match a shipping method's currency, then that shipping method is not displayed on the frontend.

Flexi rate

The Spree::Calculator::Shipping::FlexiRate calculator provides a flexible rate depending on the items in a package. (Or, a subset of specific items in a package.) It has the following preferences:

  • first_item: The shipping price for the first item(s).
  • additional_item: The shipping price for subsequent items.
  • max_items: The maximum number of items that the rate applies to.
  • currency: The currency. This value must match an available shipping method. The default value is your store's default currency setting.

Flat rate per package item

The [Spree::Calculator::Shipping::PerItem calculator][flat-rate-per-item] computes a value for every item on an order. This is useful for providing a discount for a specific product without affecting other products. It has the following preferences:

  • amount: The amount per item to calculate.
  • currency: The currency. This value must match an available shipping method. The default value is your store's default currency setting.

Price sack

The Spree::Calculator::Shipping::PriceSack calculator is useful for when you want to provide a discount for an order which is over a certain price. The calculator has the following preferences:

  • minimal_amount: The minimum amount for the line items total to trigger the calculator.
  • normal_amount: The amount to discount from the order if the line items total is less than the minimal_amount.
  • discount_amount: The amount to discount from the order if the line items total is equal to or greater than the minimal_amount.
  • currency: The currency. This value must match an available shipping method. The default value is your store's default currency setting.

Feedback

Solidus is an open source platform supported by the community. We encourage everyone using Solidus to contribute back to the documentation and the code.

If you’re interested in contributing to the docs, get started with the contributing guidelines. If you see something that needs fixing and can’t do it yourself, please send us an email.