Skip to content

Commit

Permalink
Give example for adding calculator
Browse files Browse the repository at this point in the history
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!)
  • Loading branch information
Filip Bartuzi committed Jun 11, 2014
1 parent 376e5d2 commit 4788520
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion guides/content/developer/core/calculators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -239,4 +246,4 @@ plan.compute_amount(<calculable object>)
```

`create_adjustment`, `update_adjustment` and `compute_amount` will call `compute` on the `Calculator` object. This `calculable` amount is whatever object your
`CustomCalculator` class supports.
`CustomCalculator` class supports.

0 comments on commit 4788520

Please sign in to comment.