Sha256: 84d6b0f84507889e0e2d7b1f042a44cbbe2f77e9a59fe81c9028fcf2ade2bbde

Contents?: true

Size: 848 Bytes

Versions: 7

Compression:

Stored size: 848 Bytes

Contents

module Bodega
  module CartHelper
    def button_to_cart(product, label = 'Add to Cart', options = {}, &block)
      unless options.key? :disabled
        options[:disabled] = !product.in_stock?
      end
      form_contents = hidden_field_tag('order_product[product_type]', product.class)
      form_contents << hidden_field_tag('order_product[product_id]', product.id) +
      if block_given?
        form_contents << capture(&block)
      end
      form_contents << button_tag(label, options)
      form_tag(bodega.add_to_order_path) { form_contents }
    end

    protected
    def current_order
      @current_order ||= Bodega::Order.where(identifier: session[:bodega_order_id]).first || Bodega::Order.new.tap do |order|
        order.customer = send(Bodega.config.customer_method) if Bodega.config.customer_method
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bodega-0.4.12 app/helpers/bodega/cart_helper.rb
bodega-0.4.9 app/helpers/bodega/cart_helper.rb
bodega-0.4.4 app/helpers/bodega/cart_helper.rb
bodega-0.4.3 app/helpers/bodega/cart_helper.rb
bodega-0.4.2 app/helpers/bodega/cart_helper.rb
bodega-0.4.1 app/helpers/bodega/cart_helper.rb
bodega-0.4.0 app/helpers/bodega/cart_helper.rb