Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #236 from Bartuz/patch-1
Browse files Browse the repository at this point in the history
Give example for adding calculator
  • Loading branch information
JDutil committed Jul 22, 2014
2 parents cb42a66 + 9999ed0 commit 4eaeb05
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 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 4eaeb05

Please sign in to comment.