Indexing
...
Attributes
Discovery
Registering Attributes that are not Magento Attributes
2 min
there may be cases where you need to index some entity data to klevu where a magento attribute does not represent that data if the data needs to be searchable and/or filterable then creating a static attribute is the recommended way to handle that however, if the data is only to be used on the frontend, then sending it in additionaldatatoreturn is a simpler approach and a static attribute would not be required e g for a product you want to send the following data in the entity payload { "name" "product name", "sku" "sku 101", "some attribute" "this is not a magento attribute, but some third party data" } where some attribute is not a magento attribute but is data pulled from some third party source with the klevu json api, we must register some attribute as an attribute before sending data for that attribute in the entity payload klevu provides staticattributeprovider to accomplish this called “static” as they are hardcoded in the di xml and cannot be updated via the admin or the database we add attributes to staticattributeprovider by injecting the required attribute(s) into the attributes argument via di xml e g vendor/module/etc/di xml \<type name="klevu\indexingproducts\service\provider\staticattributeprovider"> \<arguments> \<argument name="attributes" xsi\ type="array"> \<item name="some attribute" xsi\ type="array"> \<item name="attribute id" xsi\ type="number">100001\</item> \<! required > \<item name="attribute code" xsi\ type="string">some attribute\</item> \<! required > \<item name="is searchable" xsi\ type="boolean">true\</item> \<! optional default = false > \<item name="is filterable" xsi\ type="boolean">false\</item> \<! optional default = false > \<item name="is returnable" xsi\ type="boolean">true\</item> \<! optional default = false > \<item name="default label" xsi\ type="string">some attribute\</item> \<! optional default = attribute code with underscores removed and uppercase first letter > \<item name="labels" xsi\ type="array"> \<! optional item names are store ids > \<item name="1" xsi\ type="string">store label\</item> \<item name="2" xsi\ type="string">étiquette du magasin\</item> \<item name="3" xsi\ type="string">store etikett\</item> \</item> \<! the following are used to determine what attribute type is created in klevu > \<! klevu attribute types are string, number, multivalue > \<! if none of these are set the default attribute type is string > \<item name="frontend input" xsi\ type="string">select\</item> \<! optional > \<item name="backend type" xsi\ type="string">int\</item> \<! optional > \<item name="source model" xsi\ type="string">vendor\module\model\source\someattributesource\</item> \<! optional > \<item name="is html allowed on front" xsi\ type="number">1\</item> \<! optional > \<item name="is global" xsi\ type="number">1\</item> \<! optional > \</item> \</argument> \</arguments> \</type> we can do the same for categories injecting into klevu\indexingcategories\service\provider\staticattributeprovider