Publish price as in new DFC standard

This commit is contained in:
Maikel Linke
2025-01-14 15:36:28 +11:00
parent eace31f1fc
commit 84648690a6
3 changed files with 32 additions and 7 deletions

View File

@@ -7,10 +7,17 @@ class OfferBuilder < DfcBuilder
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,
stockLimitation: stock_limitation(variant),
id, price:, stockLimitation: stock_limitation(variant),
)
end

View File

@@ -3,7 +3,7 @@
require_relative "../spec_helper"
RSpec.describe OfferBuilder do
let(:variant) { build(:variant) }
let(:variant) { build(:variant, id: 5) }
describe ".offer" do
it "assigns a stock level" do
@@ -26,5 +26,14 @@ RSpec.describe OfferBuilder do
expect(offer.stockLimitation).to eq nil
end
it "assigns a price with currency" do
variant.id = 5
offer = OfferBuilder.build(variant)
expect(offer.price.value).to eq 19.99
expect(offer.price.unit).to eq "dfc-m:AUD"
end
end
end

View File

@@ -181,7 +181,10 @@ 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: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 0
'401':
description: unauthorized
@@ -219,7 +222,10 @@ 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: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 0
'404':
description: not found
@@ -499,7 +505,10 @@ 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: 19.99
dfc-b:hasUnit: dfc-m:AUD
dfc-b:stockLimitation: 5
put:
summary: Update Offer