rerobe-js-orm 4.5.5 → 4.5.6
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.
|
@@ -78,6 +78,11 @@ export default class ProductFormState extends FormState {
|
|
|
78
78
|
removeVariantByOptions(options: {
|
|
79
79
|
[k: string]: string;
|
|
80
80
|
}): void;
|
|
81
|
+
removeVariantById(id: string): void;
|
|
82
|
+
removeVariants(options?: {
|
|
83
|
+
ids?: string[];
|
|
84
|
+
predicate?: (v: VariantInventory) => boolean;
|
|
85
|
+
}): void;
|
|
81
86
|
findVariantByOptions(options: {
|
|
82
87
|
[k: string]: string;
|
|
83
88
|
}): VariantInventory | undefined;
|
|
@@ -811,6 +811,47 @@ class ProductFormState extends FormState_1.default {
|
|
|
811
811
|
this.aggregateInventoryLocationsFromVariants();
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
|
+
// Remove a single variant by id
|
|
815
|
+
removeVariantById(id) {
|
|
816
|
+
const rows = this.fields.variantInventory.selectedValues;
|
|
817
|
+
const ind = rows.findIndex((v) => v.id === id);
|
|
818
|
+
if (ind === -1)
|
|
819
|
+
return;
|
|
820
|
+
rows.splice(ind, 1);
|
|
821
|
+
// Recompute aggregates
|
|
822
|
+
const totalQty = rows.reduce((acc, cur) => {
|
|
823
|
+
const locs = cur.locations;
|
|
824
|
+
const sum = Array.isArray(locs) ? locs.reduce((a, l) => a + (Number(l === null || l === void 0 ? void 0 : l.availableAmount) || 0), 0) : 0;
|
|
825
|
+
return acc + sum;
|
|
826
|
+
}, 0);
|
|
827
|
+
this.fields.quantity.inputValue = totalQty;
|
|
828
|
+
this.fields.availableForSale.selectedValue = totalQty > 0;
|
|
829
|
+
this.aggregateInventoryLocationsFromVariants();
|
|
830
|
+
}
|
|
831
|
+
// Bulk remove variants by selector (ids and/or predicate)
|
|
832
|
+
removeVariants(options) {
|
|
833
|
+
const rows = this.fields.variantInventory.selectedValues || [];
|
|
834
|
+
if (!rows.length)
|
|
835
|
+
return;
|
|
836
|
+
const shouldRemove = (v) => {
|
|
837
|
+
if ((options === null || options === void 0 ? void 0 : options.ids) && options.ids.length && options.ids.includes(v.id))
|
|
838
|
+
return true;
|
|
839
|
+
if ((options === null || options === void 0 ? void 0 : options.predicate) && options.predicate(v))
|
|
840
|
+
return true;
|
|
841
|
+
return false;
|
|
842
|
+
};
|
|
843
|
+
const next = rows.filter((v) => !shouldRemove(v));
|
|
844
|
+
this.fields.variantInventory.selectedValues = next;
|
|
845
|
+
// Recompute aggregates
|
|
846
|
+
const totalQty = next.reduce((acc, cur) => {
|
|
847
|
+
const locs = cur.locations;
|
|
848
|
+
const sum = Array.isArray(locs) ? locs.reduce((a, l) => a + (Number(l === null || l === void 0 ? void 0 : l.availableAmount) || 0), 0) : 0;
|
|
849
|
+
return acc + sum;
|
|
850
|
+
}, 0);
|
|
851
|
+
this.fields.quantity.inputValue = totalQty;
|
|
852
|
+
this.fields.availableForSale.selectedValue = totalQty > 0;
|
|
853
|
+
this.aggregateInventoryLocationsFromVariants();
|
|
854
|
+
}
|
|
814
855
|
findVariantByOptions(options) {
|
|
815
856
|
return this.getExistingVariantByOptions(options);
|
|
816
857
|
}
|
package/lib/models/Product.js
CHANGED
|
@@ -335,7 +335,7 @@ class Product extends Base_1.default {
|
|
|
335
335
|
: [];
|
|
336
336
|
if (variantsFromInventory.length === 0) {
|
|
337
337
|
// Fallback: single-variant product (legacy behavior)
|
|
338
|
-
const variant = Object.assign(Object.assign({}, baseVariantFields()), { inventoryQuantities: [
|
|
338
|
+
const variant = Object.assign(Object.assign({ id: '' }, baseVariantFields()), { inventoryQuantities: [
|
|
339
339
|
{
|
|
340
340
|
locationId: `gid://shopify/Location/${locationId}`,
|
|
341
341
|
name: 'available',
|
|
@@ -404,7 +404,7 @@ class Product extends Base_1.default {
|
|
|
404
404
|
},
|
|
405
405
|
];
|
|
406
406
|
const basePrice = ((_b = (_a = v.price) !== null && _a !== void 0 ? _a : this.attributes.price) !== null && _b !== void 0 ? _b : '0');
|
|
407
|
-
const variant = Object.assign(Object.assign({}, baseVariantFields()), { optionValues,
|
|
407
|
+
const variant = Object.assign(Object.assign({ id: v.id }, baseVariantFields()), { optionValues,
|
|
408
408
|
inventoryQuantities });
|
|
409
409
|
// Override inventory policy if allowed to continue selling
|
|
410
410
|
if (v.continueSellingWhenOutOfStock === true) {
|