diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 66da7a0c68..c76e0d9e45 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -9,7 +9,7 @@ end Spree::Order.class_eval do belongs_to :order_cycle - belongs_to :distributor, :class_name => 'Enterprise' + belongs_to :distributor, class_name: 'Enterprise' belongs_to :cart belongs_to :customer @@ -39,7 +39,6 @@ Spree::Order.class_eval do remove_transition :from => :delivery, :to => :confirm end - # -- Scopes scope :managed_by, lambda { |user| if user.has_spree_role?('admin') @@ -88,7 +87,7 @@ Spree::Order.class_eval do unless self.order_cycle == order_cycle self.order_cycle = order_cycle self.distributor = nil unless order_cycle.nil? || order_cycle.has_distributor?(distributor) - self.empty! + empty! save! end end @@ -99,7 +98,6 @@ Spree::Order.class_eval do current_item.andand.destroy end - # Overridden to support max_quantity def add_variant(variant, quantity = 1, max_quantity = nil, currency = nil) line_items(:reload) @@ -126,7 +124,7 @@ Spree::Order.class_eval do current_item.currency = currency unless currency.nil? current_item.save else - current_item = Spree::LineItem.new(:quantity => quantity, max_quantity: max_quantity) + current_item = Spree::LineItem.new(quantity: quantity, max_quantity: max_quantity) current_item.variant = variant if currency current_item.currency = currency unless currency.nil? @@ -134,10 +132,10 @@ Spree::Order.class_eval do else current_item.price = variant.price end - self.line_items << current_item + line_items << current_item end - self.reload + reload current_item end @@ -220,26 +218,26 @@ Spree::Order.class_eval do # Does this order have shipments that can be shipped? def ready_to_ship? - self.shipments.any?{|s| s.can_ship?} + shipments.any?(&:can_ship?) end # Ship all pending orders def ship - self.shipments.each do |s| + shipments.each do |s| s.ship if s.can_ship? end end def shipping_tax - adjustments(:reload).shipping.sum &:included_tax + adjustments(:reload).shipping.sum(&:included_tax) end def enterprise_fee_tax - adjustments(:reload).enterprise_fee.sum &:included_tax + adjustments(:reload).enterprise_fee.sum(&:included_tax) end def total_tax - (adjustments + price_adjustments).sum &:included_tax + (adjustments + price_adjustments).sum(&:included_tax) end def tax_adjustments @@ -269,12 +267,9 @@ Spree::Order.class_eval do # Overrride of Spree method, that allows us to send separate confirmation emails to user and shop owners # And separately, to skip sending confirmation email completely for user invoice orders def deliver_order_confirmation_email - unless account_invoice? - Delayed::Job.enqueue ConfirmOrderJob.new(id) - end + Delayed::Job.enqueue ConfirmOrderJob.new(id) unless account_invoice? end - private def shipping_address_from_distributor @@ -287,9 +282,9 @@ Spree::Order.class_eval do self.ship_address = distributor.address.clone if bill_address - self.ship_address.firstname = bill_address.firstname - self.ship_address.lastname = bill_address.lastname - self.ship_address.phone = bill_address.phone + ship_address.firstname = bill_address.firstname + ship_address.lastname = bill_address.lastname + ship_address.phone = bill_address.phone end end end @@ -301,11 +296,11 @@ Spree::Order.class_eval do end def product_distribution_for(line_item) - line_item.variant.product.product_distribution_for self.distributor + line_item.variant.product.product_distribution_for distributor end def require_customer? - return true unless new_record? or state == 'cart' + return true unless new_record? || state == 'cart' end def customer_is_valid? diff --git a/app/serializers/api/current_order_serializer.rb b/app/serializers/api/current_order_serializer.rb index 87e0e53bb5..77927614f8 100644 --- a/app/serializers/api/current_order_serializer.rb +++ b/app/serializers/api/current_order_serializer.rb @@ -1,6 +1,6 @@ class Api::CurrentOrderSerializer < ActiveModel::Serializer attributes :id, :item_total, :email, :shipping_method_id, - :display_total, :payment_method_id + :display_total, :payment_method_id has_one :bill_address, serializer: Api::AddressSerializer has_one :ship_address, serializer: Api::AddressSerializer