Class: LineItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/line_item.rb

Instance Method Summary collapse

Instance Method Details

#adjust_quantityObject



57
58
59
# File 'app/models/line_item.rb', line 57

def adjust_quantity
  self.quantity = 0 if self.quantity.nil? || self.quantity < 0
end

#amountObject Also known as: total



52
53
54
# File 'app/models/line_item.rb', line 52

def amount
  self.price * self.quantity
end

#copy_priceObject



23
24
25
# File 'app/models/line_item.rb', line 23

def copy_price
  self.price = variant.price if variant && self.price.nil?
end

#decrement_quantityObject



48
49
50
# File 'app/models/line_item.rb', line 48

def decrement_quantity
  self.quantity -= 1
end

#increment_quantityObject

def meta_validation_of_quantities

unless quantity && quantity >= 0
  errors.add(:quantity, I18n.t("validation.must_be_non_negative"))
end
# avoid reload of order.inventory_units by using direct lookup
unless !Spree::Config[:track_inventory_levels]                        ||
       Spree::Config[:allow_backorders]                               ||
       order   && InventoryUnit.order_id_equals(order).first.present? ||
       variant && quantity <= variant.on_hand
  errors.add(:quantity, I18n.t("validation.is_too_large") + " (#{self.variant.name})")
end

if shipped_count = order.shipped_units.nil? ? nil : order.shipped_units[variant]
  errors.add(:quantity, I18n.t("validation.cannot_be_less_than_shipped_units") ) if quantity < shipped_count
end

end



44
45
46
# File 'app/models/line_item.rb', line 44

def increment_quantity
  self.quantity += 1
end