Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added delete all variants button #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/admin/variants_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ def regenerate
product.do_create_variants(:recreate)
redirect_to :action => :index, :product_id => params[:product_id]
end

def delete_all
product = Product.find_by_permalink(params[:product_id])
product.variants.delete_all
redirect_to :action => :index, :product_id => params[:product_id]
end

end
2 changes: 1 addition & 1 deletion app/controllers/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def enhanced_option_create_before
end if params[:option_values]

if quantity > 0 && variant
if quantity > variant.on_hand
if Spree::Config[:track_inventory_levels] && quantity > variant.on_hand
flash[:error] = t(:stock_to_small) % [variant.on_hand]
else
@order.add_variant(variant, quantity)
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/variants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
:confirm => t(:regenerate_confirm),
:style => "float: right"
%>
<%= button_link_to t(:delete_all),
{:action => :delete_all, :product_id => params[:product_id]},
:method => :post,
:icon => 'exclamation',
:confirm => t(:delete_confirm),
:style => "float: right"
%>

<%= render :partial => 'admin/shared/product_sub_menu' %>

Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ en:
variant_price: Variant price
regenerate: "regenerate variants"
regenerate_confirm: "This will wipe out all your current variants\nAre you sure?"
delete_all: "Delete All"
delete_confirm: "Are you really sure you want to delete all current variants?"