Publish supplier of catalog item

This commit is contained in:
Maikel Linke
2025-10-10 16:18:00 +11:00
parent c6a34cfe34
commit b2da57b496
5 changed files with 57 additions and 11 deletions

View File

@@ -47,7 +47,7 @@ Metrics/BlockNesting:
Exclude:
- 'app/models/spree/payment/processing.rb'
# Offense count: 47
# Offense count: 48
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
@@ -88,6 +88,7 @@ Metrics/ClassLength:
- 'app/services/cart_service.rb'
- 'app/services/order_cycles/form_service.rb'
- 'app/services/orders/sync_service.rb'
- 'app/services/permissions/order.rb'
- 'app/services/sets/product_set.rb'
- 'engines/order_management/app/services/order_management/order/updater.rb'
- 'lib/open_food_network/enterprise_fee_calculator.rb'
@@ -98,7 +99,6 @@ Metrics/ClassLength:
- 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb'
- 'lib/reporting/reports/enterprise_fee_summary/scope.rb'
- 'lib/reporting/reports/xero_invoices/base.rb'
- 'app/services/permissions/order.rb'
# Offense count: 30
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
@@ -129,14 +129,13 @@ Metrics/CyclomaticComplexity:
- 'lib/spree/localized_number.rb'
- 'spec/models/product_importer_spec.rb'
# Offense count: 23
# Offense count: 22
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/helpers/spree/admin/navigation_helper.rb'
- 'app/models/spree/ability.rb'
- 'app/models/spree/gateway/pay_pal_express.rb'
- 'app/models/spree/order/checkout.rb'
@@ -149,7 +148,7 @@ Metrics/MethodLength:
- 'lib/spree/localized_number.rb'
- 'lib/tasks/sample_data/product_factory.rb'
# Offense count: 47
# Offense count: 10
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ModuleLength:
Exclude:
@@ -174,7 +173,7 @@ Metrics/ParameterLists:
- 'spec/support/controller_requests_helper.rb'
- 'spec/system/admin/reports_spec.rb'
# Offense count: 3
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/PerceivedComplexity:
Exclude:
@@ -182,6 +181,27 @@ Metrics/PerceivedComplexity:
- 'app/models/spree/ability.rb'
- 'app/models/spree/order/checkout.rb'
# Offense count: 1
# Configuration parameters: EnforcedStyle, AllowedPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
Exclude:
- 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb'
# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb'
# Offense count: 3
# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
Exclude:
- 'engines/dfc_provider/lib/dfc_provider/catalog_item.rb'
# Offense count: 1
# Configuration parameters: TransactionMethods.
Rails/TransactionExitStatement:

View File

@@ -6,13 +6,15 @@ class CatalogItemBuilder < DfcBuilder
enterprise_id: variant.supplier_id,
id: variant.id,
)
supplier_url = urls.enterprise_url(variant.supplier_id)
product = SuppliedProductBuilder.supplied_product(variant)
DataFoodConsortium::Connector::CatalogItem.new(
DfcProvider::CatalogItem.new(
id, product:,
sku: variant.sku,
stockLimitation: stock_limitation(variant),
offers: [OfferBuilder.build(variant)],
managedBy: supplier_url,
)
end

View File

@@ -9,6 +9,7 @@ require "dfc_provider/engine"
# Custom data types
require "dfc_provider/supplied_product"
require "dfc_provider/address"
require "dfc_provider/catalog_item"
require "dfc_provider/coordination"
# 🙈 Monkey-patch a better inspector for semantic objects

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
# Temporary solution.
module DfcProvider
class CatalogItem < DataFoodConsortium::Connector::CatalogItem
attr_accessor :managedBy
def initialize(semantic_id, managedBy: "", **properties)
super(semantic_id, **properties)
@managedBy = managedBy
registerSemanticProperty("dfc-b:managedBy", &method("managedBy"))
.valueSetter = method("managedBy=")
end
end
end

View File

@@ -6,10 +6,12 @@ RSpec.describe CatalogItemBuilder do
let(:variant) { build(:variant) }
describe ".catalog_item" do
it "assigns a semantic id" do
before do
variant.id = 5
variant.supplier_id = 7
end
it "assigns a semantic id" do
item = CatalogItemBuilder.catalog_item(variant)
expect(item.semanticId).to eq(
@@ -18,15 +20,20 @@ RSpec.describe CatalogItemBuilder do
end
it "refers to a supplied product" do
variant.id = 5
variant.supplier_id = 7
item = CatalogItemBuilder.catalog_item(variant)
expect(item.product.semanticId).to eq(
"http://test.host/api/dfc/enterprises/7/supplied_products/5"
)
end
it "refers to the supplier" do
item = CatalogItemBuilder.catalog_item(variant)
expect(item.managedBy).to eq(
"http://test.host/api/dfc/enterprises/7"
)
end
end
describe ".apply_stock" do