Skip to content

Commit

Permalink
Publish price as in new DFC standard
Browse files Browse the repository at this point in the history
  • Loading branch information
mkllnk committed Jan 15, 2025
1 parent eace31f commit 68fbd7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 10 additions & 1 deletion engines/dfc_provider/app/services/offer_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ def self.build(variant)
id: variant.id,
)

price = DataFoodConsortium::Connector::Price.new(
value: variant.price.to_f,

# The DFC measures define only five currencies at the moment.
# And they are not standardised enough to align with our ISO 4217
# currency codes. So I propose to just use those currency codes instead.
# https://github.com/datafoodconsortium/taxonomies/issues/48
unit: "dfc-m:#{variant.currency}",
)
DataFoodConsortium::Connector::Offer.new(
id,
price: variant.price.to_f,
price: DataFoodConsortium::Connector::Price.new(value: price),
stockLimitation: stock_limitation(variant),
)
end
Expand Down
21 changes: 18 additions & 3 deletions swagger/dfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ paths:
ofn:spree_product_uri: http://test.host/api/dfc/enterprises/10000?spree_product_id=90000
- "@id": http://test.host/api/dfc/enterprises/10000/offers/10001
"@type": dfc-b:Offer
dfc-b:hasPrice: 19.99
dfc-b:hasPrice:
"@type": dfc-b:Price
dfc-b:value:
"@type": dfc-b:Price
dfc-b:value: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 0
'401':
description: unauthorized
Expand Down Expand Up @@ -219,7 +224,12 @@ paths:
dfc-b:offeredThrough: http://test.host/api/dfc/enterprises/10000/offers/10001
- "@id": http://test.host/api/dfc/enterprises/10000/offers/10001
"@type": dfc-b:Offer
dfc-b:hasPrice: 19.99
dfc-b:hasPrice:
"@type": dfc-b:Price
dfc-b:value:
"@type": dfc-b:Price
dfc-b:value: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 0
'404':
description: not found
Expand Down Expand Up @@ -499,7 +509,12 @@ paths:
"@context": https://www.datafoodconsortium.org
"@id": http://test.host/api/dfc/enterprises/10000/offers/10001
"@type": dfc-b:Offer
dfc-b:hasPrice: 19.99
dfc-b:hasPrice:
"@type": dfc-b:Price
dfc-b:value:
"@type": dfc-b:Price
dfc-b:value: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 5
put:
summary: Update Offer
Expand Down

0 comments on commit 68fbd7c

Please sign in to comment.