Skip to content

Commit

Permalink
Fix for r144
Browse files Browse the repository at this point in the history
git-svn-id: http://substruct.googlecode.com/svn/trunk/plugins/substruct@160 6a1f77cc-a145-0410-afd8-bd7963fcc59f
  • Loading branch information
subimage committed Nov 2, 2008
1 parent a913b96 commit 555725b
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 182 deletions.
59 changes: 31 additions & 28 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ def initialize(*args)
before_create :set_order_number
def set_order_number
self.order_number = Order.generate_order_number
return true
end

# Sets product cost based on line items total before a save.
before_save :set_product_cost
def set_product_cost
self.product_cost = self.line_items_total
return true
end

# Modifies the order based on any promotion codes passed in.
Expand Down Expand Up @@ -130,8 +132,28 @@ def set_promo_code
end

self.order_line_items << oli
return true
end


# Adds a new order note from the edit page.
# We display notes as read-only, so we only have to use a text field
# instead of multiple records.
attr_accessor :new_notes
before_save :set_new_notes
def set_new_notes()
unless self.new_notes.blank?
time = Time.now.strftime("%m-%d-%y %I:%M %p")
new_note = "<p>#{self.new_notes}<br/>"
new_note << "<span class=\"info\">"
new_note << "[#{time}]"
new_note << "</span></p>"
write_attribute(:notes, self.notes + self.new_notes)
self.new_notes = nil
end
return true
end

# CLASS METHODS =============================================================

# Searches an order
Expand Down Expand Up @@ -513,25 +535,6 @@ def line_items_total
return total
end

# Adds a new order note from the edit page.
#
# We display notes as read-only, so we only have to use a text field
# instead of multiple records.
def new_notes=(note)
if !note.blank? then
time = Time.now.strftime("%m-%d-%y %I:%M %p")
new_note = "<p>#{note}<br/>"
new_note << "<span class=\"info\">"
new_note << "[#{time}]"
new_note << "</span></p>"
if self.notes.blank? then
self.notes = new_note
else
self.notes << new_note
end
end
end

# Calculates the weight of an order
def weight
weight = 0
Expand Down Expand Up @@ -686,9 +689,7 @@ def run_transaction_paypal_ipn
end

self.save

self.order_status_code.id

end

# Cleans up a successful order
Expand Down Expand Up @@ -796,13 +797,15 @@ def self.matches_ipn(notification, order, details)

if details[:address_street] &&
details[:address_street] != order.shipping_address.address
order.new_notes ="The shipping address supplied by PayPal doesn't match
the shipping address for this order. PayPal
sent the following address:<br/>
#{details[:address_street]}<br/>
#{details[:address_city]}, #{details[:address_state]}<br/>
#{details[:address_zip]}<br/>
<b>Please contact the customer for clarification.<b>"
order.new_notes = %Q\
The shipping address supplied by PayPal doesn't match
the shipping address for this order. PayPal
sent the following address:<br/>
#{details[:address_street]}<br/>
#{details[:address_city]}, #{details[:address_state]}<br/>
#{details[:address_zip]}<br/>
<b>Please contact the customer for clarification.<b>
\
end

passed
Expand Down
3 changes: 1 addition & 2 deletions lib/substruct/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module Substruct
module Version
MAJOR = 1
MINOR = 0
TINY = 'a6'
TINY = 'a7'
STRING = [MAJOR, MINOR, TINY].join('.').freeze
#TITLE = "Noh-Varr".freeze
end
end
44 changes: 1 addition & 43 deletions test/fixtures/orders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,24 @@ santa_next_christmas_order:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes: <%= "<p>Order completed.<br/><span class=\"info\">[#{1.year.ago.strftime("%m-%d-%y %I:%M %p")}]</span></p>" %>
referer:
shipping_cost: 30.0
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 5


an_order_on_cart:
tax: 0.0
product_cost: 700.5
created_on: <%= 1.hour.ago.to_s(:db) %>
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type_id: 1
promotion:
notes:
referer:
shipping_cost: 0
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 1

an_order_to_charge:
Expand All @@ -42,15 +32,10 @@ an_order_to_charge:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes:
referer:
shipping_cost: 30
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 2

an_order_on_hold_payment_failed:
Expand All @@ -60,15 +45,11 @@ an_order_on_hold_payment_failed:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes: <%= "<p>Order failed!<br/>(TESTMODE) The merchant login ID or password is invalid or the account is inactive<br/><span class=\"info\">[#{1.hour.ago.strftime("%m-%d-%y %I:%M %p")}]</span></p>" %>
referer:
shipping_cost: 30
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 3

an_order_on_hold_awaiting_payment:
Expand All @@ -78,15 +59,11 @@ an_order_on_hold_awaiting_payment:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes: <%= "<p>The order was processed at PayPal but not yet confirmed.<br/><span class=\"info\">[05#{1.hour.ago.strftime("%m-%d-%y %I:%M %p")}]</span></p>" %>
referer:
shipping_cost: 30
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 4

an_order_ordered_paid_shipped:
Expand All @@ -96,34 +73,24 @@ an_order_ordered_paid_shipped:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes: <%= "<p>Order completed.<br/><span class=\"info\">[#{1.hour.ago.strftime("%m-%d-%y %I:%M %p")}]</span></p>" %>
referer:
shipping_cost: 0
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 6


an_order_sent_to_fulfillment:
tax: 0.0
product_cost: 89.5
created_on: <%= 1.hour.ago.to_s(:db) %>
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes:
referer:
shipping_cost: 30
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 7

an_order_cancelled:
Expand All @@ -133,15 +100,10 @@ an_order_cancelled:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes:
referer:
shipping_cost: 30
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 8

an_order_returned:
Expand All @@ -151,13 +113,9 @@ an_order_returned:
shipping_address: santa_address
order_user: santa
billing_address: santa_address
shipped_on:
order_shipping_type: ups_xp_critical
promotion:
notes: <%= "<p>Order completed.<br/><span class=\"info\">[#{1.month.ago.strftime("%m-%d-%y %I:%M %p")}]</span></p>" %>
referer:
shipping_cost: 30.0
order_number: <%= Order.generate_order_number %>
order_account: santa_account
auth_transaction_id:
order_status_code_id: 9
order_status_code_id: 9
2 changes: 1 addition & 1 deletion test/fixtures/wishlist_items.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
santa_wishlist_item_1:
item: uranium_portion
order_user: santa

santa_wishlist_item_2:
item: holy_grenade
order_user: santa
3 changes: 1 addition & 2 deletions test/functional/admin/content_nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ def test_should_save_existing_question
} ]

# If saved we should be redirected to list.
assert_response :redirect
assert_redirected_to :action => :list
assert_response :success

# Verify that the change was made.
a_content_node.reload
Expand Down
Loading

0 comments on commit 555725b

Please sign in to comment.