Addressing Attributes and Forming Constraints

This guide will help you understand how to address various attributes in the Sleekshop API and how to form constraints for powerful, precise querying. We'll cover the different types of attributes available and demonstrate how to create both simple and complex constraints.

Understanding Attributes

Before forming constraints, it's crucial to understand the different types of attributes you can address in the Sleekshop API.

Shopobject Attributes

Shopobjects have various types of attributes that can be addressed in different ways:

  1. Normal Attributes: Address these by their names as defined in the object definition.
{"name": "test"}
  1. Main Attributes: These are core attributes of each object. Use the "main." prefix to address them.
  • Available Main Attributes:
  • id_shopobject (The ID of the object)
  • id_variation (The variation ID of the object)
  • name (The system name of the object)
  • creation_date (The creation date of the object)
  • class (The class of the object)
{"main.class": "product"}
  1. Category Attributes: Use the "category." prefix to address these.
  • Available Category Attributes:
  • id_shopcategory (The ID of the category)
  • name (The name of the category)
  • id_shopcategory_parent (The ID of the parent category)
  • label (The label of the category)
  • permalink (The permalink of the category)
  • title (The title of the attribute)
  • path (An attribute containing nodes)
{"category.name": "Start"}
  1. Category Path and Nodes: Address the node structure of categories.
  • Available Category Path and Nodes Attributes:
  • name (A string that contains the path)
  • path.nodes (An array of nodes that belong to the path)
  • prio (The priority of the node)
  • id_parent (The parent ID)
  • label (The label of the node)
{"category.path.nodes.name": "test"}
  1. Metadata: Some objects (like products) have metadata. Use the "metadata." prefix.
  • Available Metadata Attributes:
  • element_number (The unique number of the element SKU)
  • length (The length of the product)
  • width (The width of the product)
  • height (The height of the product)
  • weight (The weight of the product)
{"metadata.element_number": "123"}
  1. Availability: Address availability attributes with the "availability." prefix.
  • Available Availability Attributes:
  • quantity (The available quantity)
  • quantity_warning (The warning quantity)
  • allow_override (A flag showing whether an override is allowed)
{"availability.quantity": 1}
  1. SEO: Address SEO attributes with the "seo." prefix.
  • Available SEO Attributes:
  • permalink (The permalink)
  • title (The title)
  • description (The description)
  • keywords (The keywords)
{"seo.permalink": "my-permalink"}
  1. PRODUCT Attribute: Apply all defined modifiers to attributes of products inherited in a PRODUCTS attribute.
{"prod.color":"red"}
  1. Variations: Address fields of product variations with the "variations." prefix.
  • Available Variation Attributes:
  • color (The color of the variation)
  • size (The size of the variation)
  • price (The price of the variation)
  • stock (The stock level of the variation)
{"variations.color":"red"}

Order Attributes

Orders have various types of attributes that can be addressed:

  1. Main Attributes: These are core attributes of each order. Use the "main." prefix to address them.
  • Available Main Order Attributes:
  • id_order (The ID of the order)
  • order_number (The order number)
  • id_user (The ID of the user)
  • username (The username)
  • creation_date (The creation date)
  • modification_date (The modification date)
  • delivery_companyname (The delivery company name)
  • delivery_department (The delivery department)
  • delivery_salutation (The delivery salutation)
  • delivery_firstname (The delivery first name)
  • delivery_lastname (The delivery last name)
  • delivery_street (The delivery street)
  • delivery_number (The delivery number)
  • delivery_zip (The delivery ZIP code)
  • delivery_state (The delivery state)
  • delivery_city (The delivery city)
  • delivery_country (The delivery country)
  • delivery_country_code (The delivery country code)
  • invoice_companyname (The invoice company name)
  • invoice_department (The invoice department)
  • invoice_salutation (The invoice salutation)
  • invoice_firstname (The invoice first name)
  • invoice_lastname (The invoice last name)
  • invoice_street (The invoice street)
  • invoice_number (The invoice number)
  • invoice_zip (The invoice ZIP code)
  • invoice_state (The invoice state)
  • invoice_city (The invoice city)
  • invoice_country (The invoice country)
  • invoice_country_code (The invoice country code)
  • email (The email address)
  • phone (The phone number)
  • notes (The notes)
  • payment_method_name (The payment method name)
  • payment_state_name (The payment state name)
  • delivery_method_name (The delivery method name)
  • delivery_state_name (The delivery state name)
  • order_state_name (The order state name)
{"main.delivery_firstname":"test"}
  1. Cart Attributes: These attributes pertain to the items in the cart. Use the "contents." prefix to address them.
  • Available Cart Attributes:
  • element_type_name (Type of the element, e.g., COUPON, DELIVERY, PRODUCT)
  • id_shopobject (The ID of the shop object)
  • element_number (The element number)
  • quantity (The quantity)
  • price (The price)
  • sum_price (The sum price)
  • name (The name of the item)
  • description (The description of the item)
{"contents.name":"product1"}
  1. Custom Order Attributes: These are additional attributes you may have set during order creation.
{"attribute1":"value1","attribute2":"value2"}

