rerobe-js-orm 3.0.2 → 3.0.4

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.
@@ -9,6 +9,7 @@ export default class Product extends Base {
9
9
  toPartialObj(): ShopifyProduct;
10
10
  toObj(): CompleteProduct;
11
11
  toProductInputObjForShopify(location?: string): any;
12
+ toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
12
13
  toObjForTextTranslation(): TranslatableAttributes;
13
14
  toObjForTypesense(): TypesenseProductObj;
14
15
  updateSelfFromTranslatedTextArray(translatedTextArray?: string[]): void;
@@ -220,6 +220,50 @@ class Product extends Base_1.default {
220
220
  }
221
221
  return productInputObj;
222
222
  }
223
+ toProductInputObjForShopifyV2(locationId, weightUnit) {
224
+ const shopifyId = this.attributes.shopifyId;
225
+ const passedTags = this.filterAttributes.tags && Array.isArray(this.filterAttributes.tags) ? this.filterAttributes.tags : [];
226
+ const productInputObj = {
227
+ title: this.attributes.title,
228
+ descriptionHtml: this.attributes.description,
229
+ productType: this.filterAttributes.productType,
230
+ vendor: this.attributes.vendorId,
231
+ tags: [
232
+ this.filterAttributes.documentId ? `ribbnId:${this.filterAttributes.documentId}` : null,
233
+ ...passedTags,
234
+ ].filter((t) => t),
235
+ variants: [
236
+ {
237
+ inventoryPolicy: 'DENY',
238
+ inventoryQuantities: [
239
+ {
240
+ availableQuantity: this.attributes.availableForSale ? 1 : 0,
241
+ locationId: `${locationId}`,
242
+ },
243
+ ],
244
+ price: this.attributes.price || '0',
245
+ taxable: false,
246
+ weight: parseFloat(this.attributes.weight) || parseFloat('999'),
247
+ weightUnit: weightUnit || 'GRAMS',
248
+ },
249
+ ],
250
+ };
251
+ if (shopifyId) {
252
+ // Todo: use getDecodedShopifyId here
253
+ productInputObj.id = shopifyId;
254
+ productInputObj.variants = [
255
+ Object.assign({}, productInputObj.variants[0]),
256
+ ];
257
+ }
258
+ if (this.attributes.imageUrls) {
259
+ const projectMediaObj = this.attributes.imageUrls.map((image) => ({
260
+ mediaContentType: 'IMAGE',
261
+ originalSource: image,
262
+ }));
263
+ return [productInputObj, projectMediaObj];
264
+ }
265
+ return [productInputObj];
266
+ }
223
267
  toObjForTextTranslation() {
224
268
  return {
225
269
  description: this.attributes.description || this.FIELD_NOT_TRANSLATABLE_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",