setGiftOptionsOnCart mutation
The setGiftOptionsOnCart
mutation allows the buyer to set the following gift options on the cart level:
- Gift messages
- Gift wrapping
- A gift receipt to accompany the order
- A printed card to accompany the order
Gift messages are a feature of Magento Open Source. All other gift options require Magento Commerce.
To remove a gift message, set the gift_message
object to null. To remove gift wrapping, set the gift_wrapping_id
attribute to null.
Use the updateCartItems mutation to set gift messages and gift wrapping on individual items.
These options are configured on the Stores > Configuration > Sales > Sales > Gift Options screen. To determine whether these options are enabled, specify these attributes in the storeConfig
query.
allow_gift_receipt
allow_gift_wrapping_on_order
allow_printed_card
cart_gift_wrapping
cart_printed_card
printed_card_price
sales_gift_wrapping
sales_printed_card
Gift wrapping is available for simple, configurable, bundle products as well as physical gift cards.
Syntax
mutation: {setGiftOptionsOnCart(input: SetGiftOptionsOnCartInput): SetGiftOptionsOnCartOutput}
Example usage
The following example adds a gift message, gift wrapping, and a gift receipt to the cart.
Request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
mutation {
setGiftOptionsOnCart(
input: {
cart_id: "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz"
gift_message: {
to: "Alex"
from: "Veronica"
message: "Happy Birthday!"
}
gift_wrapping_id: "Mg=="
gift_receipt_included: true
printed_card_included: false
}
) {
cart {
id
gift_message {
to
from
message
}
gift_wrapping {
id
}
gift_receipt_included
printed_card_included
items {
quantity
prices {
price {
value
currency
}
}
}
prices {
gift_options {
gift_wrapping_for_order {
value
currency
}
}
grand_total {
value
currency
}
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
"data": {
"setGiftOptionsOnCart": {
"cart": {
"id": "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz",
"gift_message": {
"to": "Alex"
"from": "Veronica"
"message": "Happy Birthday!"
}
"gift_wrapping": {
"id": "2"
},
"gift_receipt_included": true,
"printed_card_included": false,
"items": [
{
"quantity": 1,
"prices": {
"price": {
"value": 32,
"currency": "USD"
}
}
},
{
"quantity": 1,
"prices": {
"price": {
"value": 84,
"currency": "USD"
}
}
}
],
"prices": {
"gift_options": {
"gift_wrapping_for_order": {
"value": 7,
"currency": "USD"
}
},
"grand_total": {
"value": 132.57,
"currency": "USD"
}
}
}
}
}
}
Input attributes
The SetGiftOptionsOnCartInput
object can contain the following attributes:
Attribute | Data Type | Description |
---|---|---|
cart_id |
String! | The unique ID that identifies the shopper’s cart |
gift_message |
GiftMessageInput | Gift message details for the cart |
gift_receipt_included |
Boolean! | Indicates whether the customer requested a gift receipt for the cart |
gift_wrapping_id |
ID | The unique identifier of the gift wrapping to be used for the cart |
printed_card_included |
Boolean! | Indicates whether the customer requested a printed card for the cart |
GiftMessageInput
The GiftMessageInput
object must contain the following attributes:
Attribute | Data Type | Description |
---|---|---|
from |
String! | The name of the gift sender |
message |
String! | The text of the gift message |
to |
String! | The name of the gift recipient |
Output attributes
The SetGiftOptionsOnCartOutput
object contains the 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 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 |
---|---|
Could not find a cart with ID "XXX" |
The specified cart_id value does not exist in the quote_id_mask table. |
Field SetBillingAddressOnCartInput.cart_id of required type String! was not provided. |
The value specified in the SetShippingAddressesOnCartInput .cart_id argument is empty. |
Field CartAddressInput.firstname of required type String! was not provided. |
The value specified in the shipping_addresses .firstname argument is empty. |
Field CartAddressInput.lastname of required type String! was not provided. |
The value specified in the shipping_addresses .lastname argument is empty. |
Field CartAddressInput.city of required type String! was not provided. |
The value specified in the shipping_addresses .city argument is empty. |
Field CartAddressInput.street of required type String! was not provided. |
The value specified in the shipping_addresses .street argument is empty. |
Field CartAddressInput.country_code of required type String! was not provided. |
The value specified in the shipping_addresses .country_code argument is empty. |
Field SetBillingAddressOnCartInput.billing_address of required type BillingAddressInput! was not provided. |
The shipping_addresses input attribute of type ShippingAddressInput is missing. |