Class: Workarea::Storefront::OrderItemViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::OrderItemViewModel
- Defined in:
- app/view_models/workarea/storefront/order_item_view_model.rb
Direct Known Subclasses
Instance Method Summary collapse
- #catalog_product ⇒ Object
- #customizations_unit_price ⇒ Object
- #default_category_name ⇒ Object
- #details ⇒ Object
-
#fulfillment_sku ⇒ Object
Fulfillment.
- #has_options? ⇒ Boolean
- #image ⇒ Object
-
#multiple? ⇒ Boolean
Pricing.
- #original_price ⇒ Object
-
#product ⇒ Object
Catalog details.
- #product_name ⇒ Object
- #sku_name ⇒ Object
- #token ⇒ Object
- #total_adjustments ⇒ Object
- #variant ⇒ Object
Instance Method Details
#catalog_product ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 40 def catalog_product @catalog_product ||= if product_attributes.present? Mongoid::Factory.from_db(Catalog::Product, product_attributes) else Catalog::Product.find_by_sku(sku) end end |
#customizations_unit_price ⇒ Object
61 62 63 64 65 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 61 def customizations_unit_price (price_adjustments.detect do |adjustment| adjustment.description =~ /customizations/i end.try(:unit) || 0).to_m end |
#default_category_name ⇒ Object
85 86 87 88 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 85 def default_category_name @default_category_name = Categorization.new(catalog_product).default_model.try(:name) end |
#details ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 17 def details @details ||= begin tmp = variant.details.map do |k, v| [k.to_s.titleize, [v].flatten.join(', ')] end Hash[tmp] end end |
#fulfillment_sku ⇒ Object
Fulfillment
75 76 77 78 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 75 def fulfillment_sku @fulfillment_sku ||= Fulfillment::Sku.find_or_initialize_by(id: model.sku) end |
#has_options? ⇒ Boolean
36 37 38 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 36 def product..length > 1 end |
#image ⇒ Object
13 14 15 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 13 def image product.primary_image end |
#multiple? ⇒ Boolean
Pricing
53 54 55 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 53 def multiple? quantity > 1 end |
#original_price ⇒ Object
57 58 59 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 57 def original_price price_adjustments.first.data['original_price'].to_m end |
#product ⇒ Object
Catalog details
9 10 11 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 9 def product @product ||= ProductViewModel.wrap(catalog_product, sku: sku) end |
#product_name ⇒ Object
28 29 30 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 28 def product_name product.name end |
#sku_name ⇒ Object
32 33 34 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 32 def sku_name variant.name end |
#token ⇒ Object
80 81 82 83 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 80 def token return unless fulfillment_sku.download? @token ||= Fulfillment::Token.for_order_item(model.order.id, model.id) end |
#total_adjustments ⇒ Object
67 68 69 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 67 def total_adjustments @total_adjustments ||= price_adjustments.reduce_by_description('item') end |
#variant ⇒ Object
90 91 92 93 94 |
# File 'app/view_models/workarea/storefront/order_item_view_model.rb', line 90 def variant catalog_product.variants.detect do |variant| variant.sku.downcase == model.sku.downcase end end |