mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
add filter parameters to link leading back to bulk import product page and preserve filter parameters when updating product
This commit is contained in:
@@ -31,6 +31,19 @@ module Spree
|
||||
}
|
||||
} }
|
||||
|
||||
respond_override update: { html: {
|
||||
success: lambda {
|
||||
redirect_to edit_admin_product_url(@product, @url_filter)
|
||||
},
|
||||
failure: lambda {
|
||||
redirect_to edit_admin_product_url(@product, @url_filter)
|
||||
}
|
||||
} }
|
||||
|
||||
PRODUCT_FILTER = [
|
||||
'query', 'producerFilter', 'categoryFilter', 'sorting', 'importDateFilter'
|
||||
].freeze
|
||||
|
||||
def new
|
||||
@object.shipping_category = DefaultShippingCategory.find_or_create
|
||||
super
|
||||
@@ -56,9 +69,17 @@ module Spree
|
||||
@show_latest_import = params[:latest_import] || false
|
||||
end
|
||||
|
||||
def update
|
||||
original_supplier_id = @product.supplier_id
|
||||
def edit
|
||||
filters = product_filters(params)
|
||||
@url_filters = filters.empty? ? "" : "?#{filters.to_query}"
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
@url_filter = product_filters(request.query_parameters)
|
||||
|
||||
original_supplier_id = @product.supplier_id
|
||||
delete_stock_params_and_set_after do
|
||||
super
|
||||
if original_supplier_id != @product.supplier_id
|
||||
@@ -258,6 +279,10 @@ module Spree
|
||||
def set_product_master_variant_price_to_zero
|
||||
@product.price = 0 if @product.price.nil?
|
||||
end
|
||||
|
||||
def product_filters(params)
|
||||
params.select { |k, _v| PRODUCT_FILTER.include?(k) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- content_for :page_actions do
|
||||
%li= button_link_to t('admin.products.back_to_products_list'), admin_products_path, :icon => 'icon-arrow-left'
|
||||
%li= button_link_to t('admin.products.back_to_products_list'), "#{admin_products_path}##{@url_filters}", :icon => 'icon-arrow-left'
|
||||
%li#new_product_link
|
||||
= button_link_to t(:new_product), new_object_url, { :icon => 'icon-plus', :id => 'admin_new_product' }
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Product Details' }
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @product }
|
||||
|
||||
= form_for [:admin, @product], :method => :put, :html => { :multipart => true } do |f|
|
||||
= form_for [:admin, @product], :url => "#{admin_product_path(@product)}#{@url_filters}", :method => :put, :html => { :multipart => true } do |f|
|
||||
%fieldset.no-border-top{'ng-app' => 'admin.products'}
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/edit_resource_links'
|
||||
.form-buttons.filter-actions.actions
|
||||
= button t(:update), 'icon-refresh'
|
||||
%span.or= t(:or)
|
||||
= button_link_to t(:cancel), "#{collection_url}##{@url_filters}", icon: 'icon-remove'
|
||||
|
||||
@@ -151,6 +151,24 @@ feature '
|
||||
expect(product.tax_category).to eq(tax_category)
|
||||
end
|
||||
|
||||
scenario "editing a product comming from the bulk product update page with filter" do
|
||||
product = create(:simple_product, name: 'a product', supplier: @supplier2)
|
||||
|
||||
filter_query = "producerFilter=2"
|
||||
visit "#{spree.edit_admin_product_path(product)}?#{filter_query}"
|
||||
|
||||
click_button 'Update'
|
||||
expect(flash_message).to eq('Product "a product" has been successfully updated!')
|
||||
|
||||
# Check the url still includes the filters
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq "#{spree.edit_admin_product_path(product)}?#{filter_query}"
|
||||
|
||||
# Link back to the bulk product update page should include the filters
|
||||
expect(page).to have_link(I18n.t('admin.products.back_to_products_list'), href: %r{admin\/products#\?#{filter_query}})
|
||||
expect(page).to have_link(I18n.t(:cancel), href: %r{admin\/products#\?#{filter_query}})
|
||||
end
|
||||
|
||||
scenario "editing product group buy options" do
|
||||
product = product = create(:simple_product, supplier: @supplier2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user