From 4bac83dd8344c78842ff8df84c824765de4c5123 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 11 Jan 2024 15:07:20 +1100 Subject: [PATCH] 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. --- engines/dfc_provider/app/services/supplied_product_builder.rb | 2 +- engines/dfc_provider/spec/requests/supplied_products_spec.rb | 2 +- swagger/dfc.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/dfc_provider/app/services/supplied_product_builder.rb b/engines/dfc_provider/app/services/supplied_product_builder.rb index 2d776eafdb..143f9d341e 100644 --- a/engines/dfc_provider/app/services/supplied_product_builder.rb +++ b/engines/dfc_provider/app/services/supplied_product_builder.rb @@ -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 diff --git a/engines/dfc_provider/spec/requests/supplied_products_spec.rb b/engines/dfc_provider/spec/requests/supplied_products_spec.rb index 3e59aa2bad..8f39d971b7 100644 --- a/engines/dfc_provider/spec/requests/supplied_products_spec.rb +++ b/engines/dfc_provider/spec/requests/supplied_products_spec.rb @@ -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 diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index a7a8df3e83..cafd36a9ad 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -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: