@labdigital/commercetools-mock 2.28.1 → 2.29.1
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 +81 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +81 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/product/actions.ts +88 -4
- package/src/repositories/project.ts +34 -0
- package/src/services/product.test.ts +67 -0
package/dist/index.cjs
CHANGED
|
@@ -5140,6 +5140,67 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5140
5140
|
checkForStagedChanges(resource);
|
|
5141
5141
|
return resource;
|
|
5142
5142
|
}
|
|
5143
|
+
setProductPriceCustomField(context, resource, { name, value, staged, priceId }) {
|
|
5144
|
+
const updatePriceCustomFields = (data) => {
|
|
5145
|
+
const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
|
|
5146
|
+
if (!price) {
|
|
5147
|
+
throw new Error(
|
|
5148
|
+
`Price with id ${priceId} not found on product ${resource.id}`
|
|
5149
|
+
);
|
|
5150
|
+
}
|
|
5151
|
+
if (price.custom) {
|
|
5152
|
+
if (value === null) {
|
|
5153
|
+
delete price.custom.fields[name];
|
|
5154
|
+
} else {
|
|
5155
|
+
price.custom.fields[name] = value;
|
|
5156
|
+
}
|
|
5157
|
+
}
|
|
5158
|
+
return data;
|
|
5159
|
+
};
|
|
5160
|
+
resource.masterData.staged = updatePriceCustomFields(
|
|
5161
|
+
resource.masterData.staged
|
|
5162
|
+
);
|
|
5163
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
5164
|
+
if (!onlyStaged) {
|
|
5165
|
+
resource.masterData.current = updatePriceCustomFields(
|
|
5166
|
+
resource.masterData.current
|
|
5167
|
+
);
|
|
5168
|
+
}
|
|
5169
|
+
checkForStagedChanges(resource);
|
|
5170
|
+
return resource;
|
|
5171
|
+
}
|
|
5172
|
+
setProductPriceCustomType(context, resource, { type, fields, staged, priceId }) {
|
|
5173
|
+
const updatePriceCustomType = (data) => {
|
|
5174
|
+
const price = [data.masterVariant, ...data.variants ?? []].flatMap((variant) => variant.prices ?? []).find((price2) => price2.id === priceId);
|
|
5175
|
+
if (price) {
|
|
5176
|
+
if (type) {
|
|
5177
|
+
price.custom = createCustomFields(
|
|
5178
|
+
{ type, fields },
|
|
5179
|
+
context.projectKey,
|
|
5180
|
+
this._storage
|
|
5181
|
+
);
|
|
5182
|
+
} else {
|
|
5183
|
+
price.custom = void 0;
|
|
5184
|
+
}
|
|
5185
|
+
} else {
|
|
5186
|
+
throw new Error(
|
|
5187
|
+
`Price with id ${priceId} not found on product ${resource.id}`
|
|
5188
|
+
);
|
|
5189
|
+
}
|
|
5190
|
+
return data;
|
|
5191
|
+
};
|
|
5192
|
+
resource.masterData.staged = updatePriceCustomType(
|
|
5193
|
+
resource.masterData.staged
|
|
5194
|
+
);
|
|
5195
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
5196
|
+
if (!onlyStaged) {
|
|
5197
|
+
resource.masterData.current = updatePriceCustomType(
|
|
5198
|
+
resource.masterData.current
|
|
5199
|
+
);
|
|
5200
|
+
}
|
|
5201
|
+
checkForStagedChanges(resource);
|
|
5202
|
+
return resource;
|
|
5203
|
+
}
|
|
5143
5204
|
setTaxCategory(context, resource, { taxCategory }) {
|
|
5144
5205
|
let taxCategoryReference = void 0;
|
|
5145
5206
|
if (taxCategory) {
|
|
@@ -5187,8 +5248,6 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5187
5248
|
checkForStagedChanges(resource);
|
|
5188
5249
|
}
|
|
5189
5250
|
// 'setPrices': () => {},
|
|
5190
|
-
// 'setProductPriceCustomType': () => {},
|
|
5191
|
-
// 'setProductPriceCustomField': () => {},
|
|
5192
5251
|
// 'setDiscountedPrice': () => {},
|
|
5193
5252
|
// 'setAttributeInAllVariants': () => {},
|
|
5194
5253
|
// 'setCategoryOrderHint': () => {},
|
|
@@ -6137,6 +6196,14 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6137
6196
|
resource.messages.enabled = messagesConfiguration.enabled;
|
|
6138
6197
|
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
6139
6198
|
}
|
|
6199
|
+
changeMyBusinessUnitStatusOnCreation(context, resource, { status }) {
|
|
6200
|
+
if (resource.businessUnits === void 0) {
|
|
6201
|
+
resource.businessUnits = {
|
|
6202
|
+
myBusinessUnitStatusOnCreation: "Inactive"
|
|
6203
|
+
};
|
|
6204
|
+
}
|
|
6205
|
+
resource.businessUnits.myBusinessUnitStatusOnCreation = status;
|
|
6206
|
+
}
|
|
6140
6207
|
changeName(context, resource, { name }) {
|
|
6141
6208
|
resource.name = name;
|
|
6142
6209
|
}
|
|
@@ -6157,6 +6224,18 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6157
6224
|
setExternalOAuth(context, resource, { externalOAuth }) {
|
|
6158
6225
|
resource.externalOAuth = externalOAuth;
|
|
6159
6226
|
}
|
|
6227
|
+
setMyBusinessUnitAssociateRoleOnCreation(context, resource, { associateRole }) {
|
|
6228
|
+
if (resource.businessUnits === void 0) {
|
|
6229
|
+
resource.businessUnits = {
|
|
6230
|
+
//Default status, so we set it here also
|
|
6231
|
+
myBusinessUnitStatusOnCreation: "Inactive"
|
|
6232
|
+
};
|
|
6233
|
+
}
|
|
6234
|
+
resource.businessUnits.myBusinessUnitAssociateRoleOnCreation = {
|
|
6235
|
+
typeId: associateRole.typeId,
|
|
6236
|
+
key: associateRole.key ?? "unknown"
|
|
6237
|
+
};
|
|
6238
|
+
}
|
|
6160
6239
|
setShippingRateInputType(context, resource, { shippingRateInputType }) {
|
|
6161
6240
|
resource.shippingRateInputType = shippingRateInputType;
|
|
6162
6241
|
}
|