mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #11785 from chahmedejaz/task/11067-admin_style_v3-product-clone
Implement product clone
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user