From 851ce281eaf4ea79d90c0c2a690cdd7139b053bb Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Wed, 8 Nov 2023 18:36:22 +0500 Subject: [PATCH 1/6] #11067, implement product clone --- app/controllers/spree/admin/products_controller.rb | 2 +- .../admin/products_v3/components/_product_actions.html.haml | 1 + config/locales/en.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 5373d040dd..5b5b5c1d9d 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -89,7 +89,7 @@ module Spree Spree.t('notice_messages.product_not_cloned') end - redirect_to spree.edit_admin_product_url(@new) + redirect_to spree.admin_products_url end def group_buy_options diff --git a/app/views/admin/products_v3/components/_product_actions.html.haml b/app/views/admin/products_v3/components/_product_actions.html.haml index a465498eac..45b9f891d2 100644 --- a/app/views/admin/products_v3/components/_product_actions.html.haml +++ b/app/views/admin/products_v3/components/_product_actions.html.haml @@ -5,3 +5,4 @@ = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(product, variant), class: "vertical-ellipsis-menu-content-item" - else = link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" + = link_to t('admin.products_page.actions.clone'), clone_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" diff --git a/config/locales/en.yml b/config/locales/en.yml index a66c36bdfc..46377241f9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -576,6 +576,7 @@ en: import_date: "Import Date" actions: edit: Edit + clone: Clone adjustments: skipped_changing_canceled_order: "You can't change a cancelled order." # Common properties / models From e1e46bcbc2764abb173c294d553178c10e7659ac Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 10 Nov 2023 15:36:10 +0500 Subject: [PATCH 2/6] #11067, hide clone option for variant --- .../admin/products_v3/components/_product_actions.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/products_v3/components/_product_actions.html.haml b/app/views/admin/products_v3/components/_product_actions.html.haml index 45b9f891d2..8152ec1584 100644 --- a/app/views/admin/products_v3/components/_product_actions.html.haml +++ b/app/views/admin/products_v3/components/_product_actions.html.haml @@ -5,4 +5,4 @@ = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(product, variant), class: "vertical-ellipsis-menu-content-item" - else = link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" - = link_to t('admin.products_page.actions.clone'), clone_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" + = link_to t('admin.products_page.actions.clone'), clone_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" From d8904099dd85bcf358c2e7182349c81325faa755 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sat, 11 Nov 2023 15:47:59 +0500 Subject: [PATCH 3/6] #11067, remove messages to match with old UI UX --- app/controllers/spree/admin/products_controller.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 5b5b5c1d9d..3ecc96dab6 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -82,12 +82,7 @@ module Spree def clone @new = @product.duplicate - - flash[:success] = if @new.save - Spree.t('notice_messages.product_cloned') - else - Spree.t('notice_messages.product_not_cloned') - end + @new.save redirect_to spree.admin_products_url end From ab93b06bac530a7768a50ed52380282ef53277cd Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sat, 11 Nov 2023 15:58:29 +0500 Subject: [PATCH 4/6] #11067, add specs --- .../system/admin/products_v3/products_spec.rb | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 5316a3118f..17b4494297 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -337,6 +337,62 @@ describe 'As an admin, I can see the new product page' do end end + describe "Cloning Feature" do + let!(:variant_a1) { + create(:variant, + product: product_a, + display_name: "Medium box", + sku: "APL-01", + price: 5.25) + } + let(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") } + + before do + visit admin_products_url + end + + describe "Actions columns (clone)" do + it "shows an actions menu with a clone link when clicking on icon for product" do + within row_containing_name("Apples") do + page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Clone", href: spree.clone_admin_product_path(product_a) + end + end + + it "does not show actions menu with a clone link when clicking on icon for variant" do + within row_containing_name("Medium box") do + page.find(".vertical-ellipsis-menu").click + expect(page).to_not have_link "Clone", href: spree.clone_admin_product_path(product_a) + end + end + end + + describe "Cloning product"do + it "shows the cloned product on page when clicked on the cloned option" do + within "table.products" do + # Gather input values, because page.content doesn't include them. + input_content = page.find_all('input[type=text]').map(&:value).join + + # Products does not include the cloned product. + expect(input_content).to_not match /COPY OF Apples/ + end + + within row_containing_name("Apples") do + page.find(".vertical-ellipsis-menu").click + click_link('Clone') + end + + within "table.products" do + # Gather input values, because page.content doesn't include them. + input_content = page.find_all('input[type=text]').map(&:value).join + + # Products include the cloned product. + expect(input_content).to match /COPY OF Apples/ + end + end + end + end + def create_products(amount) amount.times do |i| create(:simple_product, name: "product #{i}") From 8bac8ad4be417bdff1e0f6f61924487944346a14 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sat, 11 Nov 2023 16:04:28 +0500 Subject: [PATCH 5/6] 11067, fix lint issues --- spec/system/admin/products_v3/products_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 17b4494297..6b88532838 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -367,7 +367,7 @@ describe 'As an admin, I can see the new product page' do end end - describe "Cloning product"do + describe "Cloning product" do it "shows the cloned product on page when clicked on the cloned option" do within "table.products" do # Gather input values, because page.content doesn't include them. From 668b102efcc5c409cb65a62d03b56addd17271e3 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 17 Nov 2023 10:21:55 +1100 Subject: [PATCH 6/6] Combine two specs for efficiency --- spec/system/admin/products_v3/products_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 6b88532838..ae15335578 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -357,9 +357,7 @@ describe 'As an admin, I can see the new product page' do page.find(".vertical-ellipsis-menu").click expect(page).to have_link "Clone", href: spree.clone_admin_product_path(product_a) end - end - it "does not show actions menu with a clone link when clicking on icon for variant" do within row_containing_name("Medium box") do page.find(".vertical-ellipsis-menu").click expect(page).to_not have_link "Clone", href: spree.clone_admin_product_path(product_a)