paxxxtothemax / substruct

Automatically exported from code.google.com/p/substruct
0 stars 0 forks source link

unable to add to cart ajax unless you have at least a 1 for the items' quantity #100

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In general, if you uncheck
 Use inventory control?
in preferences
it doesn't work.
At the least, if you have products without quantities, you can't add them 
within add_to_cart_ajax.  I 
hope to eventually get around to patching this and posting the patch.

Original issue reported on code.google.com by rogerpack2005 on 18 Jun 2008 at 5:50

GoogleCodeExporter commented 8 years ago
Not just that, it lets you add more items that the quantity that is available if
inventory control is checked, if you add the maximum quantity available several
times, it does not check what is already in the cart.

At the end it do it right on checkout anyway, and delete those items.

My doubt here is if the add_to_cart_ajax method should really block everything 
that
passes the quantity available if the inventory is checked and dont block 
anything if
unchecked.

Original comment by edmundo...@gmail.com on 18 Jun 2008 at 6:20

GoogleCodeExporter commented 8 years ago
I've switched to the add_to_cart non-ajax method. Let me know if there's a 
better way
to do this.

  def add_to_cart
    @cart = find_cart
    product = Product.find(params[:id])

    if !session[:cart].items.empty?
      for i in session[:cart].items do
        if i.item_id == product.id
          quantity = i.quantity.to_i + params[:quantity].to_i
        else
          quantity = params[:quantity]
          quantity ||= 1
        end
      end
    else
      quantity = params[:quantity]
      quantity ||= 1
    end

    if quantity.to_i > product.quantity.to_i
      flash[:notice] = "Your cart already contains the maximum quantity for this item."
      redirect_to :action => 'show', :id => product.code
    else      
      @cart.add_product(product, quantity.to_i)
      show_cart and return
    end
    rescue
      redirect_to_index("Sorry, you tried to buy a product that we don't carry any
longer.")
  end

Original comment by patrickb...@gmail.com on 13 Aug 2008 at 4:40

GoogleCodeExporter commented 8 years ago

Original comment by subim...@gmail.com on 16 Aug 2008 at 3:43

GoogleCodeExporter commented 8 years ago
looks like a good patch.

Original comment by rogerpack2005 on 8 Oct 2008 at 6:17

GoogleCodeExporter commented 8 years ago
but needs some double checking

Original comment by rogerpack2005 on 21 Feb 2009 at 5:20