Skip to main content

Measurement units

Product attributes with the Price input type are often used for sizes, weights and other measurements rather than money: a lure length, a cable cross-section, a pack weight. The extension gives these values to agents as numbers, together with their unit, so an agent can compare and sort them and tell the shopper what the number means.

A measurement appears in the product's metadata.attributes, in the MCP tools and the JSON read API, like this:

"wobbler_size": { "label": "Size", "value": 135, "unit": "mm" }
  • value is a JSON number: 135 for a whole value, 0.125 for a fractional one.
  • unit is the unit set for the attribute, as described below. When no unit is found, the unit key is left out.

Attributes that hold money keep their usual currency-formatted value and never get a unit.

Set the unit of an attribute​

  1. Open Stores -> Attributes -> Product and edit the attribute.
  2. On the Properties tab, find the Unit fieldset. It appears only while Catalog Input Type for Store Owner is Price.
  3. Enter the unit in the Default column, for example mm, kg or pcs.
  4. If a store view stores this attribute's value in a different unit, enter that unit in the store view's own column. Leave the other store-view columns empty to use the default.
  5. Click Save Attribute.

The unit is free text in any language or script, up to 16 characters. Spaces around it are trimmed.

Which unit to enter​

Enter the unit of the value as it is stored in Magento - the number you type on the product page.

The extension never converts values and never reads the unit from the attribute label. For example:

  • The value is stored in millimetres and your theme also shows inches, as 135 (5.3"). The stored value is 135, so enter mm. Agents can convert to inches themselves if a shopper asks.
  • The label is Size, mm. Still enter mm in Unit. The label is passed to agents unchanged, but it is not used as the unit.
  • The attribute is store-view scoped, and your US store view holds the value in inches while the others hold millimetres. Enter mm as the default and in for the US store view.

When the Unit field is empty​

For each store view, the extension takes the first unit it finds, in this order:

  1. The attribute's unit for that store view.
  2. The attribute's Default unit.
  3. The unit from your layered navigation extension, if one is installed and enabled:
    • Mirasvit Layered Navigation: the unit written in the attribute's Value Template, for example {value} mm.
    • Amasty Improved Layered Navigation: the attribute's Units Label.
  4. No unit: the value is sent without a unit key.

When the default is empty and a layered navigation unit exists, the Default field shows that unit as a grey placeholder, so you can see what agents will get.

tip

To check the result, open /agent/products/{url_key}.json for a product that has the attribute and look for it under metadata.attributes. Clear the cache first if you have just saved the attribute.