assignCustomerToGuestCart mutation
The assignCustomerToGuestCart
mutation merges a logged-in customer’s shopping cart into the specified guest cart. The mutation inactivates the customer’s shopping cart and moves the products to the guest cart. The guest cart is then assigned to the customer.
The masked_id
of the guest cart contains a new value. The quote_id
remains the same.
This mutation requires a valid customer authentication token.
Use the mergeCarts mutation to transfer the contents of a guest cart into a customer’s cart.
Syntax
1
2
3
4
5
6
7
mutation {
assignCustomerToGuestCart(
cart_id: String!
) {
Cart!
}
}
Example usage
In the following example, the customer and guest carts each contain one item. The mutation merges the customer’s cart to the guest cart. As a result, the guest cart contains two items.
Request:
1
2
3
4
5
6
7
8
9
10
11
12
mutation {
assignCustomerToGuestCart(
cart_id: "MDYKgqIdWMKr7VD1zlYwxrB7kuX8lR5s"
) {
items {
quantity
product {
sku
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"data": {
"assignCustomerToGuestCart": {
"items": [
{
"quantity": 1,
"product": {
"sku": "customer_item"
}
},
{
"quantity": 1,
"product": {
"sku": "guest_item"
}
}
]
}
}
}
Input attributes
Attribute | Data Type | Description |
---|---|---|
cart_id |
String! | The unique ID that identifies the guest’s cart |
Output attributes
The assignCustomerToGuestCart
mutation returns a Cart
object.
Attribute | Data Type | Description |
---|---|---|
cart |
Cart! | Describes the contents of the specified shopping cart |
Cart object
Attribute | Data Type | Description |
---|---|---|
applied_coupon |
AppliedCoupon |
Deprecated. Use applied_coupons instead |
applied_coupons |
[AppliedCoupon ] |
An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code |
applied_gift_cards |
[AppliedGiftCard ] |
An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module |
applied_reward_points |
RewardPointsAmount |
The amount of reward points applied to the cart |
applied_store_credit |
AppliedStoreCredit |
Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module |
available_gift_wrappings |
[GiftWrapping]! | The list of available gift wrapping options for the cart |
available_payment_methods |
[AvailablePaymentMethod] | Available payment methods |
billing_address |
BillingCartAddress | Contains the billing address specified in the customer’s cart |
email |
String | The customer’s email address |
gift_message |
GiftMessage | A gift message added to the cart |
gift_receipt_included |
Boolean! | Indicates if the customer requested a gift receipt for the cart |
gift_wrapping |
GiftWrapping | The selected gift wrapping for the cart |
id |
ID! | The unique ID of the cart |
is_virtual |
Boolean! | Indicates whether the cart contains only virtual products |
items |
[CartItemInterface] | Contains the items in the customer’s cart |
prices |
CartPrices | Contains subtotals and totals |
printed_card_included |
Boolean! | Indicates if the customer requested a printed card for the cart |
selected_payment_method |
SelectedPaymentMethod | Selected payment method |
shipping_addresses |
[ShippingCartAddress]! | Contains one or more shipping addresses |
total_quantity |
Float! | Total Quantity of products in the cart |
Cart query output provides more information about the Cart
object.
Errors
Error | Description |
---|---|
The current customer isn't authorized. |
The current customer is not currently logged in. |
Unable to assign the customer to the guest cart |
The current customer can’t be assigned to the provided guest cart. |
The cart isn't active |
The cart with the specified cart ID is unavailable, because the items have been purchased and the cart ID becomes inactive. |
Could not find a cart with ID "XXX" |
The specified cart_id value does not exist in the quote_id_mask table. |
The current user cannot perform operations on cart "XXX" |
Tried to assign the customer to the customer’s cart. |