Update variant name instead of product via DFC

A DFC SuppliedProduct relates to a Spree::Variant and when updating its
name we only want to change the name for that variant. Otherwise, when
we update the name of the product, it would update the name for all
variants and all the corresponding SuppliedProducts.
This commit is contained in:
Maikel Linke
2024-01-11 15:07:20 +11:00
parent 2ff2cebb0d
commit 4bac83dd83
3 changed files with 3 additions and 3 deletions

View File

@@ -49,10 +49,10 @@ class SuppliedProductBuilder < DfcBuilder
def self.apply(supplied_product, variant)
variant.product.assign_attributes(
name: supplied_product.name,
description: supplied_product.description,
)
variant.display_name = supplied_product.name
QuantitativeValueBuilder.apply(supplied_product.quantity, variant.product)
variant.unit_value = variant.product.unit_value
end

View File

@@ -188,7 +188,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", rswag_auto
submit_request(example.metadata)
variant.reload
}.to change { variant.description }.to("DFC-Pesto updated")
.and change { variant.name }.to("Pesto novo")
.and change { variant.display_name }.to("Pesto novo")
.and change { variant.unit_value }.to(17)
end
end

View File

@@ -489,7 +489,7 @@ paths:
"@context": https://www.datafoodconsortium.org
"@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001
"@type": dfc-b:SuppliedProduct
dfc-b:name: Apple - 6g
dfc-b:name: Apple (6g)
dfc-b:description: A delicious heritage apple
dfc-b:hasType: dfc-pt:non-local-vegetable
dfc-b:hasQuantity: