Class: Workarea::Storefront::CartViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
OrderPricing
Defined in:
app/view_models/workarea/storefront/cart_view_model.rb

Instance Method Summary collapse

Methods included from OrderPricing

#advance_payment_amount, #order_balance, #store_credit?, #store_credit_amount, #total_adjustments

Instance Method Details

#free_giftsArray<OrderItemViewModel>

A list of free gift items that are the result of a free item discount. Includes display data. Pricing data is irrelevant for free items.

Returns:



27
28
29
30
31
32
33
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 27

def free_gifts
  @free_gifts ||= model.items.select(&:free_gift?).select do |item|
    Inventory.any_available?(item.sku)
  end.map do |item|
    OrderItemViewModel.new(item)
  end
end

#has_shipping_address?Boolean Also known as: show_shipping_services?, show_taxes?

Returns:

  • (Boolean)


44
45
46
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 44

def has_shipping_address?
  shipping.try(:address).present?
end

#itemsArray<OrderItemViewModel>

Get a list of cart items the user has added to the order for purchasing. Includes pricing and display data.

Returns:



13
14
15
16
17
18
19
20
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 13

def items
  @items ||= model.items.by_newest.reject(&:free_gift?).map do |item|
    CartItemViewModel.new(
      item,
      options.merge(inventory: inventory.for_sku(item.sku))
    )
  end
end

#recommendationsWorkarea::Storefront::CartRecommendationsViewModel

Returns recommendations for the cart. The view model it returns behave like Enumerable.



75
76
77
78
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 75

def recommendations
  return [] unless model.quantity > 0
  @recommendations ||= CartRecommendationsViewModel.new(model)
end

#shipping_addressObject

Shipping



40
41
42
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 40

def shipping_address
  shipping.try(:address)
end

#shipping_instructionsObject



66
67
68
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 66

def shipping_instructions
  shipping.try(:instructions)
end

#shipping_optionsObject



58
59
60
61
62
63
64
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 58

def shipping_options
  return [] unless has_shipping_address?
  @shipping_options ||= Workarea::Checkout::ShippingOptions.new(
    model,
    shipping
  ).available
end

#shipping_postal_codeObject



50
51
52
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 50

def shipping_postal_code
  shipping.try(:address).try(:postal_code)
end

#shipping_serviceObject



54
55
56
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 54

def shipping_service
  shipping.try(:shipping_service).try(:name)
end