Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
SD-1354 Add pagination to the view of product's variants
Tomek Urban2ba48a4d1ad1
diff --git a/backend/app/controllers/spree/admin/variants_controller.rb b/backend/app/controllers/spree/admin/variants_controller.rbindex 823240f848..f1850c1a1f 100644--- a/backend/app/controllers/spree/admin/variants_controller.rb+++ b/backend/app/controllers/spree/admin/variants_controller.rb@@ -39,15 +39,18 @@ module Spreeenddef collection- @deleted = params.key?(:deleted) && params[:deleted] == 'on' ? 'checked' : ''+ return @collection if @collection.present?- @collection ||=- if @deleted.blank?- super.includes(:default_price, option_values: :option_type)- else- Variant.only_deleted.where(product_id: parent.id)- end- @collection+ params[:q] ||= {}+ @deleted = params.dig(:q, :deleted_at_null) || '0'++ @collection = super+ @collection = @collection.deleted if @deleted == '1'+ # @search needs to be defined as this is passed to search_link+ @search = @collection.ransack(params[:q])+ @collection = @search.result.+ page(params[:page]).+ per(params[:per_page] || Spree::Config[:variants_per_page])endprivatediff --git a/backend/app/views/spree/admin/variants/index.html.erb b/backend/app/views/spree/admin/variants/index.html.erbindex 9a9fff2ff3..f7d1d014ed 100644--- a/backend/app/views/spree/admin/variants/index.html.erb+++ b/backend/app/views/spree/admin/variants/index.html.erb@@ -10,7 +10,7 @@<tr><th colspan="2"><%= Spree.t(:options) %></th><th><%= Spree.t(:price) %></th>- <th><%= Spree.t(:sku) %></th>+ <th><%= sort_link @search, :sku, Spree.t(:sku) %></th><th class="actions"></th></tr></thead>@@ -65,6 +65,7 @@<% content_for :page_actions do %><%= product_preview_link(@product) %><%= button_link_to(Spree.t(:new_variant), spree.new_admin_product_variant_url(@product), { icon: 'add.svg', :'data-update' => 'new_variant', class: 'btn-success', id: 'new_var_link' }) if can? :create, Spree::Variant %>- <%= button_link_to (@deleted.blank? ? Spree.t(:show_deleted) : Spree.t(:show_active)), spree.admin_product_variants_url(@product, deleted: @deleted.blank? ? "on" : "off"), { class: 'btn-outline-secondary', icon: 'filter.svg' } %>+ <%= button_link_to (@deleted == '1' ? Spree.t(:show_active) : Spree.t(:show_deleted)), spree.admin_product_variants_url(@product, { q: { deleted_at_null: @deleted == '1' ? "0" : "1" } }), { class: 'btn-outline-secondary', icon: 'filter.svg' } %><% end %><% end %>+<%= render partial: 'spree/admin/shared/index_table_options', locals: { collection: @collection } %>diff --git a/backend/spec/controllers/spree/admin/variants_controller_spec.rb b/backend/spec/controllers/spree/admin/variants_controller_spec.rbindex 342167a095..c0edb3cf40 100644--- a/backend/spec/controllers/spree/admin/variants_controller_spec.rb+++ b/backend/spec/controllers/spree/admin/variants_controller_spec.rb@@ -22,7 +22,7 @@ module Spreebefore { variant_2.destroy }it 'assigns only deleted variants for a requested product' do- get :index, params: { product_id: product.slug, deleted: 'on' }+ get :index, params: { product_id: product.slug, q: { deleted_at_null: '1' } }expect(assigns(:collection)).not_to include variant_1expect(assigns(:collection)).to include variant_2enddiff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rbindex 7458061611..e4aeb632e9 100644--- a/core/app/models/spree/app_configuration.rb+++ b/core/app/models/spree/app_configuration.rb@@ -63,6 +63,7 @@ module Spreepreference :show_raw_product_description, :boolean, default: falsepreference :tax_using_ship_address, :boolean, default: truepreference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.+ preference :variants_per_page, :integer, default: Kaminari.config.default_per_page# Store credits configurationspreference :non_expiring_credit_types, :array, default: []