spree/spree — Issue #883: cannot access custom attribute on Order
Author: kritik
Created: 2011-12-16 19:37:18+00:00
State: open

I'm using Spree 0.60 I have inserted new attribute to Order model, but I cannot Use it

class AddCouponCodeToOrder < ActiveRecord::Migration
def self.up
add_column :orders, :coupon_code, :string
end

def self.down
remove_column :orders, :coupon_code
end
end

in models/order.rb I added
attr_accessible :line_items, :bill_address_attributes, :ship_address_attributes, :payments_attributes,
:ship_address, :line_items_attributes,
:shipping_method_id, :email, :use_billing, :special_instructions, :coupon_code

But I cannot either read or update coupon_code attribute
ruby-1.9.3-p0 :001 > order=Order.where(:number=>'R671611062').first
=> #, total: #, created_at: "2011-12-16 15:48:04", updated_at: "2011-12-16 19:10:19", state: "delivery", adjustment_total: #, credit_total: #, completed_at: nil, bill_address_id: 1072978483, ship_address_id: 1072978484, payment_total: #, shipping_method_id: 574015648, shipment_state: "pending", payment_state: "balance_due", email: "s6numid@gmail.com", special_instructions: nil, coupon_code: "4444"> # it's here
ruby-1.9.3-p0 :002 > order.coupon_code
=> nil

Trying to change:

ruby-1.9.3-p0 :003 > order.coupon_code="gggg"
=> "gggg"
ruby-1.9.3-p0 :004 > order.save!
=> true
ruby-1.9.3-p0 :005 > order.changed
=> []
ruby-1.9.3-p0 :006 > order.changed?
=> false
ruby-1.9.3-p0 :007 > order=Order.where(:number=>'R671611062').first
=> #, total: #, created_at: "2011-12-16 15:48:04", updated_at: "2011-12-16 19:10:19", state: "delivery", adjustment_total: #, credit_total: #, completed_at: nil, bill_address_id: 1072978483, ship_address_id: 1072978484, payment_total: #, shipping_method_id: 574015648, shipment_state: "pending", payment_state: "balance_due", email: "s6numid@gmail.com", special_instructions: nil, coupon_code: "4444"> # the old one

I'm using also spree_simple_product_translation. Can it be an issue?