Skip to main content

Catalogue Item

Allows for linking between the product and the catalog. While the product is moved to the previously created catalog, an instance is created from the CatalogItem model that is associated with the product and the catalog. A product can be added to multiple catalogs.


Model(omnitron.catalogs.models.CatalogItem)

product = models.ForeignKey('products.Product') catalog = models.ForeignKey('Catalog')

The model consists of the product and catalog relationship. There are also validations that control the category in addition to controlling the stock and price lists.


Filtering

CatalogItems can be filtered by product and catalog pk value.


ViewSet(omnitron.catalogs.resources.views.CatalogItemViewSet)

To be able to work on a catalog, the user must have a Catalog Authority Group. All CatalogItem objects returning over the Viewset are filtered according to the catalog authorization group owned by the user. This is so that the user cannot perform any action on a catalog without authorization. The create and delete operations depend on the service. If the product added in the catalog addition and deletion operations is Meta, the products linked to this product are also added to or removed from the catalog. If a product is to be added to the same catalog multiple times, it is CatalogItemDuplicatedFieldException raised.


Example Request & Response

GET Catalog Item

Sample HTTP request to get all catalog item lists from the system.

‘content_type’ header represents the response type.

The ‘Authorization’ header is required for authentication. You can retrieve api_token by logging in.

Request

Path: /api/v1/catalog_items/

import requests

url = "https://{customer_api_url}/api/v1/catalog_items/"
api_token = "API TOKEN"

headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}

response = requests.get(url, headers=headers)
print(response.text)

Response

Returns the catalog ID and the product ID of the corresponding catalog item.

{
"count": n,
"next": "/api/v1/catalog_items/?page=2",
"previous": null,
"results": [
{
"pk": 1,
"product": 1,
"catalog": 1,
"created_date": "2020-05-07T11:25:03.745360Z",
"modified_date": "2020-05-07T11:25:03.745387Z"
},
{
"..."
}
]
}

POST Create Catalog Item

After the product and catalog models are created, the post request is sent using the pk information of the relevant models. The product and catalog ID must be unique, otherwise it will throw an error. (“product”, “catalog” fields should form a unique set.)

Path: /api/v1/catalog_items/

{
"product": {product-pk},
"catalog": {catalog-pk}
}

Response

Returns the properties of the created catalog items.

Response Status Code: 201 and parameter detail.

{
"pk":{catalogitem-pk},
"product":{product-pk},
"catalog":{catalog-pk},
"created_date":"2021-05-11T10:46:47.996741Z",
"modified_date":"2021-05-11T10:46:47.996769Z"
}

DELETE Catalog Item

Path: /api/v1/catalog_items/{catalog-item-pk}/

Response

Response Status Code: 204