Class: Workarea::Storefront::CartViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::CartViewModel
- Includes:
- OrderPricing
- Defined in:
- app/view_models/workarea/storefront/cart_view_model.rb
Instance Method Summary collapse
-
#free_gifts ⇒ Array<OrderItemViewModel>
A list of free gift items that are the result of a free item discount.
- #has_shipping_address? ⇒ Boolean (also: #show_shipping_services?, #show_taxes?)
-
#items ⇒ Array<OrderItemViewModel>
Get a list of cart items the user has added to the order for purchasing.
-
#recommendations ⇒ Workarea::Storefront::CartRecommendationsViewModel
Returns recommendations for the cart.
-
#shipping_address ⇒ Object
Shipping.
- #shipping_instructions ⇒ Object
- #shipping_options ⇒ Object
- #shipping_postal_code ⇒ Object
- #shipping_service ⇒ Object
Methods included from OrderPricing
#advance_payment_amount, #order_balance, #store_credit?, #store_credit_amount, #total_adjustments
Instance Method Details
#free_gifts ⇒ Array<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.
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?
44 45 46 |
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 44 def has_shipping_address? shipping.try(:address).present? end |
#items ⇒ Array<OrderItemViewModel>
Get a list of cart items the user has added to the order for purchasing. Includes pricing and display data.
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, .merge(inventory: inventory.for_sku(item.sku)) ) end end |
#recommendations ⇒ Workarea::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_address ⇒ Object
Shipping
40 41 42 |
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 40 def shipping_address shipping.try(:address) end |
#shipping_instructions ⇒ Object
66 67 68 |
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 66 def shipping_instructions shipping.try(:instructions) end |
#shipping_options ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/view_models/workarea/storefront/cart_view_model.rb', line 58 def return [] unless has_shipping_address? @shipping_options ||= Workarea::Checkout::ShippingOptions.new( model, shipping ).available end |
#shipping_postal_code ⇒ Object
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_service ⇒ Object
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 |