Class: Plugins::Ecommerce::ProductItemDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/plugins/ecommerce/product_item_decorator.rb

Instance Method Summary collapse

Instance Method Details

#decrement_qty!Object

update quantity of product or product variation used in current cart item



33
34
35
36
37
38
39
40
41
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 33

def decrement_qty!
  val = get_product.the_qty(object.variation_id) - object.qty
  if object.variation_id.present?
    product_variation.update_column(:qty, val)
  else
    product.update_field_value('ecommerce_qty', val)
  end
  val
end

#get_productObject



23
24
25
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 23

def get_product
  @_get_product ||= object.product.decorate
end

#get_variationObject

return a product variation by id



28
29
30
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 28

def get_variation
  @_get_variation ||= self.product_variation.decorate
end

#is_valid_qty?Boolean

verify if the quantity of the cart item is avilable return true if quantity is available

Returns:

  • (Boolean)


45
46
47
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 45

def is_valid_qty?
  (get_product.the_qty_real(object.variation_id) - object.qty).to_i >= 0
end

#priceObject



19
20
21
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 19

def price
  get_product.price(object.variation_id)
end

#the_priceObject



11
12
13
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 11

def the_price
  get_product.the_price(object.variation_id)
end

#the_sub_totalObject



7
8
9
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 7

def the_sub_total
  h.e_parse_price(object.sub_total)
end

#the_taxObject



15
16
17
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 15

def the_tax
  get_product.the_tax(object.variation_id)
end

#the_titleObject



3
4
5
# File 'app/decorators/plugins/ecommerce/product_item_decorator.rb', line 3

def the_title
  get_product.the_variation_title(object.variation_id)
end