@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 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': () => {},