---
title: Attribute Mapping
slug: klevu-magento-v4/attribute-mapping
docTags: 
createdAt: 2024-09-23T17:04:48.317Z
---

It is possible to map Magento attributes to Klevu attributes via `di.xml`
The modules already map some attributes where the names in Klevu and Magento differ. e.g. Magento's `short_description` to Klevu's `shortDescription`.

The current product attribute mapping can be found in `module-m2-indexing-products/etc/di.xml` and looks like this:

:::CodeblockTabs
module-m2-indexing-products/etc/di.xml

```xml
<virtualType name="Klevu\IndexingProducts\Service\Mapper\MagentoToKlevuAttributeMapper"
             type="Klevu\Indexing\Service\Mapper\MagentoToKlevuAttributeMapper">
  <arguments>
    ...
    <argument name="attributeMapping" xsi:type="array">
      <item name="image" xsi:type="null"/>
      <item name="klevu_image" xsi:type="string">image</item>
      <item name="klevu_rating" xsi:type="string">rating</item>
      <item name="klevu_rating_count" xsi:type="string">ratingCount</item>
      <item name="quantity_and_stock_status" xsi:type="string">inStock</item>
      <item name="short_description" xsi:type="string">shortDescription</item>
      <item name="url_key" xsi:type="string">url</item>
    </argument>
  </arguments>
</virtualType>
```
:::

### Adding Mapping for Attributes

If instead of using the Magento attribute `description` for the Klevu attribute `description` you wanted to use `my_custom_attribute`. Create your own module and add `etc/di.xml` like this

:::CodeblockTabs
Vendor/Module/etc/di.xml

```xml
<virtualType name="Klevu\IndexingProducts\Service\Mapper\MagentoToKlevuAttributeMapper">
    <arguments>
        <argument name="attributeMapping" xsi:type="array">
            <item name="my_custom_attribute" xsi:type="string">description</item>
        </argument>
    </arguments>
</virtualType>
```
:::

Now if you access `my_custom_attribute` in Magento admin you’ll see that the Klevu section can no longer be updated as it is mapped to a standard Klevu attribute and standard Klevu attributes are immutable. However, the `description` attribute will be editable as it is no longer mapped to a standard Klevu attribute.

If `description` is also set to be registered with Klevu this will cause an issue as there are 2 Magento attributes mapped to the same Klevu attribute (if no mapping is in place then an attribute will use its attribute code). Therefore mapping for `description` would also be required.
e.g.

:::CodeblockTabs
Vendor/Module/etc/di.xml

```xml
<virtualType name="Klevu\IndexingProducts\Service\Mapper\MagentoToKlevuAttributeMapper">
    <arguments>
        <argument name="attributeMapping" xsi:type="array">
            <item name="my_custom_attribute" xsi:type="string">description</item>
            <item name="description" xsi:type="string">someOtherField</item>
        </argument>
    </arguments>
</virtualType>
```
:::

or

:::CodeblockTabs
Vendor/Module/etc/di.xml

```xml
<virtualType name="Klevu\IndexingProducts\Service\Mapper\MagentoToKlevuAttributeMapper">
    <arguments>
        <argument name="attributeMapping" xsi:type="array">
            <item name="my_custom_attribute" xsi:type="string">description</item>
            <item name="description" xsi:type="null"/>
        </argument>
    </arguments>
</virtualType>
```
:::

