mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-23 17:05:53 +02:00
Fix mpreis units
This commit is contained in:
parent
4c55a085b2
commit
b8577bb507
|
@ -2,22 +2,41 @@ const axios = require("axios");
|
|||
const utils = require("./utils");
|
||||
|
||||
const conversions = {
|
||||
'CM': { unit: 'cm', factor: 1 },
|
||||
'DAG': { unit: 'g', factor: 10 },
|
||||
'DL': { unit: 'ml', factor: 10 },
|
||||
'GRM': { unit: 'g', factor: 1 },
|
||||
'H87': { unit: 'ml', factor: 1000 },
|
||||
'HLT': { unit: 'ml', factor: 1000 },
|
||||
'KGM': { unit: 'g', factor: 1000 },
|
||||
'LTR': { unit: 'ml', factor: 1000 },
|
||||
'MLT': { unit: 'ml', factor: 1 },
|
||||
'MTR': { unit: 'm', factor: 1 },
|
||||
'XRO': { unit: 'stk', factor: 1 },
|
||||
'cm': { unit: 'cm', factor: 1 },
|
||||
'dag': { unit: 'g', factor: 10 },
|
||||
'dl': { unit: 'ml', factor: 10 },
|
||||
'grm': { unit: 'g', factor: 1 },
|
||||
'kgm': { unit: 'g', factor: 1000 },
|
||||
'ltr': { unit: 'ml', factor: 1000 },
|
||||
'mlt': { unit: 'ml', factor: 1 },
|
||||
'mtr': { unit: 'm', factor: 1 },
|
||||
'stk': { unit: 'stk', factor: 1 },
|
||||
'stk.': { unit: 'stk', factor: 1 },
|
||||
'g': { unit: 'g', factor: 1 },
|
||||
'anw': { unit: 'stk', factor: 1 },
|
||||
'l': { unit: 'ml', factor: 1000 },
|
||||
'm': { unit: 'cm', factor: 100 },
|
||||
'ml': { unit: 'ml', factor: 1 },
|
||||
'kg': { unit: 'g', factor: 1000 },
|
||||
'paar': { unit: 'stk', factor: 1 },
|
||||
'stück': { unit: 'stk', factor: 1 },
|
||||
'bl.': { unit: 'stk', factor: 1 },
|
||||
'pkg': { unit: 'stk', factor: 1 },
|
||||
'gr': { unit: 'g', factor: 1 },
|
||||
'er': { unit: 'stk', factor: 1 },
|
||||
};
|
||||
|
||||
exports.getCanonical = function(item, today) {
|
||||
let quantity = item.prices[0].presentationPrice.measurementUnit.quantity
|
||||
let unit = item.prices[0].presentationPrice.measurementUnit.unitCode
|
||||
let unit = item.prices[0].presentationPrice.measurementUnit.unitCode.toLowerCase()
|
||||
if(['xro', 'h87', 'hlt'].indexOf(unit)!=-1) {
|
||||
const q = utils.parseUnitAndQuantityAtEnd(item.mixins.productCustomAttributes.packagingUnit)
|
||||
quantity = q[0] ?? quantity;
|
||||
unit = q[1];
|
||||
}
|
||||
if (!(unit in conversions)) {
|
||||
unit = 'stk';
|
||||
}
|
||||
const isWeighted = (item.mixins.productCustomAttributes?.packagingDescription ?? "").startsWith("Gewichtsware");
|
||||
return utils.convertUnit({
|
||||
id: item.code,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
exports.convertUnit = function (item, units, store) {
|
||||
|
||||
if(!(item.unit in units)) {
|
||||
console.error(`Unknown unit in ${store}: '${item.unit}'`);
|
||||
console.error(`Unknown unit in ${store}: '${item.unit}' in item ${item.name}`);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user