انتقل إلى المحتوى الرئيسي

cartApplyCode

نظرة عامة

طبّق كود قسيمة/ترويجي على السلة الحالية. قدم معرف السلة (أو token) والكود المطلوب؛ تعيد الاستجابة بيانات السلة المحدثة.

Mutation

mutation ApplyCode($cart: String!, $code: String!) {
applyCode(cart: $cart, code: $code) {
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
}
}

المتغيرات

{
"cart": "<CART_ID_OR_TOKEN>",
"code": "<COUPON_CODE>"
}

أمثلة

curl -X POST \
https://appssubdomain.com/api/graphql \
-H "Content-Type": "application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "mutation ApplyCode($cart: String!, $code: String!) { applyCode(cart: $cart, code: $code) { success message data { _id coupon couponApplied totalPrice } } }",
"variables": { "cart": "<CART_ID>", "code": "<COUPON_CODE>" }
}
EOF

ملاحظات

  • تأكد من أن cart يطابق طريقة نظامك في تحديد السلال (ID، token، session).
  • تعامل مع success/message لإظهار أخطاء الأكواد غير الصالحة/منتهية الصلاحية للمتسوقين.
  • بعد تطبيق الكود بنجاح، أعد عرض الإجماليات وأسعار العناصر باستخدام data المُعادة.