-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new calculator from line item discounts
Set it as default in CreateItemAdjustment PromotionAction as the previous FlatPercentItemTotal only works for discounts on orders
- Loading branch information
Showing
5 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Spree | ||
class Calculator | ||
class PercentOnLineItem < Calculator | ||
preference :percent, :decimal, default: 0 | ||
|
||
def self.description | ||
Spree.t(:percent_per_item) | ||
end | ||
|
||
def compute(object) | ||
((object.price * object.quantity) * preferred_percent) / 100 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core/spec/models/spree/calculator/percent_on_line_item_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper' | ||
|
||
module Spree | ||
class Calculator | ||
describe PercentOnLineItem do | ||
let(:line_item) { double("LineItem", price: 10, quantity: 10) } | ||
|
||
before { subject.preferred_percent = 15 } | ||
|
||
it "computes based on item price and quantity" do | ||
expect(subject.compute(line_item)).to eq 15 | ||
end | ||
end | ||
end | ||
end |