Class: Workarea::CartCleaner
- Inherits:
-
Object
- Object
- Workarea::CartCleaner
- Defined in:
- app/services/workarea/cart_cleaner.rb
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize(cart) ⇒ CartCleaner
constructor
A new instance of CartCleaner.
- #message? ⇒ Boolean
- #messages ⇒ Object
Constructor Details
#initialize(cart) ⇒ CartCleaner
Returns a new instance of CartCleaner.
5 6 7 |
# File 'app/services/workarea/cart_cleaner.rb', line 5 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
3 4 5 |
# File 'app/services/workarea/cart_cleaner.rb', line 3 def cart @cart end |
Instance Method Details
#clean ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/workarea/cart_cleaner.rb', line 17 def clean items_to_remove = [] cart.items.each do |item| product = products.detect { |p| p.id == item.product_id } variant = product && product.variants.detect { |v| v.sku == item.sku } price = pricing.for_sku(item.sku, quantity: item.quantity) if product.blank? items_to_remove << item.id self. << I18n.t('workarea.carts.product_unavailable', product_id: item.product_id) next end unless product.purchasable? && variant.try(:active?) items_to_remove << item.id self. << I18n.t('workarea.carts.product_unavailable', product_id: item.product_id) next end unless price.persisted? items_to_remove << item.id self. << I18n.t('workarea.carts.product_unavailable', product_id: item.product_id) next end end items_to_remove.each do |item_id| cart.remove_item(item_id) end end |
#message? ⇒ Boolean
13 14 15 |
# File 'app/services/workarea/cart_cleaner.rb', line 13 def .present? end |
#messages ⇒ Object
9 10 11 |
# File 'app/services/workarea/cart_cleaner.rb', line 9 def @messages ||= [] end |