@labdigital/commercetools-mock 2.48.1 → 2.49.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 +22 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart/actions.ts +39 -0
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
CartChangeTaxRoundingModeAction,
|
|
18
18
|
CartRemoveDiscountCodeAction,
|
|
19
19
|
CartRemoveLineItemAction,
|
|
20
|
+
CartRemoveShippingMethodAction,
|
|
20
21
|
CartSetBillingAddressAction,
|
|
21
22
|
CartSetBillingAddressCustomTypeAction,
|
|
22
23
|
CartSetCountryAction,
|
|
@@ -28,6 +29,7 @@ import type {
|
|
|
28
29
|
CartSetLineItemShippingDetailsAction,
|
|
29
30
|
CartSetLocaleAction,
|
|
30
31
|
CartSetShippingAddressAction,
|
|
32
|
+
CartSetShippingAddressCustomFieldAction,
|
|
31
33
|
CartSetShippingAddressCustomTypeAction,
|
|
32
34
|
CartSetShippingMethodAction,
|
|
33
35
|
CustomFields,
|
|
@@ -43,6 +45,7 @@ import type {
|
|
|
43
45
|
TaxPortion,
|
|
44
46
|
TaxedItemPrice,
|
|
45
47
|
} from "@commercetools/platform-sdk/dist/declarations/src/generated/models/cart";
|
|
48
|
+
import type { ShippingMethodResourceIdentifier } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/shipping-method";
|
|
46
49
|
import { Decimal } from "decimal.js/decimal";
|
|
47
50
|
import { v4 as uuidv4 } from "uuid";
|
|
48
51
|
import { CommercetoolsError } from "~src/exceptions";
|
|
@@ -402,6 +405,7 @@ export class CartUpdateHandler
|
|
|
402
405
|
if (!resource.custom) {
|
|
403
406
|
throw new Error("Resource has no custom field");
|
|
404
407
|
}
|
|
408
|
+
|
|
405
409
|
resource.custom.fields[name] = value;
|
|
406
410
|
}
|
|
407
411
|
|
|
@@ -751,4 +755,39 @@ export class CartUpdateHandler
|
|
|
751
755
|
resource.shippingInfo = undefined;
|
|
752
756
|
}
|
|
753
757
|
}
|
|
758
|
+
|
|
759
|
+
setShippingAddressCustomField(
|
|
760
|
+
context: RepositoryContext,
|
|
761
|
+
resource: Writable<Cart>,
|
|
762
|
+
{ name, value }: CartSetShippingAddressCustomFieldAction,
|
|
763
|
+
) {
|
|
764
|
+
if (!resource.shippingAddress) {
|
|
765
|
+
throw new Error("Resource has no shipping address");
|
|
766
|
+
}
|
|
767
|
+
if (!resource.shippingAddress.custom) {
|
|
768
|
+
throw new Error("Resource has no custom field");
|
|
769
|
+
}
|
|
770
|
+
resource.shippingAddress.custom.fields[name] = value;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
removeShippingMethod(
|
|
774
|
+
context: RepositoryContext,
|
|
775
|
+
resource: Writable<Cart>,
|
|
776
|
+
{ shippingKey }: CartRemoveShippingMethodAction,
|
|
777
|
+
) {
|
|
778
|
+
if (!resource.shippingInfo) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const shippingMethod =
|
|
782
|
+
this._storage.getByResourceIdentifier<"shipping-method">(
|
|
783
|
+
context.projectKey,
|
|
784
|
+
{ key: shippingKey } as ShippingMethodResourceIdentifier,
|
|
785
|
+
);
|
|
786
|
+
|
|
787
|
+
if (resource.shippingInfo?.shippingMethod?.id !== shippingMethod.id) {
|
|
788
|
+
throw new Error("Shipping method with key not found");
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
resource.shippingInfo = undefined;
|
|
792
|
+
}
|
|
754
793
|
}
|