User Attributes

Users also have various types of attributes that can be addressed:

  1. Main Attributes: These are core attributes of each user. Use the "main." prefix to address them.
  • Available Main User Attributes:
  • status (The status of the user)
  • id_user (The ID of the user)
  • username (The username)
  • email (The email address)
  • default_language (The default language)
  • reg_date (The registration date)
  • first_login (The first login date)
  • last_login (The last login date)
  • salutation (The salutation)
  • firstname (The first name)
  • lastname (The last name)
  • companyname (The company name)
  • department (The department)
  • street (The street address)
  • number (The street number)
  • zip (The ZIP code)
  • city (The city)
  • state (The state)
  • country (The country)
  • vat_number (The VAT number)
{"main.firstname":"test"}
  1. Additional User Attributes: These are inherited from the mother class and can be addressed as normal attributes of shop objects.
{"test_field":111}

Forming Constraints

Now that we understand how to address attributes, let's look at how to form constraints for querying.

Simple Constraints

AND Combination

To combine multiple conditions with AND, simply list them in the JSON object:

{
  "name": "test",
  "price": 100
}

This constraint will find all products named "test" with a price of 100.

OR Combination

To combine conditions with OR, use the "OR" keyword:

[
  {
    "OR": {"name": "test"},
    "0": {"price": 100},
    "1": {"short_description": "short_txt"}
  }
]

This constraint will find products that either have the name "test", a price of 100, or a short description of "short_txt".

Advanced Constraints

Between

Between

{
    "price": ["BETWEEN", 30, 90]
}

Use the BETWEEN operator to find values within a specific range:

Greater Than

Greater Than

{
    "price": [">", 100]
}

Use the > operator to find values greater than a specific number.

Less Than

Less Than

{
    "price": ["<", 100]
}

Use the < operator to find values less than a specific number.

LIKE

LIKE

{
    "name": ["LIKE", "a"]
}

Use the LIKE operator to find values that contain a specific string.

IN

IN

{
    "price": ["IN", [100, 99, 98]]
}

Use the IN operator to find values that match any of the provided values.

Complex Constraints

You can combine these operators to create powerful, complex queries. Here's an example that finds products with a name like "a" and a price either greater than 10 or less than 8:

{
  "main.name": ["LIKE", "a"],
  "0": {
    "OR": {"price": [">", 10]},
    "0": {"price": ["<", 8]}
  }
}

Best Practices

  1. Start with simple constraints and gradually build complexity.
  2. Use appropriate modifiers (e.g., "main.", "category.", "metadata.") to target specific attribute types.
  3. Remember that all order attributes are saved as strings, so provide values as strings when querying.
  4. Use the LIKE operator for flexible text matching, but be aware it may impact performance on large datasets.
  5. Combine different operators to create precise, powerful queries tailored to your specific needs.

Was this page helpful?