From f7ade48e8655c282d765f06ed47dc865b142bbe0 Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Sat, 4 Apr 2015 17:06:26 +0100 Subject: [PATCH] Update DB schema to store updatable weight on items sold --- .../api/line_items_controller_decorator.rb | 17 +++++++++++++++++ .../20150305004846_add_weight_to_line_items.rb | 5 +++++ db/schema.rb | 1 + 3 files changed, 23 insertions(+) create mode 100644 app/controllers/spree/api/line_items_controller_decorator.rb create mode 100644 db/migrate/20150305004846_add_weight_to_line_items.rb diff --git a/app/controllers/spree/api/line_items_controller_decorator.rb b/app/controllers/spree/api/line_items_controller_decorator.rb new file mode 100644 index 0000000000..f9a025873d --- /dev/null +++ b/app/controllers/spree/api/line_items_controller_decorator.rb @@ -0,0 +1,17 @@ +Spree::Api::LineItemsController.class_eval do + after_filter :apply_enterprise_fees, :only => :update + + def apply_enterprise_fees + authorize! :read, order + order.update_distribution_charge! + end +end + + +#when we update a line item the .update_distribution_charge! is called +# order.should_receive .update_distribution_charge! +# check fails when absent + +# in order model check that .update_distribution_charge! is properly tested. +# think through use cases - existing completed order +# currently likely just used to complete orders so add test case that works on a completed order diff --git a/db/migrate/20150305004846_add_weight_to_line_items.rb b/db/migrate/20150305004846_add_weight_to_line_items.rb new file mode 100644 index 0000000000..a4df1a12f0 --- /dev/null +++ b/db/migrate/20150305004846_add_weight_to_line_items.rb @@ -0,0 +1,5 @@ +class AddWeightToLineItems < ActiveRecord::Migration + def change + add_column :spree_line_items, :unit_value, :decimal, :precision => 8, :scale => 2 + end +end diff --git a/db/schema.rb b/db/schema.rb index cb8b503583..96f5896c79 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -549,6 +549,7 @@ ActiveRecord::Schema.define(:version => 20150424025907) do t.string "currency" t.decimal "distribution_fee", :precision => 10, :scale => 2 t.string "shipping_method_name" + t.decimal "unit_value", :precision => 8, :scale => 2 end add_index "spree_line_items", ["order_id"], :name => "index_line_items_on_order_id"