mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-08 07:46:59 +00:00
Compare commits
13 Commits
dependabot
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff4b8c82fa | ||
|
|
b0a28aed49 | ||
|
|
7120828123 | ||
|
|
2601a7efd3 | ||
|
|
6b79765622 | ||
|
|
b9eef83753 | ||
|
|
05f0e71545 | ||
|
|
734af38386 | ||
|
|
b11ce2cdfe | ||
|
|
9eda07064d | ||
|
|
78ee53f728 | ||
|
|
3daabe70ed | ||
|
|
6a6a1298df |
@@ -1 +1 @@
|
||||
24.10.0
|
||||
24.14.1
|
||||
|
||||
@@ -441,7 +441,7 @@ GEM
|
||||
thor (>= 0.14, < 2.0)
|
||||
jquery-ui-rails (4.2.1)
|
||||
railties (>= 3.2.16)
|
||||
json (2.19.2)
|
||||
json (2.19.3)
|
||||
json-canonicalization (1.0.0)
|
||||
json-jwt (1.17.0)
|
||||
activesupport (>= 4.2)
|
||||
@@ -1269,7 +1269,7 @@ CHECKSUMS
|
||||
jmespath (1.6.2) sha256=238d774a58723d6c090494c8879b5e9918c19485f7e840f2c1c7532cf84ebcb1
|
||||
jquery-rails (4.4.0) sha256=b1048e5bf181b94dcac82d28a4696cd79c6200167a024a07f57607ab28aa7036
|
||||
jquery-ui-rails (4.2.1) sha256=5b349e7066150b16d7a784183f040c083d51af3357937b8564aa0cc8b1cd59bd
|
||||
json (2.19.2) sha256=e7e1bd318b2c37c4ceee2444841c86539bc462e81f40d134cf97826cb14e83cf
|
||||
json (2.19.3) sha256=289b0bb53052a1fa8c34ab33cc750b659ba14a5c45f3fcf4b18762dc67c78646
|
||||
json-canonicalization (1.0.0) sha256=d4848a8cca7534455c6721f2d9fc9e5e9adca49486864a898810024f67d59446
|
||||
json-jwt (1.17.0) sha256=6ff99026b4c54281a9431179f76ceb81faa14772d710ef6169785199caadc4cc
|
||||
json-ld (3.3.2) sha256=b9531893bf5bdc01db428e96953845a23adb1097125ce918ae0f97c4a6e1ab27
|
||||
|
||||
@@ -92,7 +92,7 @@ module Orders
|
||||
end
|
||||
|
||||
def translation_scope
|
||||
"orders.customer_credit_service"
|
||||
"customer_credit_service"
|
||||
end
|
||||
|
||||
class Response
|
||||
|
||||
@@ -5220,8 +5220,7 @@ en:
|
||||
credit_payment_method_missing: Credit payment method is missing
|
||||
no_credit_available: No credit available
|
||||
not_enough_credit_available: Not enough credit available
|
||||
orders:
|
||||
customer_credit_service:
|
||||
no_credit_owed: No credit owed
|
||||
credit_payment_method_missing: Customer credit payment method is missing, please check configuration
|
||||
refund_sucessful: Refund successful!
|
||||
customer_credit_service:
|
||||
no_credit_owed: No credit owed
|
||||
credit_payment_method_missing: Customer credit payment method is missing, please check configuration
|
||||
refund_sucessful: Refund successful!
|
||||
|
||||
@@ -32,9 +32,12 @@ module Spree
|
||||
end
|
||||
|
||||
def duplicate_variants
|
||||
product.variants.map do |variant|
|
||||
# Create a hash with mapping: { <orig-variant>: <new-variant>, }
|
||||
mapped_variants = product.variants.index_with do |variant|
|
||||
duplicate_variant(variant)
|
||||
end
|
||||
duplicate_variant_links(mapped_variants)
|
||||
mapped_variants.values
|
||||
end
|
||||
|
||||
def duplicate_variant(variant)
|
||||
@@ -47,6 +50,19 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
def duplicate_variant_links(mapped_variants)
|
||||
# Find any links between orig variants (links to/from another product are ignored)
|
||||
variant_links = VariantLink.where(source_variant: [mapped_variants.keys],
|
||||
target_variant: [mapped_variants.keys])
|
||||
# Link the new variants
|
||||
variant_links.find_each do |variant_link|
|
||||
source_variant = mapped_variants[variant_link.source_variant]
|
||||
target_variant = mapped_variants[variant_link.target_variant]
|
||||
|
||||
target_variant.variant_links_as_target.new(source_variant:)
|
||||
end
|
||||
end
|
||||
|
||||
def duplicate_image(image)
|
||||
new_image = image.dup
|
||||
new_image.attachment.attach(image.attachment_blob)
|
||||
|
||||
@@ -36,6 +36,7 @@ RSpec.describe Spree::Core::ProductDuplicator do
|
||||
|
||||
it "can duplicate a product" do
|
||||
duplicator = Spree::Core::ProductDuplicator.new(product)
|
||||
allow(duplicator).to receive(:duplicate_variant_links) # tested elsewhere
|
||||
expect(new_product).to receive(:name=).with("COPY OF foo")
|
||||
expect(new_product).to receive(:sku=).with("")
|
||||
expect(new_product).to receive(:product_properties=).with([new_property])
|
||||
@@ -65,6 +66,92 @@ RSpec.describe Spree::Core::ProductDuplicator do
|
||||
end
|
||||
end
|
||||
|
||||
describe "duplicating" do
|
||||
subject { described_class.new(product).duplicate }
|
||||
|
||||
context "with multiple variant links" do
|
||||
let(:product) { create(:product) }
|
||||
|
||||
before do
|
||||
src_variant = product.variants.first.tap { it.update! display_name: "SRC" }
|
||||
user = src_variant.supplier.owner
|
||||
src_variant.create_linked_variant(user).tap { it.update! display_name: "LNK1" }
|
||||
src_variant.create_linked_variant(user).tap { it.update! display_name: "LNK2" }
|
||||
end
|
||||
|
||||
it "duplicates variant links" do
|
||||
expect(subject).to be_a Spree::Product
|
||||
expect(subject.variants.count).to eq 3
|
||||
|
||||
new_src_variant = subject.variants.find { it.display_name == "SRC" }
|
||||
new_lnk_variant1 = subject.variants.find { it.display_name == "LNK1" }
|
||||
new_lnk_variant2 = subject.variants.find { it.display_name == "LNK2" }
|
||||
|
||||
expect(new_src_variant.target_variants).to eq [new_lnk_variant1, new_lnk_variant2]
|
||||
expect(new_lnk_variant1.source_variants).to eq [new_src_variant]
|
||||
expect(new_lnk_variant2.source_variants).to eq [new_src_variant]
|
||||
end
|
||||
|
||||
it "minimises(?) database queries" do
|
||||
expect { subject }.to query_database [
|
||||
"Spree::ProductProperty Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"Spree::Image Load",
|
||||
"Spree::Price Load",
|
||||
"VariantLink Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"Spree::Variant Load",
|
||||
"TRANSACTION",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::ShippingCategory Load",
|
||||
"Spree::Taxon Load",
|
||||
"Enterprise Load",
|
||||
"Spree::Product Create",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"VariantLink Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Variant Create",
|
||||
"Spree::Price Create",
|
||||
"VariantLink Create",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Exists?",
|
||||
"Spree::StockItem Create",
|
||||
"ActsAsTaggableOn::Tagging Load",
|
||||
"Spree::Variant Update",
|
||||
"Spree::Product Update",
|
||||
"Enterprise Update",
|
||||
"Enterprise Update All",
|
||||
"Spree::Taxon Update",
|
||||
"TRANSACTION"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "errors" do
|
||||
context "with invalid product" do
|
||||
# Name has a max length of 255 char, when cloning a product the cloned product has a name
|
||||
|
||||
@@ -220,13 +220,9 @@ RSpec.describe '
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
around do |example|
|
||||
I18n.default_locale = :es
|
||||
example.run
|
||||
I18n.default_locale = :en
|
||||
end
|
||||
|
||||
before do
|
||||
allow(I18n).to receive(:default_locale).and_return(:es)
|
||||
|
||||
variant.update( unit_value: 1, unit_description: 'foo' )
|
||||
|
||||
# When I view the variant
|
||||
|
||||
Reference in New Issue
Block a user