mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Use product group attributes for Spree::Product updates
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user