rerobe-js-orm 4.9.2 → 4.9.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.
@@ -35,6 +35,15 @@ export default class Product extends Base {
35
35
  }): {
36
36
  [k: string]: any;
37
37
  };
38
+ buildQuantityCloneData({ price, imageUrls, overrides, }?: {
39
+ price?: string | number;
40
+ imageUrls?: string[];
41
+ overrides?: {
42
+ [k: string]: any;
43
+ };
44
+ }): {
45
+ [k: string]: any;
46
+ };
38
47
  diagnoseVariantInventory(): 'no_variants' | 'all_zero_qty' | 'ok';
39
48
  toProductInputObjForShopify(location?: string): any;
40
49
  toProductInputObjForShopifyV2(locationId: string, weightUnit?: string): any[];
@@ -281,7 +281,39 @@ class Product extends Base_1.default {
281
281
  const systemTags = Array.isArray(parent.systemTags)
282
282
  ? parent.systemTags.filter((tag) => tag !== 'templateProduct')
283
283
  : [];
284
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, parent), { productClass: product_constants_1.PRODUCT_CLASS_VALUES.UNIQUE, variantInventory: [], status: product_constants_1.PRODUCT_STATES.hidden, systemTags: [...new Set([...systemTags, 'clonedProduct', 'variantClone'])], price: String(resolvedPrice), imageUrls: resolvedImageUrls, sku: resolvedSku }), ProductVariantHelpers_1.default.mapOptionsToAttributes(variantOptions)), { variantOptions, originalVariantProductId: parent.documentId || '', chosenVariantId: (chosenVariant && chosenVariant.id) || chosenVariantId || '', chosenVariantSku: resolvedSku, bookedTimestamp: null, openTimestamp: null }), overrides);
284
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, parent), { productClass: product_constants_1.PRODUCT_CLASS_VALUES.UNIQUE, variantInventory: [], status: product_constants_1.PRODUCT_STATES.hidden, systemTags: [...new Set([...systemTags, 'clonedProduct', 'variantClone'])], price: String(resolvedPrice), imageUrls: resolvedImageUrls, sku: resolvedSku }), ProductVariantHelpers_1.default.mapOptionsToAttributes(variantOptions)), { variantOptions, originalVariantProductId: parent.documentId || '', chosenVariantId: (chosenVariant && chosenVariant.id) || chosenVariantId || '', chosenVariantSku: resolvedSku,
285
+ // The clone is a brand-new unit "born now": null out the parent's
286
+ // lifecycle timestamps so the persistence layer stamps fresh createdAt(s).
287
+ // Critical for createdAtTimestamp — the abandoned-clone reaper deletes by
288
+ // age, so inheriting the parent's (old) timestamp would reap the clone
289
+ // immediately, mid-checkout.
290
+ createdAt: null, createdAtTimestamp: null, bookedTimestamp: null, openTimestamp: null }), overrides);
291
+ }
292
+ // Build the data for ONE concrete, single-unit clone of a multi-quantity
293
+ // product that has NO variant axes — tracked retail, SUPPLY, and
294
+ // always-in-stock ("non-clothing") items. The sibling of
295
+ // buildVariantCloneData: same UNIQUE, hidden-until-sold, born-now sold-unit
296
+ // shape, but carries no variant options. Back-linked to the stock-holding
297
+ // parent (via originalVariantProductId) so the parent's inventoryLocations are
298
+ // decremented at sale time while the parent itself stays LISTED. Tagged
299
+ // `quantityClone` so the sold/inventory pipeline routes it to the parent's
300
+ // inventoryLocations (not variantInventory).
301
+ //
302
+ // Pure: returns the clone's data object. The caller assigns a documentId and
303
+ // persists it (N copies for quantity > 1).
304
+ buildQuantityCloneData({ price = '', imageUrls = [], overrides = {}, } = {}) {
305
+ const parent = this.toObj();
306
+ const resolvedPrice = price || parent.price || '0';
307
+ const resolvedImageUrls = Array.isArray(imageUrls) && imageUrls.length ? imageUrls : parent.imageUrls || [];
308
+ const systemTags = Array.isArray(parent.systemTags)
309
+ ? parent.systemTags.filter((tag) => tag !== 'templateProduct')
310
+ : [];
311
+ return Object.assign(Object.assign(Object.assign({}, parent), { productClass: product_constants_1.PRODUCT_CLASS_VALUES.UNIQUE, variantInventory: [], status: product_constants_1.PRODUCT_STATES.hidden, systemTags: [...new Set([...systemTags, 'clonedProduct', 'quantityClone'])], price: String(resolvedPrice), imageUrls: resolvedImageUrls,
312
+ // Back-link to the stock-holding parent (decremented on sale). No variant.
313
+ originalVariantProductId: parent.documentId || '', chosenVariantId: '', chosenVariantSku: parent.sku || '',
314
+ // Born now (see buildVariantCloneData) so the reaper measures the clone's
315
+ // age, not the parent's.
316
+ createdAt: null, createdAtTimestamp: null, bookedTimestamp: null, openTimestamp: null }), overrides);
285
317
  }
286
318
  // Diagnose whether a variant-inventory product is purchasable. Mirrors
287
319
  // the readiness gate the retail entry exposes as a confirm-before-save
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.9.2",
3
+ "version": "4.9.4",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",