rerobe-js-orm 4.6.8 → 4.6.9
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.
- package/lib/models/Product.d.ts +1 -1
- package/lib/models/Product.js +15 -1
- package/package.json +1 -1
package/lib/models/Product.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export default class Product extends Base {
|
|
|
11
11
|
toObj(): CompleteProduct;
|
|
12
12
|
toProductInputObjForShopify(location?: string): any;
|
|
13
13
|
toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
|
|
14
|
-
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string): {
|
|
14
|
+
toProductInputObjForShopifyV3(locationId: string, weightUnit?: string, taxRate?: number): {
|
|
15
15
|
productOptions: {
|
|
16
16
|
name: string;
|
|
17
17
|
values: {
|
package/lib/models/Product.js
CHANGED
|
@@ -295,7 +295,7 @@ class Product extends Base_1.default {
|
|
|
295
295
|
}
|
|
296
296
|
return [productInputObj];
|
|
297
297
|
}
|
|
298
|
-
toProductInputObjForShopifyV3(locationId, weightUnit) {
|
|
298
|
+
toProductInputObjForShopifyV3(locationId, weightUnit, taxRate) {
|
|
299
299
|
var _a;
|
|
300
300
|
const title = this.attributes.title || `Ribbn Product ${this.attributes.handle || this.filterAttributes.documentId}`;
|
|
301
301
|
const inInventoryStatuses = [
|
|
@@ -324,6 +324,14 @@ class Product extends Base_1.default {
|
|
|
324
324
|
compareAtPrice: this.attributes.price || '0',
|
|
325
325
|
taxable: this.attributes.isTaxable === 'yes' ? true : false,
|
|
326
326
|
});
|
|
327
|
+
const applyTaxIfNeeded = (price, taxable) => {
|
|
328
|
+
const rate = typeof taxRate === 'number' && taxRate > 0 ? taxRate : 0;
|
|
329
|
+
const base = Number(price || 0);
|
|
330
|
+
if (!taxable || !rate)
|
|
331
|
+
return String(price !== null && price !== void 0 ? price : '0');
|
|
332
|
+
const adjusted = Number((base * (1 + rate)).toFixed(2));
|
|
333
|
+
return String(adjusted);
|
|
334
|
+
};
|
|
327
335
|
const passedTags = ((_a = this.filterAttributes.tags) === null || _a === void 0 ? void 0 : _a.length) ? this.filterAttributes.tags : [];
|
|
328
336
|
const tags = [
|
|
329
337
|
this.filterAttributes.documentId ? `ribbnId:${this.filterAttributes.documentId}` : null,
|
|
@@ -365,6 +373,9 @@ class Product extends Base_1.default {
|
|
|
365
373
|
variant.price = this.consignmentAttributes.salePrice;
|
|
366
374
|
variant.compareAtPrice = this.attributes.price || variant.compareAtPrice;
|
|
367
375
|
}
|
|
376
|
+
// Apply tax to price and compareAtPrice if taxable
|
|
377
|
+
variant.price = applyTaxIfNeeded(variant.price, Boolean(variant.taxable));
|
|
378
|
+
variant.compareAtPrice = applyTaxIfNeeded(variant.compareAtPrice, Boolean(variant.taxable));
|
|
368
379
|
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions: [{ name: 'Variant', values: [{ name: title }] }], descriptionHtml: this.attributes.description, vendor: this.filterAttributes.brand, tags,
|
|
369
380
|
files, variants: [variant] });
|
|
370
381
|
}
|
|
@@ -440,6 +451,9 @@ class Product extends Base_1.default {
|
|
|
440
451
|
variant.price = salePrice;
|
|
441
452
|
variant.compareAtPrice = basePrice;
|
|
442
453
|
}
|
|
454
|
+
// Apply tax to price and compareAtPrice if taxable
|
|
455
|
+
variant.price = applyTaxIfNeeded(variant.price, Boolean(variant.taxable));
|
|
456
|
+
variant.compareAtPrice = applyTaxIfNeeded(variant.compareAtPrice, Boolean(variant.taxable));
|
|
443
457
|
return variant;
|
|
444
458
|
});
|
|
445
459
|
return Object.assign(Object.assign({ title }, (statusToInclude ? { status: statusToInclude } : {})), { productOptions, descriptionHtml: this.attributes.description, vendor: this.filterAttributes.brand, tags,
|