Mapping
Omnitron provides an easy-to-use mapping interface enabling you to associate the products integrated from ERP or other external resources and approved on Integrations > Pending Products page with Omnitron.
Note: Mapping process is needed only if you prefer to use the pending product stage before the productization process. You might skip this stage if you prefer to handle the mapping process on the integration layer and directly send your products to the Product Pool.
Mapping Model Structure
Mapping is a matching process between values coming from ERP and external sources.
Fig 1: Mapping Model
The mapping model consists of the following strategies:
AttributeValueMappingStrategy
: This strategy leads to map attribute values
The strategy used to match attribute values. Pulls custom is_localizable
and language parameters from kwargs. According to these parameters, it is decided whether the attribute will be pulled according to the language. Then, the default_value
is drawn from the output_kwargs
in the mapping model and the value is retrieved according to the mapping_key
in the mapping model. If value does not exist and the default_attribute is present, it pulls the attribute directly from the product object and maps it to value. After that, it returns (value, True) if pulled from the default_attribute. If pulled directly from mapping (value, False).
AttributeSetMappingStrategy
: This strategy leads to map [Attribute Set],
There are no language operations as in AttributeValueMappingStrategy, but the rest of the value pulling process is the same. When returning, the value is returned directly.
Path: omnitron.mappings.models.Mapping
- Mapping_Type (EnumField): Indicates the mapping type. Its values are;
attribute
='attribute'attribute_set
='attribute set'attribute_value
='attribute value'
- input_kwargs (JSONField): Represents the attributes' rules
- output_kwargs (JSONField): Represents default values
- priority (integer): Indicates the mapping priority
- mapping_key: The name of the attribute to be associated with
MappingViewSet
MappingViewSet {omnitron.mappings.resources.views.MappingViewSet}
is located at the address of /api/v1/mappings/
.
Allows GET, POST, PUT, PATCH and DELETE methods inherited from ModelViewSet. perform_create(), perform_update() and perform_destroy() functions are overridden; perform create/update operations on the relevant MappingService.
Figure 2: MappingViewSet and Methods
And one property named strategy is defined. This property returns the two strategies mentioned above in class format upon fetching from mapping_type.
Parameter | Data Type | Default | In | Required | Description |
api_token | string | header | YES | The API key of the customer account | |
product_sku | string | body | YES | Product SKU | |
stock_list | id | body | YES | Stock list which includes the product | |
stock | integer | 0 | body | NO | Amount of stock |
unit_type | enum(string) | qty | body | NO | Stocked quantity type qty: Quantity kg: Kilogram |
MappingFilter
Mapping filter {omnitron.mappings.resources.filters.MappingFilter}
is used to determine filter keys and how these keys work.
Figure 3: MappingFilter Structure
GET
Mapping
Get request to get list of mapping objects.
Path: /api/v1/mappings/
{
"count": 499,
"next": "{customer_omnitron_url}/api/v1/mappings/?page=2",
"previous": null,
"results": [
{
"pk": 2515,
"created_date": "2017-01-22T07:43:38.446000Z",
"modified_date": "2017-01-22T07:43:38.446000Z",
"mapping_type": "attribute_value",
"value_dict": {
"attributes__erp_color": "BEYAZ"
},
"default_value": {
"filtre_renk1": "Beyaz"
},
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"create_all_kind": false
},
...
]
}
POST
Create Mapping
Adds a new record to the mapping table.Validated with MappingSerializer. Returns HTTP400 if data is not available. Returns HTTP406 if there is an error or incompatibility at the service layer during the recording process.
Path: /api/v1/mappings/
Body
{
"mapping_type": "attribute_value",
"value_dict": {
"attributes__erp_color": "TEST"
},
"default_value": {
"filtre_renk1": "Test"
},
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"create_all_kind": false
}
Response
{
"pk": 3014,
"created_date": "2023-01-05T19:06:07.007354Z",
"modified_date": "2023-01-05T19:06:07.007381Z",
"mapping_type": "attribute_value",
"value_dict": {
"attributes__erp_color": "TEST"
},
"default_value": {
"filtre_renk1": "Test"
},
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"create_all_kind": false
}
Errors
{
{
"non_field_errors": "... required field",
"error_code": "mapping_101"
}
-- OR
{
"mapping_type": [
"This field is required."
]
}
-- OR
{
{
"non_field_errors": "{0} field type is not {1}",
"error_code": "mapping_101"
}
-- OR
{
"value_dict": [
"Expected a dictionary of items but got type \"list\"."
]
}
PATCH
Partial Update
Path: /api/v1/mappings/{pk}/
Partially updates the object of the relevant primary key from the attribute table. Validated with AttributeSerializer. Returns HTTP400 if data is not available. If it cannot find the object, it returns HTTP404. With partial update behavior, it only updates the sent parameters.
Body
{
"create_all_kind": true
}
Response
{{
"pk": 3016,
"created_date": "2023-01-05T19:15:39.212420Z",
"modified_date": "2023-01-05T19:20:57.624044Z",
"mapping_type": "attribute_value",
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"value_dict": {
"attributes__erp_color": "TEST"
},
"default_value": {
"filtre_renk1": "Test Renk"
},
"create_all_kind": true
}
PUT
Partial Update
Path: /api/v1/mappings/{pk}/
Updates the object of the corresponding primary key from the mapping table. Validated with MappingSerializer. Returns HTTP400 if data is not available. If it cannot find the object, it returns HTTP404. Updates the entire object with the update behavior.
Body
{
"mapping_type": "attribute_value",
"value_dict": {
"attributes__erp_color": "TEST"
},
"default_value": {
"filtre_renk1": "Test Renk"
},
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"create_all_kind": false
}
Response
{
"pk": 3016,
"created_date": "2023-01-05T19:15:39.212420Z",
"modified_date": "2023-01-05T19:16:14.737971Z",
"mapping_type": "attribute_value",
"value_dict": {
"attributes__erp_color": "TEST"
},
"default_value": {
"filtre_renk1": "Test Renk"
},
"default_attribute": null,
"priority": 0,
"mapping_key": "filtre_renk1",
"create_all_kind": false
}
Errors
{
"mapping_type": [
"This field is required."
],
"mapping_key": [
"This field is required."
]
}