cartUpdateItem
نظرة عامة
استخدم updateCartItem لتغيير كمية عنصر سطر معين في السلة. يعيد حساب API الإجماليات والقسائم والتوفيرات، ويعيد حالة السلة الجديدة.
- النوع: GraphQL Mutation
- Endpoint: https://appssubdomain.com
- المصادقة:
Authorization: Bearer <TOKEN>(الجلسة/الحساب)
Mutation
mutation UpdateCartItem($data: updateCartItemInput!) {
updateCartItem(data: $data) {
data {
_id
app
account {
_id
app
verified
blocked
orderCount
lastSeen
createdAt
updatedAt
}
coupon
kind
couponApplied
couponDiscount
items {
productId
_id
variantId
productData {
title
slug
image { _id fileUrl }
price
}
variantData {
price
compareAtPrice
options {
_id
option { _id name type product }
label
sortOrder
}
}
quantity
price
compareAtPrice
totalPrice
totalCompareAtPrice
totalSavings
}
deviceId
sessionId
status
totalQuantity
totalPrice
totalCompareAtPrice
totalSavings
isFastOrder
createdAt
updatedAt
url
encryptionKey
}
success
message
}
}
المتغيرات
{
"data": {
"itemId": "<CART_ITEM_ID>",
"quantity": 3
}
}
أمثلة
- cURL
- JavaScript (fetch)
curl -X POST \
https://appssubdomain.com\
-H "Content-Type": "application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "mutation UpdateCartItem($data: updateCartItemInput!) { updateCartItem(data: $data) { success message data { _id totalPrice totalQuantity } } }",
"variables": {
"data": {
"itemId": "<CART_ITEM_ID>",
"quantity": 3
}
}
}
EOF
const res = await fetch('https://appssubdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
mutation UpdateCartItem($data: updateCartItemInput!) {
updateCartItem(data: $data) {
success
message
data { _id totalPrice totalQuantity }
}
}
`,
variables: {
data: { itemId: '<CART_ITEM_ID>', quantity: 3 },
},
}),
});
const json = await res.json();
ملاحظات
- عادة ما يفرض الـ backend حدود الحد الأدنى/الأقصى؛ افحص
messageإذا فشل التحديث. - استخدمه جنباً إلى جنب مع
removeCartItemوaddToCartلبناء تدفقات إدارة السلة الكاملة.