@labdigital/commercetools-mock 2.28.1 → 2.29.0
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/dist/index.cjs +61 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/product/actions.ts +88 -4
- package/src/services/product.test.ts +67 -0
package/dist/index.js
CHANGED
|
@@ -5103,6 +5103,67 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5103
5103
|
checkForStagedChanges(resource);
|
|
5104
5104
|
return resource;
|
|
5105
5105
|
}
|
|
5106
|
+
setProductPriceCustomField(context, resource, { name, value, staged, priceId }) {
|
|
5107
|
+
const updatePriceCustomFields = (data) => {
|
|
5108
|
+
const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
|
|
5109
|
+
if (!price) {
|
|
5110
|
+
throw new Error(
|
|
5111
|
+
`Price with id ${priceId} not found on product ${resource.id}`
|
|
5112
|
+
);
|
|
5113
|
+
}
|
|
5114
|
+
if (price.custom) {
|
|
5115
|
+
if (value === null) {
|
|
5116
|
+
delete price.custom.fields[name];
|
|
5117
|
+
} else {
|
|
5118
|
+
price.custom.fields[name] = value;
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
return data;
|
|
5122
|
+
};
|
|
5123
|
+
resource.masterData.staged = updatePriceCustomFields(
|
|
5124
|
+
resource.masterData.staged
|
|
5125
|
+
);
|
|
5126
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
5127
|
+
if (!onlyStaged) {
|
|
5128
|
+
resource.masterData.current = updatePriceCustomFields(
|
|
5129
|
+
resource.masterData.current
|
|
5130
|
+
);
|
|
5131
|
+
}
|
|
5132
|
+
checkForStagedChanges(resource);
|
|
5133
|
+
return resource;
|
|
5134
|
+
}
|
|
5135
|
+
setProductPriceCustomType(context, resource, { type, fields, staged, priceId }) {
|
|
5136
|
+
const updatePriceCustomType = (data) => {
|
|
5137
|
+
const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
|
|
5138
|
+
if (price) {
|
|
5139
|
+
if (type) {
|
|
5140
|
+
price.custom = createCustomFields(
|
|
5141
|
+
{ type, fields },
|
|
5142
|
+
context.projectKey,
|
|
5143
|
+
this._storage
|
|
5144
|
+
);
|
|
5145
|
+
} else {
|
|
5146
|
+
price.custom = void 0;
|
|
5147
|
+
}
|
|
5148
|
+
} else {
|
|
5149
|
+
throw new Error(
|
|
5150
|
+
`Price with id ${priceId} not found on product ${resource.id}`
|
|
5151
|
+
);
|
|
5152
|
+
}
|
|
5153
|
+
return data;
|
|
5154
|
+
};
|
|
5155
|
+
resource.masterData.staged = updatePriceCustomType(
|
|
5156
|
+
resource.masterData.staged
|
|
5157
|
+
);
|
|
5158
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
5159
|
+
if (!onlyStaged) {
|
|
5160
|
+
resource.masterData.current = updatePriceCustomType(
|
|
5161
|
+
resource.masterData.current
|
|
5162
|
+
);
|
|
5163
|
+
}
|
|
5164
|
+
checkForStagedChanges(resource);
|
|
5165
|
+
return resource;
|
|
5166
|
+
}
|
|
5106
5167
|
setTaxCategory(context, resource, { taxCategory }) {
|
|
5107
5168
|
let taxCategoryReference = void 0;
|
|
5108
5169
|
if (taxCategory) {
|
|
@@ -5150,8 +5211,6 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5150
5211
|
checkForStagedChanges(resource);
|
|
5151
5212
|
}
|
|
5152
5213
|
// 'setPrices': () => {},
|
|
5153
|
-
// 'setProductPriceCustomType': () => {},
|
|
5154
|
-
// 'setProductPriceCustomField': () => {},
|
|
5155
5214
|
// 'setDiscountedPrice': () => {},
|
|
5156
5215
|
// 'setAttributeInAllVariants': () => {},
|
|
5157
5216
|
// 'setCategoryOrderHint': () => {},
|