Skip to content

Commit

Permalink
make currency translator a common util and use it for dfc products en…
Browse files Browse the repository at this point in the history
…dpoint / get currencyCode via query
  • Loading branch information
dupreesi committed Oct 9, 2024
1 parent cd6e49c commit 953c754
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 175 deletions.
9 changes: 7 additions & 2 deletions web/connector/productUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { throwError } from '../utils/index.js';
import loadConnectorWithResources from './index.js';
import loadProductTypes from './mappedProductTypes.js';
import config from '../config.js';
import currencyMeasureFor from '../utils/currencyMeasureFor.js';

const createQuantitativeValue = (connector, value, unit) =>
connector.createQuantity({
Expand Down Expand Up @@ -45,7 +46,6 @@ async function createVariantSuppliedProduct(
try {
const connector = await loadConnectorWithResources();
const kilogram = connector.MEASURES.UNIT.QUANTITYUNIT.KILOGRAM;
const euro = connector.MEASURES.UNIT.CURRENCYUNIT.EURO;

const semanticBase = `${config.PRODUCER_SHOP_URL}api/dfc/Enterprises/${enterpriseName}/SuppliedProducts/${variant.id}`;

Expand All @@ -55,7 +55,12 @@ async function createVariantSuppliedProduct(
kilogram
);
const hasVat = variant.taxable ? 1.0 : 0.0; // TODO check how the vat rate can be added
const price = createPrice(connector, variant.price, euro, hasVat);
const price = createPrice(
connector,
variant.price,
currencyMeasureFor(connector, variant.currencyCode),
hasVat
);
const offer = createOffer(connector, semanticBase, price);
const inventoryQuantity =
variant.inventoryPolicy === 'CONTINUE' ? -1 : variant.inventoryQuantity;
Expand Down
Loading

0 comments on commit 953c754

Please sign in to comment.