diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 5373d040dd..3ecc96dab6 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -82,14 +82,9 @@ module Spree def clone @new = @product.duplicate + @new.save - flash[:success] = if @new.save - Spree.t('notice_messages.product_cloned') - else - 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..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,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 7ebf889ee8..f512b2b9b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -579,6 +579,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 diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 14a59ebd3e..c9f35240d2 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -335,6 +335,60 @@ describe 'As an admin, I can see the new product page', feature: :admin_style_v3 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 + + 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}")