From 8620f0a37d0cca1c9101ca470039b440c9d02181 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Jan 2025 17:14:51 +1100 Subject: [PATCH] Product group can be present or just linked --- .../app/services/supplied_product_builder.rb | 7 ++----- .../app/services/supplied_product_importer.rb | 11 ++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/engines/dfc_provider/app/services/supplied_product_builder.rb b/engines/dfc_provider/app/services/supplied_product_builder.rb index 9cc11113955..10afbf3f907 100644 --- a/engines/dfc_provider/app/services/supplied_product_builder.rb +++ b/engines/dfc_provider/app/services/supplied_product_builder.rb @@ -10,10 +10,7 @@ def self.supplied_product(variant) variant.supplier_id, spree_product_id: variant.product_id ) - technical_product_id = urls.enterprise_technical_product_url( - enterprise_id: variant.supplier_id, - id: variant.product_id, - ) + technical_product = TechnicalProductBuilder.technical_product(variant.product) DfcProvider::SuppliedProduct.new( id, @@ -21,7 +18,7 @@ def self.supplied_product(variant) description: variant.description, productType: DfcProductTypeFactory.for(variant.primary_taxon&.dfc_id), quantity: QuantitativeValueBuilder.quantity(variant), - isVariantOf: [technical_product_id], + isVariantOf: [technical_product], spree_product_uri: product_uri, spree_product_id: variant.product.id, image_url: variant.product&.image&.url(:product) diff --git a/engines/dfc_provider/app/services/supplied_product_importer.rb b/engines/dfc_provider/app/services/supplied_product_importer.rb index 9f9078f4ede..9d31b7dce1e 100644 --- a/engines/dfc_provider/app/services/supplied_product_importer.rb +++ b/engines/dfc_provider/app/services/supplied_product_importer.rb @@ -51,7 +51,9 @@ def self.referenced_spree_product(supplied_product, supplier) def self.spree_product(supplied_product, supplier) supplied_product.isVariantOf.lazy.map do |group| - group_id = group.semanticId + # We may have an object or just the id here: + group_id = group.try(:semanticId) || group + id = begin route = Rails.application.routes.recognize_path(group_id) @@ -68,7 +70,9 @@ def self.spree_product(supplied_product, supplier) end def self.spree_product_linked(supplied_product, supplier) - semantic_ids = supplied_product.isVariantOf.map(&:semanticId) + semantic_ids = supplied_product.isVariantOf.map do |id_or_object| + id_or_object.try(:semanticId) || id_or_object + end supplier.supplied_products.includes(:semantic_link) .where(semantic_link: { semantic_id: semantic_ids }) .first @@ -121,7 +125,8 @@ def self.apply(supplied_product, variant) end def self.semantic_link(supplied_product) - semantic_id = supplied_product.isVariantOf.first&.semanticId + group = supplied_product.isVariantOf.first + semantic_id = group.try(:semanticId) || semantic_id SemanticLink.new(semantic_id:) if semantic_id.present? end