Module: Spree::CartHelper

Defined in:
app/helpers/spree/cart_helper.rb

Instance Method Summary collapse

Instance Method Details

#cart_id(order) ⇒ Object



48
49
50
51
52
# File 'app/helpers/spree/cart_helper.rb', line 48

def cart_id(order)
  return 'cart_contents' if order.blank? || order.id.blank? || order.updated_at.blank?

  "cart_contents_#{order.id}_#{order.updated_at.to_i}"
end

#color_options_style_for_line_items(line_items) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/spree/cart_helper.rb', line 30

def color_options_style_for_line_items(line_items)
  @color_options_style_for_line_items = begin
    colors = line_items.map(&:variant).map do |v|
      color_option_values = v.option_values.find_all do |ov|
        ov.option_type.color?
      end

      color_option_values.map do |ov|
        { name: ov.name, filter_name: ov.name }
      end
    end

    colors = colors.flatten.uniq { |color| [color[:name], color[:filter_name]] }

    Spree::ColorsPreviewStylesPresenter.new(colors).to_s
  end
end

#quantity_field_options(opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/spree/cart_helper.rb', line 3

def quantity_field_options(opts = {})
  opts[:min]   ||= 1
  opts[:max]   ||= maximum_quantity

  {
    min: opts[:min], max: opts[:max],
    class: opts[:class],
    data: { 'quantity-picker-target': 'quantity' },
    aria: { label: Spree.t(:quantity) }
  }
end

#quantity_modifier_button_tag(text = '+', opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/spree/cart_helper.rb', line 15

def quantity_modifier_button_tag(text = '+', opts = {})
  opts[:action] ||= 'increase'
  opts[:type]   ||= 'button'

  button_tag(
    text,
    type: opts[:type],
    class: opts[:class],
    data: {
      'quantity-picker-target': opts[:action],
      action: "click->quantity-picker##{opts[:action]} click->cart#disableCart turbo-stream-form:submit-end->cart#enableCart"
    }
  )
end