Skip to content

Commit

Permalink
Product group can be present or just linked
Browse files Browse the repository at this point in the history
  • Loading branch information
mkllnk committed Jan 24, 2025
1 parent 5cd20a7 commit 8620f0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 2 additions & 5 deletions engines/dfc_provider/app/services/supplied_product_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ 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,
name: variant.product_and_full_name,
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)
Expand Down
11 changes: 8 additions & 3 deletions engines/dfc_provider/app/services/supplied_product_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8620f0a

Please sign in to comment.