mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add our own SuppliedProduct with custom property
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "data_food_consortium/connector/connector"
|
||||
|
||||
class DfcLoader
|
||||
def self.connector
|
||||
@connector ||= load_vocabularies
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
17
engines/dfc_provider/lib/dfc_provider/supplied_product.rb
Normal file
17
engines/dfc_provider/lib/dfc_provider/supplied_product.rb
Normal 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
|
||||
Reference in New Issue
Block a user