diff --git a/admin/app/components/solidus_admin/products/index/component.html.erb b/admin/app/components/solidus_admin/products/index/component.html.erb index ab9cb3c6880..1d93b2abd53 100644 --- a/admin/app/components/solidus_admin/products/index/component.html.erb +++ b/admin/app/components/solidus_admin/products/index/component.html.erb @@ -4,7 +4,7 @@ <%= page_header_actions do %> <%= render component("ui/button").new( tag: :a, - text: t('.add_product'), + text: t('.add'), href: spree.new_admin_product_path, icon: "add-line", ) %> diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 61ed95110fd..df52184f00e 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -62,6 +62,10 @@ def filters def scopes [ { name: :all, label: t('.scopes.all'), default: true }, + { name: :in_stock, label: t('.scopes.in_stock') }, + { name: :out_of_stock, label: t('.scopes.out_of_stock') }, + { name: :available, label: t('.scopes.available') }, + { name: :discontinued, label: t('.scopes.discontinued') }, { name: :deleted, label: t('.scopes.deleted') }, ] end @@ -79,7 +83,7 @@ def columns def image_column { col: { class: "w-[72px]" }, - header: tag.span('aria-label': t('.product_image'), role: 'text'), + header: tag.span('aria-label': t('.image'), role: 'text'), data: ->(product) do image = product.gallery.images.first or return diff --git a/admin/app/components/solidus_admin/products/index/component.yml b/admin/app/components/solidus_admin/products/index/component.yml index 4de6e6f3e48..8ae8270bd25 100644 --- a/admin/app/components/solidus_admin/products/index/component.yml +++ b/admin/app/components/solidus_admin/products/index/component.yml @@ -1,6 +1,6 @@ en: - product_image: 'Image' - add_product: 'Add Product' + image: 'Image' + add: 'Add new' batch_actions: delete: 'Delete' discontinue: 'Discontinue' @@ -9,4 +9,8 @@ en: with_deleted: Include deleted scopes: all: All + available: Available + discontinued: Discontinued + in_stock: In stock + out_of_stock: Out of stock deleted: Deleted diff --git a/admin/app/components/solidus_admin/products/status/component.rb b/admin/app/components/solidus_admin/products/status/component.rb index 190e97779a4..2c7be1885f6 100644 --- a/admin/app/components/solidus_admin/products/status/component.rb +++ b/admin/app/components/solidus_admin/products/status/component.rb @@ -3,11 +3,21 @@ class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent STATUSES = { available: :green, - discontinued: :red + discontinued: :yellow, + deleted: :red, }.freeze def self.from_product(product) - new(status: product.available? ? :available : :discontinued) + status = + if product.deleted? + :deleted + elsif product.discontinued? + :discontinued + else + :available + end + + new(status: status) end def initialize(status:) diff --git a/admin/app/components/solidus_admin/products/status/component.yml b/admin/app/components/solidus_admin/products/status/component.yml index c0f10400804..51e56549a30 100644 --- a/admin/app/components/solidus_admin/products/status/component.yml +++ b/admin/app/components/solidus_admin/products/status/component.yml @@ -1,3 +1,4 @@ en: available: 'Available' discontinued: 'Discontinued' + deleted: 'Deleted' diff --git a/admin/app/components/solidus_admin/promotions/index/component.yml b/admin/app/components/solidus_admin/promotions/index/component.yml index 6f43121d76f..cdb40f9455b 100644 --- a/admin/app/components/solidus_admin/promotions/index/component.yml +++ b/admin/app/components/solidus_admin/promotions/index/component.yml @@ -1,6 +1,6 @@ en: promotion_image: 'Image' - add: 'Add Promotion' + add: 'Add new' batch_actions: delete: 'Delete' scopes: diff --git a/admin/app/components/solidus_admin/users/index/component.yml b/admin/app/components/solidus_admin/users/index/component.yml index 179e1336f95..6a7fa4eaab4 100644 --- a/admin/app/components/solidus_admin/users/index/component.yml +++ b/admin/app/components/solidus_admin/users/index/component.yml @@ -1,6 +1,6 @@ en: promotion_image: 'Image' - add: 'Add Promotion' + add: 'Add new' batch_actions: delete: 'Delete' discontinue: 'Discontinue' diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb index c82a5ebd1a8..5479bbe6519 100644 --- a/admin/app/controllers/solidus_admin/products_controller.rb +++ b/admin/app/controllers/solidus_admin/products_controller.rb @@ -6,6 +6,10 @@ class ProductsController < SolidusAdmin::BaseController search_scope(:all, default: true) search_scope(:deleted) { _1.with_discarded.discarded } + search_scope(:discontinued) { _1.where(discontinue_on: ...Time.current) } + search_scope(:available) { _1.available } + search_scope(:in_stock) { _1.where(id: Spree::Variant.in_stock.distinct.select(:product_id)) } + search_scope(:out_of_stock) { _1.where.not(id: Spree::Variant.in_stock.distinct.select(:product_id)) } def index products = apply_search_to( @@ -28,7 +32,7 @@ def edit end def show - @product = Spree::Product.friendly.find(params[:id]) + @product = Spree::Product.with_discarded.friendly.find(params[:id]) respond_to do |format| format.html { render component('products/show').new(product: @product) } diff --git a/admin/spec/components/solidus_admin/products/status/component_spec.rb b/admin/spec/components/solidus_admin/products/status/component_spec.rb index 45f1d52ba75..7a705f01505 100644 --- a/admin/spec/components/solidus_admin/products/status/component_spec.rb +++ b/admin/spec/components/solidus_admin/products/status/component_spec.rb @@ -21,7 +21,7 @@ render_inline described_class.from_product(product) - expect(rendered_content).to have_text("Discontinued") + within('tbody') { expect(rendered_content).to have_text("Discontinued") } end end end diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index b390e4c24bb..f450020428f 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -59,10 +59,13 @@ click_button "Activate" expect(page).to have_content("Products were successfully activated.", wait: 5) - expect(page).to have_content("Just a product") - expect(page).to have_content("Another product") - expect(page).not_to have_content("Discontinued") - expect(page).to have_content("Available").twice + within('tbody') do + expect(page).to have_content("Just a product") + expect(page).to have_content("Another product") + expect(page).not_to have_content("Discontinued") + expect(page).to have_content("Available").twice + end + expect(page).to be_axe_clean end end