Create sourced variant link on clone

This commit is contained in:
David Cook
2026-02-17 12:36:53 +11:00
parent 04c0adf960
commit b877540f5f
2 changed files with 7 additions and 1 deletions

View File

@@ -118,10 +118,10 @@ module Admin
variant = source_variant.dup #may need a VariantDuplicator like producs?
variant.price = source_variant.price
variant.save!
variant.source_variants << source_variant
variant.on_demand = source_variant.on_demand
variant.on_hand = source_variant.on_hand
variant.save!
#todo: create link to source
flash.now[:success] = t('.success')
variant_index = "-#{variant.id}"

View File

@@ -97,6 +97,12 @@ RSpec.describe "Admin::ProductsV3" do
expect(response).to have_http_status(:ok)
expect(response.body).to match "Original variant" # cloned variant name
}.to change { variant.product.variants.count }.by(1)
new_variant = variant.product.variants.last
# The new variant is a target of the original. It is a "sourced" variant.
expect(variant.target_variants.first).to eq new_variant
# The new variant's source is the original
expect(new_variant.source_variants.first).to eq variant
end
end
end