Centra

Support Center

How to setup Custom Attributes

Last Updated: Jul 03, 2018 05:07PM CEST

Custom Attributes

This is how you set up the custom attributes for product, variants, orders and customers.

The following structure is used in the config.php to define custom attributes on products, variants, accounts and orders. Attributes means that you can create arbitrary fields which will be available in the API and exports. There are different types of attributes.

Mapping attributes

The normal attribute on a product or variant is one which is mapped to a attribute object which can contain meta-data. The reason for this is for example if you have a specific Color-attribute that contains the name, hex-code and image of the color. You do not want to upload these values every time, so one attribute is created, which you then link to the products that should have the color.

The structure looks something like this:

config.php
$usr_conf['ATTRIBUTE_TYPES'] = [
    'sh_swatch' => [
      'desc' => 'Showroom Color Swatch',
      'group' => 'variation', 
      'elements' => [
          'color' => ['desc' => 'Image', 'type' => 'image', 'readonly' => true, 'size' => '60x60'],
          'color_text' => ['desc' => 'Color', 'type' => 'text', 'readonly' => true]
      ],
    ]
];

You can then create a new Showroom Color Swatch-attribute under CATALOG / ATTRIBUTES:

When this attribute is saved, this attribute option will be listed under the Showroom Color Swatch-title in the variant-section of the product:

In the API, the values will come out like this:

...
"countryOfOriginName": "",
"sh_swatch": {
  "color": {
    "type": "image",
    "url": "https://d1go3p1fxskufg.cloudfront.net/client/dynamic/attributes/screen-shot-2018-07-03-at-133111_9471.jpg",
    "width": "60",
    "height": "60",
    "mimeType": "image/jpeg"
  },
  "color_text": "#8b0000"
},
"markets": {
...

Dynamic attributes

Dynamic attributes, compared to mapping attributes are not linked to any pre existing attribute, but have specific data for the specific product. This data needs to be set for each product instead of linking to an existing attribute. The difference between mapped and dynamic is that dynamic uses "readonly": false for the attribute.

Please note that when you have "readonly": false on the attribute, only the element with the text-key will be visible in the API for now. This means that if you need multiple elements you need multiple attributes as well.

config.php
$usr_conf['ATTRIBUTE_TYPES'] = [
    'limited_edition' => [
      'desc' => 'Limited Edition',
      'group' => 'product', 
      'readonly' => false,
      'elements' => [
          'text' => ['desc' => 'Limited Edition', 'type' => 'boolean', 'options' => [[1,'Yes'],[0,'No']]],
      ],
    ],
];

This will show up on the product directly with a Yes / No-option:

And in the API, it will show up like this:

...
"limited_edition": 1,
...

Please note that when the option you’ve selected is 0/false the property will not show up in the API at all.

Attribute-groups

The group on the attribute inside the config.php specifies where the attribute should be placed. The following groups exists today:

Group Description
product Listed under General Attributes on all Products
variation Listed under each Variant on all Products
order Listed on each Order
customer Listed under each Customer
account Listed under each Account (B2B)

Attribute element-types

Element-type are inside the elements-property for the attribute config.php:

$usr_conf['ATTRIBUTE_TYPES'] = [
    'limited_edition' => [
      'desc' => 'This is the attribute',
      'group' => 'product', 
      'elements' => [
          'text' => ['desc' => 'This is the element-type', 'type' => 'boolean', 'options' => [[1,'Yes'],[0,'No']]],
      ],
    ],
];

The following element types exists today. Not all of them are supported for the Dynamic attributes (which are shown inline on each product/variant), so the support for the different options are listed below:

Type Description Support Options
input Mapping/Dynamic Set class of the input (double the size of the input): 'class' => 'double'
text Mapping/Dynamic Set class of the textarea: 'class' => 'double'
boolean Mapping/Dynamic Options for the radio inputs (default is always 0): 'options' => [[1,'Yes'],[0,'No']]
select Mapping/Dynamic Default selected is always first option, so keep it as [0,'Select'] like: 'options' => [[0,'Select'],['1','AAA'],['2','BBB']]
image Mapping Size of the image: 'size' => '600x400'
Allowed image formats: 'jpg','jpeg','png','gif','svg'
file   Mapping No options available.

API-output

The API-output differs between Dynamic and Mapped attributes.

Mapped attributes will always have a parent element named as the attribute-key:

config.php
$usr_conf["ATTRIBUTE_TYPES"] = [
    "attribute_name" => [
      "desc" => "This is the attribute",
      "group" => "product", 
      "readonly" => true,
      'elements' => [
          'abc' => ['desc' => 'Text', 'type' => 'input'],
          'xyz' => ['desc' => 'Image', 'type' => 'image', 'size' => '600x400'],
      ],
    ],
];

Having this attribute selected on a product, will output this in the API:

"attribute_name": {
  "abc": "Test text",
  "xyz": {
    "type": "image",
    "url": "https://d1go3p1fxskufg.cloudfront.net/client/dynamic/attributes/screen-shot-2018-07-03-at-132850_2467.jpg",
    "width": "600",
    "height": "400",
    "mimeType": "image/jpeg"
  }
},

But for Dynamic attributes the will be listed inline, remember that only the element with the key text will be shown, if the value is not 0/false:

config.php
$usr_conf['ATTRIBUTE_TYPES'] = [
    'attribute_name' => [
      'desc' => 'This is the attribute',
      'group' => 'product', 
      'readonly' => false,
      'elements' => [
          'text' => ['desc' => 'Text', 'type' => 'input'],
      ],
    ],
];

API
"attribute_name": "This is the text",

The dynamic attributes supported are all strings, so they look the same as per above. This is how the elements look like from the mapped attributes:

config.php
$usr_conf['ATTRIBUTE_TYPES'] = [
  'attribute_field' => [
      'desc' => 'This is the attribute',
      'group' => 'product',
      'readonly' => true,
      'elements' => [
          'text' => ['desc' => 'Text', 'type' => 'input'],
          'textarea' => ['desc' => 'Textarea', 'type' => 'text'],
          'boolean' => ['desc' => 'Boolean', 'type' => 'boolean', 'options' => [[1,'Yes'],[0,'No']]],
          'select' => ['desc' => 'Select', 'type' => 'select', 'options' => [[0,'Select'],['aa','AA'],['bb','BB']]],
          'image' => ['desc' => 'Image', 'type' => 'image', 'size' => '600x400'],
          'file' => ['desc' => 'File', 'type' => 'file']
      ],
  ],
];

API
...
"attribute_field": {
  "text": "Text",
  "textarea": "Textarea",
  "boolean": "1",
  "select": "bb",
  "image": {
    "type": "image",
    "url": "https://d1go3p1fxskufg.cloudfront.net/client/dynamic/attributes/screen-shot-2018-07-03-at-144850_4265_png.jpg",
    "width": "600",
    "height": "400",
    "mimeType": "image/jpeg"
  },
  "file": {
    "type": "file",
    "url": "https://d1go3p1fxskufg.cloudfront.net/client/dynamic/attributes/6/screen-shot-2018-07-03-at-144850.png"
  }
},
...

Contact Us

support@youngskilled.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete