Class: Spree::Tax::ItemAdjuster
- Inherits:
-
Object
- Object
- Spree::Tax::ItemAdjuster
- Includes:
- TaxHelpers
- Defined in:
- app/models/spree/tax/item_adjuster.rb
Overview
Adjust a single taxable item (line item or shipment)
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#adjust! ⇒ Array<Spree::Adjustment>
Deletes all existing tax adjustments and creates new adjustments for all (geographically and category-wise) applicable tax rates.
-
#initialize(item, options = {}) ⇒ ItemAdjuster
constructor
A new instance of ItemAdjuster.
Constructor Details
#initialize(item, options = {}) ⇒ ItemAdjuster
Returns a new instance of ItemAdjuster.
11 12 13 14 15 16 17 18 |
# File 'app/models/spree/tax/item_adjuster.rb', line 11 def initialize(item, = {}) @item = item @order = @item.order # set instance variable so `TaxRate.match` is only called when necessary @rates_for_order_zone = [:rates_for_order_zone] @rates_for_default_zone = [:rates_for_default_zone] @order_tax_zone = [:order_tax_zone] end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
5 6 7 |
# File 'app/models/spree/tax/item_adjuster.rb', line 5 def item @item end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'app/models/spree/tax/item_adjuster.rb', line 5 def order @order end |
Instance Method Details
#adjust! ⇒ Array<Spree::Adjustment>
Deletes all existing tax adjustments and creates new adjustments for all (geographically and category-wise) applicable tax rates.
Creating the adjustments will also run the ItemAdjustments class and persist all taxation and promotion totals on the item.
27 28 29 30 31 32 33 |
# File 'app/models/spree/tax/item_adjuster.rb', line 27 def adjust! return unless order_tax_zone(order) item.adjustments.destroy(item.adjustments.select(&:tax?)) rates_for_item(item).map { |rate| rate.adjust(order_tax_zone(order), item) } end |