diff --git a/engines/dfc_provider/app/services/product_group_builder.rb b/engines/dfc_provider/app/services/product_group_builder.rb index fd25b21f84..50c1088914 100644 --- a/engines/dfc_provider/app/services/product_group_builder.rb +++ b/engines/dfc_provider/app/services/product_group_builder.rb @@ -12,6 +12,15 @@ class ProductGroupBuilder < DfcBuilder DataFoodConsortium::Connector::SuppliedProduct.new( id, variants:, + name: product.name, ) end + + def self.apply(supplied_product, spree_product) + description = supplied_product.isVariantOf.first.try(:description) || + supplied_product.description + name = supplied_product.isVariantOf.first.try(:name) + spree_product.description = description if description.present? + spree_product.name = name if name.present? + end end diff --git a/engines/dfc_provider/app/services/supplied_product_importer.rb b/engines/dfc_provider/app/services/supplied_product_importer.rb index 9d7920e820..cbeb8d3cdf 100644 --- a/engines/dfc_provider/app/services/supplied_product_importer.rb +++ b/engines/dfc_provider/app/services/supplied_product_importer.rb @@ -112,7 +112,7 @@ class SuppliedProductImporter < DfcBuilder end def self.apply(supplied_product, variant) - variant.product.assign_attributes(description: supplied_product.description) + ProductGroupBuilder.apply(supplied_product, variant.product) variant.display_name = supplied_product.name variant.primary_taxon = taxon(supplied_product) diff --git a/engines/dfc_provider/spec/services/supplied_product_importer_spec.rb b/engines/dfc_provider/spec/services/supplied_product_importer_spec.rb index ae2f0083b5..2a4fc0e856 100644 --- a/engines/dfc_provider/spec/services/supplied_product_importer_spec.rb +++ b/engines/dfc_provider/spec/services/supplied_product_importer_spec.rb @@ -218,6 +218,15 @@ RSpec.describe SuppliedProductImporter do expect(imported_variant.primary_taxon).to eq(new_taxon) end + it "copies name and description from parent product" do + supplied_product.isVariantOf << DfcProvider::SuppliedProduct.new( + "some-id", name: "Our tomatoes", description: "Choose a variety." + ) + imported_product = imported_variant.product + expect(imported_product.name).to eq "Our tomatoes" + expect(imported_product.description).to eq "Choose a variety." + end + context "when spree_product_uri doesn't match the server host" do let(:supplied_product) do DfcProvider::SuppliedProduct.new( diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index 66a924ceed..eb38ea6532 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -182,6 +182,7 @@ paths: ofn:spree_product_uri: http://test.host/api/dfc/enterprises/10000?spree_product_id=90000 - "@id": http://test.host/api/dfc/enterprises/10000/product_groups/90000 "@type": dfc-b:SuppliedProduct + dfc-b:name: Apple dfc-b:hasVariant: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 - "@id": http://test.host/api/dfc/enterprises/10000/offers/10001 "@type": dfc-b:Offer @@ -584,6 +585,7 @@ paths: "@context": https://www.datafoodconsortium.org "@id": http://test.host/api/dfc/enterprises/10000/product_groups/90000 "@type": dfc-b:SuppliedProduct + dfc-b:name: Pesto dfc-b:hasVariant: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "/api/dfc/enterprises/{enterprise_id}/social_medias/{name}": get: