app/models/exchange.rb in artfully_ose-1.2.0.beta.1 vs app/models/exchange.rb in artfully_ose-1.2.0.pre
- old
+ new
@@ -1,9 +1,9 @@
class Exchange
include ActiveModel::Validations
- attr_accessor :order, :items, :tickets, :ticket_type, :send_email_confirmation
+ attr_accessor :order, :items, :tickets, :ticket_type
attr_reader :exchange_order
validates_presence_of :order
validates_presence_of :ticket_type
validates_length_of :items, :minimum => 1
@@ -15,16 +15,15 @@
validate :tickets_belong_to_organization
#The original order
#The items to exchange
#The tickets that they are being exchanged for
- def initialize(order, items, tickets, ticket_type, send_email_confirmation = false)
+ def initialize(order, items, tickets = [], ticket_type)
self.order = order
self.items = items
- self.tickets = tickets || []
- self.ticket_type = ticket_type
- self.send_email_confirmation = send_email_confirmation
+ self.tickets = tickets
+ self.ticket_type = ticket_type
end
def items_are_exchangeable
errors.add(:items, "are not available to exchange") unless items.all?(&:exchangeable?)
end
@@ -41,11 +40,11 @@
errors.add(:tickets, "do not belong to this organization") unless tickets.all? { |ticket| order.organization.can? :manage, ticket }
end
def submit
ActiveRecord::Base.transaction do
- self.tickets = Ticket.lock(self.tickets, self.ticket_type, Cart.create)
+ self.tickets = Ticket.lock(tickets, ticket_type, Cart.create)
sell_new_items
return_old_items
end
end
@@ -74,10 +73,9 @@
exchange_order.parent = order
exchange_order.payment_method = order.payment_method
exchange_order.created_at = time
exchange_order.for_organization order.organization
exchange_order.details = "Order is the result of an exchange on #{I18n.l time, :format => :slashed_date}"
- exchange_order.skip_email = !send_email_confirmation
exchange_order << tickets
end
exchange_order.record_exchange! items
exchange_order.save!
@exchange_order = exchange_order