@shushed/helpers 0.0.265 → 0.0.267

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -336,10 +336,14 @@ class FredHelperBase {
336
336
  for (const variant of variants) {
337
337
  const { id, ...rest } = variant;
338
338
  Object.entries(rest).forEach(([key, value]) => {
339
- const valueId = this.attributes.find(a => a.attribute_id === key)?.type === 'list'
340
- || this.attributes.find(a => a.attribute_id === key)?.type === 'set' || this.attributes.find(a => a.attribute_id === key)?.type === 'set64' ?
341
- (Array.isArray(value) ? value.map(v => `_${v}`).join(' | ') : `_${value}`) : '';
342
- lines.push(this.createCSVLine(variant.id, 'en_GB', key, valueId, Array.isArray(value) ? value.join(' | ') : String(value)));
339
+ const isMultivalue = this.attributes.find(a => a.attribute_id === key)?.type === 'list'
340
+ || this.attributes.find(a => a.attribute_id === key)?.type === 'set' || this.attributes.find(a => a.attribute_id === key)?.type === 'set64';
341
+ const asArr = Array.isArray(value) && isMultivalue ? value : [value];
342
+ for (let i = 0; i < asArr.length; i++) {
343
+ if (asArr[i]) {
344
+ lines.push(this.createCSVLine(variant.id, 'en_GB', key, `_${Array.isArray(asArr[i]) ? asArr[i].map((v) => `_${v}`).join(' | ') : `_${asArr[i]}`}`, String(Array.isArray(asArr[i]) ? asArr[i].join(' | ') : value)));
345
+ }
346
+ }
343
347
  });
344
348
  }
345
349
  });
@@ -361,14 +365,13 @@ class FredHelperBase {
361
365
  if (!value) {
362
366
  continue;
363
367
  }
364
- const valueId = this.attributes.find(a => a.attribute_id === attributeId)?.type === 'list'
365
- || this.attributes.find(a => a.attribute_id === attributeId)?.type === 'set' || this.attributes.find(a => a.attribute_id === attributeId)?.type === 'set64' ?
366
- (Array.isArray(value) ? value.map(v => `_${v}`).join(' | ') : `_${value}`) : '';
367
- const valueStr = Array.isArray(value)
368
- ? value.join(' | ')
369
- : String(value);
370
- if (valueStr) {
371
- lines.push(this.createCSVLine(product.product_id, 'en_GB', attributeId, valueId, valueStr));
368
+ const isMultivalue = this.attributes.find(a => a.attribute_id === attributeId)?.type === 'list'
369
+ || this.attributes.find(a => a.attribute_id === attributeId)?.type === 'set' || this.attributes.find(a => a.attribute_id === attributeId)?.type === 'set64';
370
+ const asArr = Array.isArray(value) && isMultivalue ? value : [value];
371
+ for (let i = 0; i < asArr.length; i++) {
372
+ if (asArr[i]) {
373
+ lines.push(this.createCSVLine(product.product_id, 'en_GB', attributeId, `_${Array.isArray(asArr[i]) ? asArr[i].map((v) => `_${v}`).join(' | ') : `_${asArr[i]}`}`, String(Array.isArray(asArr[i]) ? asArr[i].join(' | ') : value)));
374
+ }
372
375
  }
373
376
  }
374
377
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.265",
3
+ "version": "0.0.267",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",