Class: Gemgento::LineItem

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

Overview

Author:

  • Gemgento LLC

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#asyncObject

Returns the value of attribute async.



9
10
11
# File 'app/models/gemgento/line_item.rb', line 9

def async
  @async
end

#destroy_quote_after_rollbackObject

Returns the value of attribute destroy_quote_after_rollback.



9
10
11
# File 'app/models/gemgento/line_item.rb', line 9

def destroy_quote_after_rollback
  @destroy_quote_after_rollback
end

Instance Method Details

#as_json(options = nil) ⇒ Void

JSON representation of the LineItem.

Parameters:

  • options (Hash) (defaults to: nil)

Returns:

  • (Void)


34
35
36
37
38
# File 'app/models/gemgento/line_item.rb', line 34

def as_json(options = nil)
  result = super
  result['product'] = self.product.as_json({ store: Store.find(self.itemizable.store.id) })
  return result
end

#priceBigDecimal

Get the associated Product price.

Returns:

  • (BigDecimal)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/gemgento/line_item.rb', line 43

def price
  return super.to_d unless super.nil?

  if product.magento_type == 'giftvoucher'
    self.options[:amount].to_d
  elsif self.options[:custom_price]
    self.options[:custom_price].to_d
  else
    user_group = itemizable.user ? itemizable.user.user_group : nil
    product.price(user_group, itemizable.store, self.qty_ordered).to_d
  end

end