Add our own SuppliedProduct with custom property

This commit is contained in:
Maikel Linke
2023-08-11 13:17:38 +10:00
parent c42f62e09f
commit fcf7b94278
5 changed files with 27 additions and 11 deletions

View File

@@ -1,8 +1,5 @@
# frozen_string_literal: true
# Load our monkey-patches:
require "data_food_consortium/connector/connector"
# Our interface to the DFC Connector library.
module DfcIo
# Serialise DFC Connector subjects as JSON-LD string.

View File

@@ -1,7 +1,5 @@
# frozen_string_literal: true
require "data_food_consortium/connector/connector"
class DfcLoader
def self.connector
@connector ||= load_vocabularies

View File

@@ -7,17 +7,14 @@ class SuppliedProductBuilder < DfcBuilder
id: variant.id,
)
DataFoodConsortium::Connector::SuppliedProduct.new(
DfcProvider::SuppliedProduct.new(
id,
name: variant.name_to_display,
description: variant.description,
productType: product_type,
quantity: QuantitativeValueBuilder.quantity(variant),
).tap do |supplied_product|
supplied_product.registerSemanticProperty("ofn:spree_product_id") do
variant.product.id
end
end
spree_product_id: variant.product.id,
)
end
def self.import(supplied_product)

View File

@@ -1,6 +1,13 @@
# frozen_string_literal: true
# Load our monkey-patches of the DFC Connector:
require "data_food_consortium/connector/connector"
# Our Rails engine
require "dfc_provider/engine"
# Custom data types
require "dfc_provider/supplied_product"
module DfcProvider
end

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
module DfcProvider
class SuppliedProduct < DataFoodConsortium::Connector::SuppliedProduct
attr_accessor :spree_product_id
def initialize(semantic_id, spree_product_id: nil, **properties)
super(semantic_id, **properties)
self.spree_product_id = spree_product_id
registerSemanticProperty("ofn:spree_product_id") do
self.spree_product_id
end
end
end
end