Skip to content

Instantly share code, notes, and snippets.

@rthbound
Created January 7, 2012 22:15
Show Gist options
  • Select an option

  • Save rthbound/1576241 to your computer and use it in GitHub Desktop.

Select an option

Save rthbound/1576241 to your computer and use it in GitHub Desktop.
# If the cart already has this product in it,
if existing_cart_product = cart.cart_products.find_by_part_number_id(@cart_product.part_number_id)
# And if the current quantity in cart exceeds or equals the available quantity
if existing_cart_product.quantity >= available_quantity
# Set the quantity in cart to the available quantity, and add 0 of the requested quantity to the cart.
existing_cart_product.update_attributes(:quantity => available_quantity)
@addl_msg << "Quantity has been depleted for this item. There are #{existing_cart_product.quantity} units in your cart. "
@cart_product.quantity = 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment