From 478852072342ad227ed031f46970865e3dd33978 Mon Sep 17 00:00:00 2001 From: Filip Bartuzi Date: Wed, 11 Jun 2014 09:09:03 +0200 Subject: [PATCH] Give example for adding calculator Believe or not but I struggled a bit with adding my own calculator to spree. As some other folks: #1: http://grokbase.com/t/gg/spree-user/141amnc5ns/creating-spree-extension-uninitialized-constant #2: http://stackoverflow.com/questions/5119960/how-to-properly-load-a-handmade-extension-in-spree #3: https://www.ruby-forum.com/topic/4403156 It's all about naming convention so why not give example just in case someone forgot it (as I did!) --- guides/content/developer/core/calculators.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/guides/content/developer/core/calculators.md b/guides/content/developer/core/calculators.md index 0acbf434994..2d9d2574dfe 100644 --- a/guides/content/developer/core/calculators.md +++ b/guides/content/developer/core/calculators.md @@ -184,6 +184,13 @@ config.spree.calculators.shipping_methods << CustomCalculator config.spree.calculators.promotion_actions_create_adjustments << CustomCalculator ``` +For example if your calculator is placed in `app/models/spree/calculator/shipping/my_own_calculator.rb` you should call: + +``` +config = Rails.application.config +config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::MyOwnCalculator +``` + ### Determining Availability By default, all shipping method calculators are available at all times. If you wish to make this dependent on something from the order, you can re-define the `available?` method inside your calculator: @@ -239,4 +246,4 @@ plan.compute_amount() ``` `create_adjustment`, `update_adjustment` and `compute_amount` will call `compute` on the `Calculator` object. This `calculable` amount is whatever object your -`CustomCalculator` class supports. \ No newline at end of file +`CustomCalculator` class supports.