How to: work with inventory attributes
This document is intended to explain how to fetch data for inventory attribute values.
General info
Inventory attributes may be defined on following entities : Product, ProductVariant and ProductInstance.
For specific Product/ProductVariant/ProductInstance it is possible to set/edit specific set of product attributes that are specified in used product template.
Product template is collection of product attributes, on product category may be defined properties ProductTemplate, VariantTemplate and InstanceTemplate that are supposed to be used for product/variant or instance and each of these properties may be overriden on product level.
Get product attributes
Word: POST
URL: {host_url}/api/inventory/productAttribute/GetProductAttributes
Minimal request:
{
} |
Method returns collection of all defined product attributes. Each product attribute have Kind which is enum of type ProductAttributeKind and have following options:
Unknown = 0,
String = 1,
StringOptions = 2,
Int = 3,
IntOptions = 4,
Decimal = 5,
DecimalOptions = 6,
Memo = 7,
Url = 8,
Actor = 9,
Date = 10,
Catalog= 11 |
Resolve product attribute values
Product, ProductVariant and Product instance entities have AttributeValues collection. Usually they are optionally included in responses. For example, product instance attributes are included by default in case when they are returned by GetProductInstancePage method, for product page situation is more complex and explained in GetProductPage usage document.
Each element is of AttributeValues collection is of type ProductAttributeValueBase and have ProductAttribute where minimal information (SystemName, Kind and DisplayName) of product attribute is presented and also ProductAttributeId property that can be used to resolve entire attribute data by id from collection returned by GetProductAttributes method.
Also each product attribute value have set of properties named StringValue, IntValue etc.
To resolve on which exactly property attribute value is stored, following pseudo code may be used:
case ProductAttributeKind.String:
case ProductAttributeKind.StringOptions:
return productAttributeValue.StringValue;
case ProductAttributeKind.Memo:
return productAttributeValue.MemoValue;
case ProductAttributeKind.Url:
return productAttributeValue.UrlValue;
case ProductAttributeKind.Int:
case ProductAttributeKind.IntOptions:
return productAttributeValue.IntValue;
case ProductAttributeKind.Decimal:
case ProductAttributeKind.DecimalOptions:
return productAttributeValue.DecimalValue
case ProductAttributeKind.Date:
return productAttributeValue.DateValue;
case ProductAttributeKind.Actor: // actor id will be returned
return productAttributeValue.EntityIdValue
case ProductAttributeKind.Catalog: // catalog value id will be returned
return productAttributeValue.EntityIdValue; |
Resolve product attribute catalog value
If product attribute have kind Catalog, it’s value is stored in EntityIdValue field of ProductAttribute Value.
Its meaning is CatalogValueItemId. So to display it, catalog value need to be fetched and should be displayed its Code and Value in some combination.
To resolve catalog system name, Product attribute need to be resolved by Id. Product attribute with kind [Catalog] have filled CatalogPreferences property, which have property CatalogSystemName. By catalog system name may be resolved catalog values.
Get catalog values by system name
Word: POST
URL: {host_url}/api/catalogs/catalogValue/GetCatalogValues
Minimal request:
Method returns collection catalog values for specific catalog. Desired catalog value may be found among them by Id.
Resolve product attribute actor value
If product attribute have kind Actor
, it’s value is stored in EntityIdValue field of ProductAttribute Value.
Its meaning is ActorId. Minimal way to display actor data by its id is retrieve actor text.
Get Actor texts
Word: POST
URL: {host_url}/api/actors/actor/GetActorTexts
Minimal request:
Method returns collection of values of type EntityDescriptor each of them have DisplayValue property that may be displayed as product attribute value.