Move taxon discovery to own class for additions

This commit is contained in:
Maikel Linke
2025-01-30 10:17:20 +11:00
parent 1fcefcfcd0
commit 26d09acafe
2 changed files with 12 additions and 5 deletions

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class ProductTypeImporter < DfcBuilder
def self.taxon(product_type)
dfc_id = product_type&.semanticId
# Every product needs a primary taxon to be valid. So if we don't have
# one or can't find it we just take a random one.
Spree::Taxon.find_by(dfc_id:) || Spree::Taxon.first
end
end

View File

@@ -111,11 +111,7 @@ class SuppliedProductBuilder < DfcBuilder
end
def self.taxon(supplied_product)
dfc_id = supplied_product.productType&.semanticId
# Every product needs a primary taxon to be valid. So if we don't have
# one or can't find it we just take a random one.
Spree::Taxon.find_by(dfc_id:) || Spree::Taxon.first
ProductTypeImporter.taxon(supplied_product.productType)
end
private_class_method :product_type, :taxon