mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge branch 'product-quantity-fix'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
Spree::OrdersController.class_eval do
|
||||
before_filter :populate_order_distributor, :only => :populate
|
||||
before_filter :populate_order_count_on_hand, :only => :populate
|
||||
after_filter :populate_variant_attributes, :only => :populate
|
||||
|
||||
def populate_order_distributor
|
||||
@@ -15,6 +16,24 @@ Spree::OrdersController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def populate_order_count_on_hand
|
||||
params[:products].each do |product_id, variant_id|
|
||||
product = Spree::Product.find product_id
|
||||
if product.count_on_hand < params[:quantity].to_i
|
||||
flash[:error] = "Unfortunately " + (product.count_on_hand == 0 ? "no" : "only" + product.count_on_hand.to_s ) + " units of the selected item remain."
|
||||
redirect_populate_to_first_product
|
||||
end
|
||||
end if params[:products]
|
||||
|
||||
params[:variants].each do |variant_id, quantity|
|
||||
variant = Spree::Variant.find variant_id
|
||||
if variant.count_on_hand < params[:quantity].to_i
|
||||
flash[:error] = "Unfortunately " + (variant.count_on_hand == 0 ? "no" : "only" + variant.count_on_hand.to_s ) + " units of the selected item remain."
|
||||
redirect_populate_to_first_product
|
||||
end
|
||||
end if params[:variants]
|
||||
end
|
||||
|
||||
def populate_variant_attributes
|
||||
if params.key? :variant_attributes
|
||||
params[:variant_attributes].each do |variant_id, attributes|
|
||||
|
||||
Reference in New Issue
Block a user