Sha256: 22315c6d9b79322ce059d6683438e727bf11782749845e32771e8f929bacc767
Contents?: true
Size: 1.77 KB
Versions: 4
Compression:
Stored size: 1.77 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.promotion_credits.destroy_all @order.line_items.destroy_all end redirect_to cart_path end def accurate_title I18n.t(:shopping_cart) end end
Version data entries
4 entries across 4 versions & 1 rubygems