Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating code for 0.7.0 spree

  • Loading branch information...
commit 955c53bf56571a0cfb7c00ffe63de9cb6bcfc08d 1 parent a2e0a13
@AlanMcCann authored
Showing with 29 additions and 21 deletions.
  1. +10 −8 app/models/order_decorator.rb
  2. +19 −13 app/models/variant_decorator.rb
View
18 app/models/order_decorator.rb
@@ -1,23 +1,23 @@
Order.class_eval do
# override the add_variant functionality so that we can adjust the price based on possible volume adjustment
- def add_variant(variant, quantity=1)
+
+ def add_variant(variant, quantity = 1)
current_item = contains?(variant)
price = variant.volume_price(quantity) # Added
if current_item
- current_item.increment_quantity unless quantity > 1
- current_item.quantity = (current_item.quantity + quantity) if quantity > 1
+ current_item.quantity += quantity
current_item.price = price # Added
current_item.save
else
- current_item = line_items.create(:quantity => quantity)
+ current_item = LineItem.new(:quantity => quantity)
current_item.variant = variant
- current_item.price = price
- current_item.save
+ current_item.price = variant.price
+ self.line_items << current_item
end
# populate line_items attributes for additional_fields entries
# that have populate => [:line_item]
- Variant.additional_fields.select{|f| !f[:populate].nil? && f[:populate].include?(:line_item) }.each do |field|
+ Variant.additional_fields.select{|f| !f[:populate].nil? && f[:populate].include?(:line_item) }.each do |field|
value = ""
if field[:only].nil? || field[:only].include?(:variant)
@@ -27,5 +27,7 @@ def add_variant(variant, quantity=1)
end
current_item.update_attribute(field[:name].gsub(" ", "_").downcase, value)
end
+
+ current_item
end
-end
+end
View
32 app/models/variant_decorator.rb
@@ -4,23 +4,29 @@
# calculates the price based on quantity
def volume_price(quantity)
- volume_prices.each do |price|
- if price.include?(quantity)
- case price.discount_type
- when 'price'
- return price.amount
- when 'dollar'
- return self.price - price.amount
- when 'percent'
- return self.price * (1 - price.amount)
+ puts "volume price"
+ if self.volume_prices.count == 0
+ return self.price
+ puts "no volume prices - return #{self.price}"
+ else
+ puts "foun volume prices"
+ self.volume_prices.each do |price|
+ if price.include?(quantity)
+ case price.discount_type
+ when 'price'
+ return price.amount
+ when 'dollar'
+ return self.price - price.amount
+ when 'percent'
+ return self.price * (1 - price.amount)
+ else
+ return self.price
+ end
else
- return self.price
+ self.price
end
- else
- self.price
end
end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.