Skip to content

Commit 65b1454

Browse files
committed
Updated API from documentation release
1 parent b516eb4 commit 65b1454

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"anonymousCart": {
3+
"typeId": "cart",
4+
"id": "7c2e2694-aefe-43d7-888e-6a99514b4bea"
5+
},
6+
"mergeMode": "MergeWithExistingCustomerCart",
7+
"updateProductData": false
8+
}

api-specs/api/resources/carts.raml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ post:
104104
displayName: Check if Cart exists by Customer ID
105105
securedBy: [oauth_2_0: { scopes: ['view_orders:{projectKey}'] }]
106106
description: Checks if a Cart exists for a Customer. Returns a `200` status if the Cart exists, or a `404` status otherwise.
107+
/customer-id={customerId}/merge:
108+
type: base
109+
uriParameters:
110+
customerId:
111+
type: string
112+
description: '`customerId` of the Customer.'
113+
post:
114+
displayName: Merge Cart
115+
securedBy: [oauth_2_0: { scopes: ['manage_orders:{projectKey}'] }]
116+
description: |
117+
Merges items from an anonymous Cart into the most recently modified active Cart of a Customer. If no active Cart exists, a [ResourceNotFound](ctp:api:type:ResourceNotFoundError) error is returned.
118+
119+
For more information, see [Merge behavior](/../api/carts-orders-overview#merge-behavior).
120+
121+
body:
122+
application/json:
123+
type: MergeCartDraft
124+
example: !include ../examples/cart-merge.example.json
125+
responses:
126+
200:
127+
body:
128+
application/json:
129+
type: Cart
130+
example: !include ../examples/cart.example.json
107131
/key={key}:
108132
(methodName): withKey
109133
type:

api-specs/api/resources/in-store/carts-in-store.raml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@ post:
117117
},
118118
]
119119
description: Checks if one or more Carts exist for a Customer in a [Store](ctp:api:type:Store). Returns a `200` status if the Cart exists, or a `404` status otherwise.
120+
/customer-id={customerId}/merge:
121+
type: base
122+
uriParameters:
123+
customerId:
124+
type: string
125+
description: '`customerId` of the Customer.'
126+
post:
127+
displayName: Merge Cart in Store
128+
securedBy:
129+
[
130+
oauth_2_0:
131+
{
132+
scopes:
133+
[
134+
'manage_orders:{projectKey}',
135+
'manage_orders:{projectKey}:{storeKey}',
136+
],
137+
},
138+
]
139+
description: |
140+
Merges items from an anonymous Cart into the most recently modified active Cart of a Customer. If no active Cart exists, a [ResourceNotFound](ctp:api:type:ResourceNotFoundError) error is returned.
141+
142+
If the Cart exists in the Project but does not have a `store` specified, or the `store` field references a different Store, a [ResourceNotFound](ctp:api:type:ResourceNotFoundError) error is returned.
143+
144+
For more information, see [Merge behavior](/../api/carts-orders-overview#merge-behavior).
145+
146+
body:
147+
application/json:
148+
type: MergeCartDraft
149+
example: !include ../../examples/cart-merge.example.json
150+
responses:
151+
200:
152+
body:
153+
application/json:
154+
type: Cart
155+
example: !include ../../examples/cart.example.json
120156
/key={key}:
121157
(methodName): withKey
122158
type:

api-specs/api/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<option type="exclude">active-cart</option>
3434
<option type="exclude">health</option>
3535
<option type="exclude">product-tailoring</option>
36+
<option type="exclude">merge</option>
3637
</options>
3738
</rule>
3839
<rule>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#%RAML 1.0 DataType
2+
(package): Cart
3+
displayName: CartMergeMode
4+
type: string
5+
description: |
6+
Determines how to manually merge an anonymous Cart with an existing Customer Cart.
7+
enum:
8+
- MergeWithExistingCustomerCart
9+
- UseAsNewActiveCustomerCart
10+
(enumDescriptions):
11+
MergeWithExistingCustomerCart: |
12+
Merges the anonymous Cart with the existing Customer Cart. Line Items from the anonymous Cart are added to the Customer Cart.
13+
UseAsNewActiveCustomerCart: |
14+
Uses the anonymous Cart as the new active Customer Cart, replacing the existing one.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#%RAML 1.0 DataType
2+
(package): Cart
3+
displayName: MergeCartDraft
4+
type: object
5+
description: |
6+
Used for merging an anonymous Cart with a Customer Cart with the [Merge Cart](ctp:api:endpoint:/{projectKey}/carts/customer-id={customerId}/merge:POST) and [Merge Cart in Store](ctp:api:endpoint:/{projectKey}/in-store/key={storeKey}/carts/customer-id={customerId}/merge:POST) endpoints. Either `anonymousCart` or `anonymousId` is required.
7+
properties:
8+
anonymousCart?:
9+
type: CartResourceIdentifier
10+
description: |
11+
[ResourceIdentifier](ctp:api:type:ResourceIdentifier) to the anonymous [Cart](ctp:api:type:Cart) to be merged. Required if `anonymousId` is not provided.
12+
mergeMode?:
13+
type: CartMergeMode
14+
description: |
15+
Determines how to merge the anonymous Cart with the existing Customer Cart.
16+
default: MergeWithExistingCustomerCart
17+
updateProductData?:
18+
type: boolean
19+
description: |
20+
- If `true`, the [LineItem](ctp:api:type:LineItem) Product data (`name`, `variant`, and `productType`) of the returned Cart will be updated.
21+
- If `false`, only the prices, discounts, and tax rates will be updated.
22+
default: false
23+
anonymousId?:
24+
type: string
25+
description: |
26+
Assigns the Customer to the [Carts](ctp:api:type:Cart) that have the same `anonymousId`. Required if `anonymousCart` is not provided.
27+
If both `anonymousCart` and `anonymousId` are provided, this value must match the `anonymousId` of the anonymous [Cart](ctp:api:type:Cart) otherwise, an [InvalidOperation](ctp:api:type:InvalidOperationError) error is returned.

api-specs/api/types/types.raml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ CartDiscountSetValidUntilAction: !include cart-discount/updates/CartDiscountSetV
186186
BestDeal: !include cart/BestDeal.raml
187187
Cart: !include cart/Cart.raml
188188
CartDraft: !include cart/CartDraft.raml
189+
CartMergeMode: !include cart/CartMergeMode.raml
189190
CartOrigin: !include cart/CartOrigin.raml
190191
CartPagedQueryResponse: !include cart/CartPagedQueryResponse.raml
191192
CartReference: !include cart/CartReference.raml
@@ -222,6 +223,7 @@ LineItem: !include cart/LineItem.raml
222223
LineItemDraft: !include cart/LineItemDraft.raml
223224
LineItemMode: !include cart/LineItemMode.raml
224225
LineItemPriceMode: !include cart/LineItemPriceMode.raml
226+
MergeCartDraft: !include cart/MergeCartDraft.raml
225227
MethodExternalTaxRateDraft: !include cart/MethodExternalTaxRateDraft.raml
226228
MethodTaxRate: !include cart/MethodTaxRate.raml
227229
MethodTaxedPrice: !include cart/MethodTaxedPrice.raml

api-specs/graphql/schema.sdl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,22 @@ type CartLimitsProjection {
20572057
total: CartLimitWithCurrent!
20582058
}
20592059

2060+
enum CartMergeMode {
2061+
"""
2062+
`LineItem`s of the anonymous cart will be copied to the customer’s active cart that has been modified most recently.
2063+
2064+
The `CartState` of the anonymous cart gets changed to `Merged` while the `CartState` of the customer’s cart remains `Active`.
2065+
2066+
`CustomLineItems` and `CustomFields` of the anonymous cart will not be copied to the customers cart.
2067+
2068+
If a `LineItem` in the anonymous cart matches an existing line item in the customer’s cart (same product ID and variant ID), the maximum quantity of both LineItems is used as the new quantity. In that case `CustomFields` on the `LineItem` of the anonymous cart will not be in the resulting `LineItem`.
2069+
"""
2070+
MergeWithExistingCustomerCart
2071+
2072+
"The anonymous cart is used as new active customer cart. No `LineItem`s get merged."
2073+
UseAsNewActiveCustomerCart
2074+
}
2075+
20602076
enum CartOrigin {
20612077
"The cart was created by the customer. This is the default value"
20622078
Customer
@@ -5825,6 +5841,13 @@ interface MeQueryInterface implements CartQueryInterface & ActiveCartInterface &
58255841
shoppingLists(where: String, sort: [String!], limit: Int, offset: Int): ShoppingListQueryResult!
58265842
}
58275843

5844+
input MergeCartDraft {
5845+
anonymousCart: ResourceIdentifierInput
5846+
mergeMode: CartMergeMode = MergeWithExistingCustomerCart
5847+
anonymousId: String
5848+
updateProductData: Boolean = false
5849+
}
5850+
58285851
type Message implements Versioned & ReferenceExpandable {
58295852
id: String!
58305853
type: String!
@@ -6442,6 +6465,11 @@ type Mutation {
64426465
"Create/modify entity as an associate in business-unit."
64436466
asAssociate: AsAssociateArgument): Cart
64446467

6468+
mergeCart(customerId: String!, draft: MergeCartDraft!,
6469+
6470+
"The mutation is only performed if the resource is part of the store. Can be used with store-specific OAuth permissions."
6471+
storeKey: KeyReferenceInput): Cart
6472+
64456473
"BETA: This feature can be subject to change and should be used carefully in production. https://docs.commercetools.com/api/contract#public-beta"
64466474
createMyCart(draft: MyCartDraft!,
64476475

0 commit comments

Comments
 (0)