module MongoidCart::ActsAsProduct
Attributes
amount[RW]
unit[RW]
Public Instance Methods
build_sku()
click to toggle source
a method which provides a product sku like PN-aec5d-00002
# File lib/mongoid_cart/acts_as_product.rb, line 61 def build_sku "#{self.product_title.split(' ').map(&:first).map!(&:upcase).join}-#{_id.to_s.split(//).first(5).join}-#{_id.to_s.split(//).last(5).join}" end
carts()
click to toggle source
# File lib/mongoid_cart/acts_as_product.rb, line 25 def carts MongoidCart::Cart.in(id: cart_items.pluck(:cart_id)) end
to_cart_item_params()
click to toggle source
returns Hash with mapped cart_item params
# File lib/mongoid_cart/acts_as_product.rb, line 66 def to_cart_item_params {sku: self.sku, product_title: self.product_title, type: self.type, in_stock: self.in_stock, net_price: self.net_price, units: self.units, unit: self.unit, amount: self.amount }.merge!(Hash["#{self.class.to_s.underscore}_id".to_sym, self.id]) end
type()
click to toggle source
returns class of product as String
# File lib/mongoid_cart/acts_as_product.rb, line 79 def type self.class.to_s end
Private Instance Methods
assign_sku()
click to toggle source
# File lib/mongoid_cart/acts_as_product.rb, line 85 def assign_sku self.sku = build_sku end