Sha256: a1920824d3450a5d81aca4fee6f6f3164d46d0f9ebf74c3758d0abfaacc763e4
Contents?: true
Size: 1.72 KB
Versions: 10
Compression:
Stored size: 1.72 KB
Contents
class OrdersController < Spree::BaseController helper :products def show @order = Order.find_by_number(params[:id]) end def update @order = current_order if @order.update_attributes(params[:order]) @order.line_items = @order.line_items.select {|li| li.quantity > 0 } redirect_to cart_path else render :edit end end # Shows the current incomplete order from the session def edit @order = current_order(true) end # Adds a new item to the order (creating a new order if none already exists) # # Parameters can be passed using the following possible parameter configurations: # # * Single variant/quantity pairing # +:variants => {variant_id => quantity}+ # # * Multiple products at once # +:products => {product_id => variant_id, product_id => variant_id}, :quantity => quantity + # +:products => {product_id => variant_id, product_id => variant_id}}, :quantity => {variant_id => quantity, variant_id => quantity}+ def populate @order = current_order(true) params[:products].each do |product_id,variant_id| quantity = params[:quantity].to_i if !params[:quantity].is_a?(Hash) quantity = params[:quantity][variant_id].to_i if params[:quantity].is_a?(Hash) @order.add_variant(Variant.find(variant_id), quantity) if quantity > 0 end if params[:products] params[:variants].each do |variant_id, quantity| quantity = quantity.to_i @order.add_variant(Variant.find(variant_id), quantity) if quantity > 0 end if params[:variants] redirect_to cart_path end def empty if @order = current_order @order.line_items.destroy_all end redirect_to cart_path end def accurate_title I18n.t(:shopping_cart) end end
Version data entries
10 entries across 10 versions & 1 rubygems