Skip to content

Commit

Permalink
Merge pull request #13079 from mkllnk/dfc-price
Browse files Browse the repository at this point in the history
Publish price as in new DFC standard
  • Loading branch information
dacook authored Jan 21, 2025
2 parents a1df61c + 8464869 commit 51300ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 10 additions & 3 deletions engines/dfc_provider/app/services/offer_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ 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,
stockLimitation: stock_limitation(variant),
id, price:, stockLimitation: stock_limitation(variant),
)
end

Expand Down
11 changes: 10 additions & 1 deletion engines/dfc_provider/spec/services/offer_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,5 +26,14 @@

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
15 changes: 12 additions & 3 deletions swagger/dfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51300ee

Please sign in to comment.