cartRemoveItem
نظرة عامة
استدعِ removeCartItem مع ID عنصر السطر المراد حذفه. تعكس الاستجابة بنية السلة حتى تتمكن من تحديث الإجماليات والقسائم وحالة واجهة المستخدم فوراً.
- النوع: GraphQL Mutation
- Endpoint: https://appssubdomain.com
- المصادقة:
Authorization: Bearer <TOKEN>(الجلسة/الحساب)
Mutation
mutation RemoveCartItem($data: RemoveCartItemInput!) {
removeCartItem(data: $data) {
data {
_id
app
account {
_id
verified
blocked
orderCount
lastSeen
createdAt
updatedAt
}
coupon
kind
couponApplied
couponDiscount
items {
_id
productId
variantId
productData { title slug app 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>"
}
}
أمثلة
- cURL
- JavaScript (fetch)
curl -X POST \
https://appssubdomain.com\
-H "Content-Type": "application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "mutation RemoveCartItem($data: RemoveCartItemInput!) { removeCartItem(data: $data) { success message data { _id totalPrice items { _id quantity } } } }",
"variables": {
"data": {
"itemId": "<CART_ITEM_ID>"
}
}
}
EOF
const res = await fetch('https://appssubdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
mutation RemoveCartItem($data: RemoveCartItemInput!) {
removeCartItem(data: $data) {
success
message
data { _id totalPrice totalQuantity }
}
}
`,
variables: {
data: { itemId: '<CART_ITEM_ID>' },
},
}),
});
const json = await res.json();
ملاحظات
- استخدم لقطة السلة المُعادة لتحديث واجهة المستخدم واكتشاف ما إذا تغيرت إجماليات القسيمة بعد الحذف.
- تحقق من أن
itemIdينتمي إلى الجلسة/الحساب الحالي قبل الاستدعاء، وإلا توقع خطأ فيmessage.