removeItemFromCart
Remove item from cart.
Signature
declare function removeItemFromCart(
context: Context,
input: RemoveItemFromCartInput,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<FetchResult<RemoveItemFromCartMutation>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
input | Required | RemoveItemFromCartInput | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- RemoveItemFromCartInput
- CustomQuery
- CustomHeaders
FetchResultRemoveItemFromCartMutation
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// Assumes that the cart has an item with the UID 'MY='.
// Configure method parameters
const params = { cart_id: TEST_CART_ID, cart_item_uid: 'MY=' }
const result = await sdk.magento.removeItemFromCart(params);
// result will contain the updated cart.
// you can look at the cart items to see that the item with the UID 'MY=' has been removed.
const hasItem = result.data?.removeItemFromCart!.cart!.items!.find(item => item!.uid === 'MY=');Creating a custom GraphQL query for manipulating the cart response data.
module.exports = {
integrations: {
magento: {
customQueries: {
'remove-item-from-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation removeItemFromCart($input: RemoveItemFromCartInput) {
removeItemFromCart(input: $input) {
cart {
${metadata.fields}
}
}
}`
}),
},
}
}
};Using a custom GraphQL query created in the previous example.
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
// this will reduce the amount of data transferred from the server to the client.
// All we need is the cart ID and the email address of the customer.
const customQuery = {
cart: 'remove-item-from-cart-custom-query',
metadata: {
fields: 'id email'
}
};
// Assumes that the cart has an item with the UID 'MY='.
// Uses params from the previous example and the custom query.
const result = await sdk.magento.removeItemFromCart(params, customQuery);
// result will contain only the fields specified in the custom query.