frontend/app/controllers/spree/orders_controller.rb
# Adds a new item to the order (creating a new order if none already exists)
Adds a new item to the order (creating a new order if none already exists)
Adds a new item to the order ( creating a new order if none already exists )
def populate
      order    = current_order(create_order_if_necessary: true)
      variant  = Spree::Variant.find(params[:variant_id])
      quantity = params[:quantity].to_i
      options  = params[:options] || {}
      if quantity.between?(1, 2_147_483_647)
        begin
          Spree::Cart::AddItem.call(order: order, variant: variant, quantity: quantity, options: options).value
          order.update_line_item_prices!
          order.create_tax_charge!
          order.update_with_updater!
        rescue ActiveRecord::RecordInvalid => e
          error = e.record.errors.full_messages.join(', ')
        end
      else
        error = Spree.t(:please_enter_reasonable_quantity)
      end
      if error
        flash[:error] = error
        redirect_back_or_default(spree.root_path)
      else
        respond_with(order) do |format|
          format.html { redirect_to(cart_path(variant_id: variant.id)) }
        end
      end
    end
def populate order = current_order ( create_order_if_necessary : true ) variant = Spree :: Variant . find ( params [ :variant_id ] ) quantity = params [ :quantity ] . to_i options = params [ :options ] || { } if quantity . between? ( 1 , 2_147_483_647 ) begin Spree :: Cart :: AddItem . call ( order : order , variant : variant , quantity : quantity , options : options ) . value order . update_line_item_prices! order . create_tax_charge! order . update_with_updater! rescue ActiveRecord :: RecordInvalid => e error = e . record . errors . full_messages . join ( ', ' ) end else error = Spree . t ( :please_enter_reasonable_quantity ) end if error flash [ :error ] = error redirect_back_or_default ( spree . root_path ) else respond_with ( order ) do | format | format . html { redirect_to ( cart_path ( variant_id : variant . id ) ) } end end end
Adds a new item to the order (creating a new order if none already exists)
Adds a new item to the order ( creating a new order if none already exists )
# 2,147,483,647 is crazy. See issue #2695.