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
Move Price List Products to the new table component
Damian Legawiec64a546f93176
diff --git a/admin/app/controllers/spree/admin/price_list_products_controller.rb b/admin/app/controllers/spree/admin/price_list_products_controller.rbindex 742d19ff83..2daf4c537a 100644--- a/admin/app/controllers/spree/admin/price_list_products_controller.rb+++ b/admin/app/controllers/spree/admin/price_list_products_controller.rb@@ -33,6 +33,10 @@ module Spreedef scopeparent.products.distinctend++ def edit_object_url(object, options = {})+ spree.edit_admin_product_path(object, options)+ endendendenddiff --git a/admin/app/views/spree/admin/price_list_products/_table_row.html.erb b/admin/app/views/spree/admin/price_list_products/_table_row.html.erbdeleted file mode 100644index bc482c59e7..0000000000--- a/admin/app/views/spree/admin/price_list_products/_table_row.html.erb+++ /dev/null@@ -1,28 +0,0 @@-<tr id="<%= dom_id product %>" data-controller="row-link">- <td class="pr-0 w-5">- <div class="custom-control form-checkbox ml-1">- <%= check_box_tag "ids[]", product.id, false,- class: "custom-control-input",- id: "ids_#{product.id}",- data: { media_form_target: "checkbox", action: "change->media-form#showDeleteButton" } %>- <label class="custom-control-label" for="ids_<%= product.id %>"><span></span></label>- </div>- </td>- <td scope="row" class="w-40 py-0 whitespace-normal" data-action="click->row-link#openLink">- <%= link_to spree.edit_admin_product_path(product), class: 'flex items-center w-full no-underline h-full py-2', data: { row_link_target: :link, 'turbo-frame': '_top' } do %>- <div class="mr-6">- <%= render 'spree/admin/shared/product_image', object: product %>- </div>- <span class="text-gray-900 font-medium">- <%= product.name %>- </span>- <% end %>- </td>- <%= render 'spree/admin/products/product_status', product: product %>- <td class="w-20 cursor-pointer whitespace-normal" data-action="click->row-link#openLink">- <%= display_inventory(product) %>- </td>- <td class="w-10 cursor-pointer" data-action="click->row-link#openLink">- <%= display_admin_price(product) %>- </td>-</tr>diff --git a/admin/app/views/spree/admin/price_list_products/index.html.erb b/admin/app/views/spree/admin/price_list_products/index.html.erbindex 5738713c6a..e31a708eb6 100644--- a/admin/app/views/spree/admin/price_list_products/index.html.erb+++ b/admin/app/views/spree/admin/price_list_products/index.html.erb@@ -1,56 +1 @@-<%= turbo_frame_tag :price_list_products do %>- <div class="card mb-6" data-controller="media-form" data-media-form-delete-url-value="<%= spree.bulk_destroy_admin_price_list_products_path(@parent) %>">- <div class="card-header flex justify-between items-center border-gray-200 pr-3">- <h5 class="card-title flex items-center gap-2">- <%= Spree.t(:products) %>- <span class="badge badge-info" id="products_count"><%= @price_list.products.distinct.count %></span>- </h5>- <div class="flex gap-2">- <button type="button"- data-media-form-target="deleteButton"- data-action="media-form#deleteSelected"- class="btn btn-sm btn-danger btn-outline hidden">- <%= icon('trash') %>- <%= Spree.t(:delete_selected) %>- </button>- <%= link_to Spree.t(:add_products),- spree.bulk_new_admin_price_list_products_path(@price_list),- class: 'btn btn-sm btn-light',- data: { action: 'drawer#open', turbo_frame: :drawer } %>- <% if @price_list.prices.any? %>- <%= link_to Spree.t(:edit_prices),- spree.edit_prices_admin_price_list_path(@price_list),- class: 'btn btn-sm btn-primary',- data: { turbo_frame: '_top' } %>- <% end %>- </div>- </div>-- <% if @collection.any? %>- <div class="table-responsive">- <table class="table" id="listing_price_list_products">- <thead>- <tr>- <th scope="col" class="pr-0 w-5 rounded-none"></th>- <th scope="col"><%= Spree.t(:name) %></th>- <th scope="col" class="text-center"><%= Spree.t(:status) %></th>- <th scope="col"><%= Spree.t(:inventory) %></th>- <th scope="col" class="rounded-none"><%= Spree.t(:price) %></th>- </tr>- </thead>- <tbody>- <%= render partial: 'table_row', collection: @collection, as: :product %>- </tbody>- </table>- </div>-- <%= render partial: 'spree/admin/shared/index_table_options', locals: { collection: @collection } %>- <% else %>- <div class="card-body">- <p class="text-gray-500 text-center py-8">- <%= Spree.t(:no_products_in_price_list) %>- </p>- </div>- <% end %>- </div>-<% end %>+<%= render_table @price_list.products, :price_list_products, container_class: 'card-body p-0' %>diff --git a/admin/app/views/spree/admin/price_lists/show.html.erb b/admin/app/views/spree/admin/price_lists/show.html.erbindex c5a19bf9c2..e0695245d4 100644--- a/admin/app/views/spree/admin/price_lists/show.html.erb+++ b/admin/app/views/spree/admin/price_lists/show.html.erb@@ -6,7 +6,29 @@<div class="grid grid-cols-12 gap-6"><div class="col-span-12 lg:col-span-8"><%= render 'rules' %>- <%= turbo_frame_tag :price_list_products, src: spree.admin_price_list_products_path(@price_list) %>+ <div class="card mb-6">+ <div class="card-header flex justify-between items-center border-gray-200 pr-3">+ <h5 class="card-title flex items-center gap-2">+ <%= Spree.t(:products) %>+ <span class="badge badge-info" id="products_count"><%= @price_list.products.distinct.count %></span>+ </h5>+ <div class="flex gap-2">+ <%= link_to Spree.t(:add_products),+ spree.bulk_new_admin_price_list_products_path(@price_list),+ class: 'btn btn-sm btn-light',+ data: { action: 'drawer#open', turbo_frame: :drawer } %>+ <% if @price_list.prices.any? %>+ <%= link_to Spree.t(:edit_prices),+ spree.edit_prices_admin_price_list_path(@price_list),+ class: 'btn btn-sm btn-primary',+ data: { turbo_frame: '_top' } %>+ <% end %>+ </div>+ </div>+ <%= turbo_frame_tag :price_list_products, src: spree.admin_price_list_products_path(@price_list) do %>+ <%= render 'spree/admin/shared/spinner' %>+ <% end %>+ </div></div><div class="col-span-12 lg:col-span-4">diff --git a/admin/app/views/spree/admin/tables/_table.html.erb b/admin/app/views/spree/admin/tables/_table.html.erbindex fb98579a46..0cac97d7b7 100644--- a/admin/app/views/spree/admin/tables/_table.html.erb+++ b/admin/app/views/spree/admin/tables/_table.html.erb@@ -1,4 +1,4 @@-<%# locals: (collection:, table:, table_key:, selected_columns: nil, frame_name: nil, bulk_operations: false, sortable: false, export_type: nil, edit_object_url: :default) %>+<%# locals: (collection:, table:, container_class: 'card-lg', table_key:, selected_columns: nil, frame_name: nil, bulk_operations: false, sortable: false, export_type: nil, edit_object_url: :default) %><% frame_name ||= controller_name %><% columns = table.visible_columns(selected_columns, self) %><% current_sort = params.dig(:q, :s) %>@@ -11,7 +11,7 @@<% end %><%= turbo_frame_tag frame_name, autoscroll: true, data: { autoscroll_block: :start, turbo_action: 'advance' } do %>- <div class="card-lg" data-controller="table" data-table-url-value="<%= request.path %>">+ <div class="<%= local_assigns[:container_class] || 'card-lg' %>" data-controller="table" data-table-url-value="<%= request.path %>"><div class="p-2 border-b border-gray-200"><div class="flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between"><div class="flex gap-2 items-center flex-wrap">diff --git a/admin/config/initializers/spree_admin_tables.rb b/admin/config/initializers/spree_admin_tables.rbindex 044153826d..b88b444478 100644--- a/admin/config/initializers/spree_admin_tables.rb+++ b/admin/config/initializers/spree_admin_tables.rb@@ -1400,4 +1400,55 @@ Rails.application.config.after_initialize dofilterable: true,default: false,position: 80++ # ==========================================+ # Price List Products Table+ # ==========================================+ Spree.admin.tables.register(:price_list_products, model_class: Spree::Product, search_param: :multi_search, row_actions: false, new_resource: false)++ Spree.admin.tables.price_list_products.add :name,+ label: :name,+ type: :custom,+ sortable: true,+ filterable: true,+ default: true,+ position: 10,+ partial: 'spree/admin/tables/columns/product_name'++ Spree.admin.tables.price_list_products.add :status,+ label: :status,+ type: :custom,+ filter_type: :status,+ sortable: true,+ filterable: true,+ default: true,+ position: 20,+ partial: 'spree/admin/tables/columns/product_status',+ ransack_attribute: 'status',+ value_options: -> { Spree::Product::STATUSES.map { |s| { value: s, label: s.humanize } } }++ Spree.admin.tables.price_list_products.add :inventory,+ label: :inventory,+ type: :custom,+ sortable: false,+ filterable: false,+ default: true,+ position: 30,+ partial: 'spree/admin/tables/columns/product_inventory'++ Spree.admin.tables.price_list_products.add :created_at,+ label: :created_at,+ type: :datetime,+ sortable: true,+ filterable: true,+ default: false,+ position: 50++ Spree.admin.tables.price_list_products.add :updated_at,+ label: :updated_at,+ type: :datetime,+ sortable: true,+ filterable: true,+ default: false,+ position: 60enddiff --git a/core/app/models/spree/price_list.rb b/core/app/models/spree/price_list.rbindex 4d0d0d398e..9994d5beb4 100644--- a/core/app/models/spree/price_list.rb+++ b/core/app/models/spree/price_list.rb@@ -11,8 +11,8 @@ module Spreehas_many :price_rules, class_name: 'Spree::PriceRule', dependent: :destroyhas_many :prices, class_name: 'Spree::Price', dependent: :destroy_async- has_many :variants, -> { where(spree_prices: { deleted_at: nil }) }, through: :prices, source: :variant- has_many :products, -> { where(spree_prices: { deleted_at: nil }) }, through: :variants, source: :product+ has_many :variants, -> { where(spree_prices: { deleted_at: nil }).distinct }, through: :prices, source: :variant+ has_many :products, -> { where(spree_prices: { deleted_at: nil }).distinct }, through: :variants, source: :productalias price_list_products products# Override default nested attributes to use bulk_update_prices for performancediff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rbindex 2136128008..bcacd3fc10 100644--- a/core/app/models/spree/product.rb+++ b/core/app/models/spree/product.rb@@ -43,6 +43,8 @@ module Spreedefault_image secondary_imagepurchasable? in_stock? backorderable? has_variants? digital?]+ STATUSES = %w[draft active archived].freeze+STATUS_TO_WEBHOOK_EVENT = {'active' => 'activated','draft' => 'drafted',diff --git a/docs/developer/admin/tables.mdx b/docs/developer/admin/tables.mdxindex aedcbf156c..eb6d036bec 100644--- a/docs/developer/admin/tables.mdx+++ b/docs/developer/admin/tables.mdx@@ -517,6 +517,7 @@ Spree registers tables for all built-in resources:| `:post_categories` | `Spree::PostCategory` || `:webhook_endpoints` | `Spree::WebhookEndpoint` || `:webhook_deliveries` | `Spree::WebhookDelivery` |+| `:price_list_products` | `Spree::Product` (nested) |## API Reference