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

الحصول على السمات بواسطة العلامة

في هذا المثال، نوضح كيفية استرجاع مخطط السمة لمجموعة سمات معينة بواسطة علامتها باستخدام واجهة برمجة التطبيقات OneEntry.

✅ هدف السيناريو:

  • الاتصال بواجهة برمجة التطبيقات OneEntry
  • استرجاع مخطط السمة لمجموعة سمات مسماة
  • الوصول إلى بيانات التعريف الخاصة بالسمة: العلامة، النوع، التسمية، المدققون، وعناوين القائمة

✅ ما تحتاجه:

  • عنوان PROJECT_URL و APP_TOKEN صالحين للمصادقة مع واجهة برمجة التطبيقات OneEntry.
  • مجموعة سمات تم تكوينها في OneEntry مع علامة معروفة (مثل "منتج")

📌 مهم:

  • هذه الأمثلة لا تتضمن معالجة الأخطاء.
  • يمكنك إدارة الأخطاء باستخدام كتلة try-catch أو من خلال استخدام بناء مثل await Promise.catch((error) => error).
  • تعيد SCHEMA من السمات — وليس القيم الفعلية للكيانات.
  • القيمة دائماً في المخطط — للحصول على القيم الحقيقية استخدم Products.getProducts()، Pages.getPageByUrl()، إلخ.
  • استخدم listTitles لبناء خيارات الفلترة لسمات نوع القائمة و radioButton.

📚 انظر في الوثائق:

📦 مرجع SDK:

جربه مباشرة

قم بتشغيل هذه الطريقة بشكل تفاعلي في JS SDK sandbox — قم بتوصيل عنوان مشروعك و رمز التطبيق في الزيارة الأولى، ثم افتح:

السيناريو

1. استيراد defineOneEntry من SDK وتعريف PROJECT_URL و APP_TOKEN

مثال:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. إنشاء عميل API باستخدام defineOneEntry()

مثال:

const { AttributesSets } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. الحصول على مخطط السمة بواسطة العلامة باستخدام AttributesSets.getAttributesByMarker()

مثال:

const attributes = await AttributesSets.getAttributesByMarker(
'product',
'en_US',
);
console.log('Attributes: ', attributes);
النتيجة:
[
{
"type": "real",
"value": {},
"marker": "price",
"position": 1,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"initialValue": null,
"localizeInfos": {
"title": "Price"
},
"additionalFields": {}
},
{
"type": "string",
"value": {},
"marker": "currency",
"position": 2,
"listTitles": [],
"validators": {
"defaultValueValidator": {
"fieldDefaultValue": "USD",
"fieldDefaultValue2": ""
}
},
"initialValue": null,
"localizeInfos": {
"title": "Currency"
},
"additionalFields": {}
},
{
"type": "image",
"value": {},
"marker": "image",
"position": 3,
"listTitles": [],
"validators": {},
"initialValue": null,
"localizeInfos": {
"title": "Image"
},
"additionalFields": {}
}
]

المثال النهائي

// 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

// 2. Creating an API client with [defineOneEntry()](/docs/index/#Installation)
const { AttributesSets } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. Get attribute schema by marker with [AttributesSets.getAttributesByMarker()](/docs/attribute-sets/getAttributeSetByMarker)
const attributes = await AttributesSets.getAttributesByMarker(
'product',
'en_US',
);
console.log('Attributes: ', attributes);