Product Collection
It is provided with the ProductCollection
model of grouping the products in catalogs or creating special collections with various rule sets. The collection type may be Dynamic
or Static
. Collection items are created only from items available for sale. In dynamic collections, a collection rule set is created using certain filters so that the products are dynamically added to the collection through this rule set. Dynamic collections remain active for the specified time expiration_date
period. As long as they are not expired, the items in the collection are updated according to the rule set. This process is managed with tasks. In static collections, the items are added to the collection once and remain stable. While the created collections can be used to create special pages, they can also be used to create campaigns.
GET
Product Collection
GET
Product CollectionSample HTTP request to get all product_collections
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
import requests
url = "https://{customer_api_url}/api/v1/product_collections/"
api_token = "API TOKEN"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
response = requests.get(url, headers=headers)
print(response.text)
Path: /api/v1/product_collections/
Response
{
"count": n,
"next": "/api/v1/product_collections/?page=2",
"previous": null,
"results": [
{
"pk": 170,
"name": "test",
"created_date": "2020-02-25T14:37:04.907721Z",
"modified_date": "2021-05-07T11:35:27.751999Z",
"collection_type": "dynamic",
"catalog": 1,
"is_active": true,
"sort_option": 909,
"uuid": "12cdaa24-31f6-4e4d-849c-93851b214b2e",
"expiration_date": "2020-02-27T18:00:00Z",
"value_dict": {
"0": [
{
"value": "4",
"key": "active_stock__stock__gte"
}
],
"1": [
{
"value": "True",
"key": "active_price__discount"
}
],
"active_catalog_item__isnull": [
false
],
"active_stock__isnull": [
false
],
"active_price__isnull": [
false
]
},
"selected_filters": [
{
"value": "4",
"key": "active_stock__stock__gte"
},
{
"value": "True",
"key": "active_price__discount"
}
]
},
{
"pk": 2,
"name": "test-collection-sezgin22",
"created_date": "2019-09-19T07:12:51.713764Z",
"modified_date": "2020-03-31T16:11:21.606342Z",
"collection_type": "static",
"catalog": 1,
"is_active": false,
"sort_option": null,
"uuid": "2be5902a-9dac-4720-a092-4faba04bc1a0",
"expiration_date": null,
"value_dict": {},
"selected_filters": []
},
...
]
}
POST
Creating a Static Collection
POST
Creating a Static CollectionRecords new objects in the ProductCollection
table. The ProductCollectionSerializer
class defined at omnitron.channels.integrations.omniweb.serializers
is used to validate the data.
‘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/product_collections/
import requests
url = "https://{customer_api_url}/api/v1/product_collections/"
api_token = "API TOKEN"
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(api_token)
}
data = {
"name": "test-collection-1",
"collection_type": "static", # can be "static" or "dynamic"
"catalog": {catalog-id}
}
response = requests.post(url, headers=headers, data=data)
print(response.text)
Response
{
"pk":{product-collection-pk},
"name":"test-collection-1",
"created_date":"2021-05-11T11:50:01.348381Z",
"modified_date":"2021-05-11T11:50:01.348414Z",
"collection_type":"static",
"catalog":{catalog-id},
"is_active":true,
"sort_option":null,
"uuid":"df9b8773-6a35-44cd-b692-8eebadc69d60",
"expiration_date":null,
"value_dict":{},
"selected_filters":[]
}
POST
Add a Product to a Static Collection
POST
Add a Product to a Static CollectionAllows users to create their own product collection items. catalog_item
and collection field IDs must be inserted.
Path: /api/v1/product_collection_items/
{
"catalog_item": {catalog-item-id},
"collection": {product-collection-id}
}
Response
{
"pk":1,
"catalog_item": {catalog-item-od},
"collection":{product-collection-id}
}
DELETE
Product from Static Collection
DELETE
Product from Static CollectionAllows users to remove specific product collection items completely. It returns "204 No Content"
Path: /api/v1/product_collection_items/{product-collection-item-id}
Response Status Code: 204
POST
Create Dynamic Collection
POST
Create Dynamic CollectionAllows users to create their own product collections. Dynamic refers users to add dynamic filters and automatically find and add products that fit into filters. Users can mark these collections as active or inactive, by default is_active
is true.
Path: /api/v1/product_collections/
{
"collection_type": "dynamic",
"is_active": true,
"name": "test",
"catalog": {catalog-id},
"expiration_date": "2021-05-12T15:27+0300"
}
Response
{
"pk":1359,
"name":"test",
"created_date":"2021-05-11T12:27:09.239906Z",
"modified_date":"2021-05-11T12:27:09.239932Z",
"collection_type":"dynamic",
"catalog":{catalog-id},
"is_active":true,
"sort_option":null,
"uuid":"831174d8-ebb9-4cd2-aad1-00011ca056cf",
"expiration_date":"2021-05-12T15:27:00+03:00",
"value_dict":{},
"selected_filters":[]
}
PATCH
Update a Dynamic Collection
PATCH
Update a Dynamic CollectionUpdate can be performed for collections with PATCH
Patch operations. The following request is an example of a rule set assignment for a dynamic collection.
Path: /api/v1/product_collections/{product-collection-id}
{
"value_dict":{
"active_categories__category":{category-id}
},
"selected_filters":[
{
"name":"Test Category",
"value":{catergory-id},
"key":"active_categories__category",
"label":"Category",
"dumpedLabel":"Category"
}
]
}
DELETE
Collection
DELETE
CollectionWith the deletion request, the collection is deactivated but not completely removed from the system.The sample is_active
parameter is updated to false because the perform_destroy
method of the ProductCollectionViewSet
is overridden.
Path: /api/v1/product_collections/{product-collection-pk}/
Response Status Code: 204
GET
List All Products in a Collection
GET
List All Products in a CollectionPath: /api/v1/product_collections/{product-collection-pk}/item_list
The endpoint where the products in the collection are listed so all the products belonging to this collection are listed. Listing is done by calling the item_list
method of the ProductCollectionViewSet
.
Response:
{
"count": n,
"next": "/api/v1/product_collections/1357/item_list/?limit=1&page=2",
"previous": null,
"results": [
{
"pk": 856,
"name": "WEDGIE ALPARGATA FUCHSIA",
"base_code": "1115101",
"sku": "1115101003",
"product_type": {
"value": "0",
"label": "Simple"
},
"is_active": false,
"parent": 217740,
"attributes": {
"erp_MalDetayAdi": "WEDGIE",
"integration_AsilRenk": "FUCHSIA"
},
"attributes_kwargs": {},
"extra_attributes": {},
"active_catalog_item": {
"pk": 18,
"active_collection_item": null
},
"active_price": {
"pk": 12,
"price": "100.00",
...
},
"active_stock": {
"pk": 229,
"stock": 100,
"unit_type": "qty"
},
"active_categories": [
{
"pk": 19,
"category": {
"pk": 7,
...
}
}
],
"productimage_set": [
{
"pk": 111635,
"status": "active"
...
},
],
"attribute_set": {
"pk": 2,
"name": "Shoe"
}
}
]
}
GET
List All Addable Products for a Collection
GET
List All Addable Products for a CollectionPath: /api/v1/product_collections/{product-collection-pk}/product_list/
The endpoint where the products that can be added in the collection are listed. Listing is done by calling the product_list
method of the ProductCollectionViewSet
.
Response:
{
"count": 758,
"next": "api/v1/product_collections/1357/product_list/?limit=1&page=2",
"previous": null,
"results": [
{
"pk": 3,
"name": "Guitar",
"base_code": "1020583",
"sku": "1020583031",
"product_type": {
"value": "0",
"label": "Simple"
},
"is_active": true,
"parent": null,
"attributes": {},
"attributes_kwargs": {},
"extra_attributes": {},
"active_catalog_item": {
"pk": 3383,
"active_collection_item": null
},
"active_price": {
"pk": 39,
"price": "120.00",
"currency_type": "usd"
},
"active_stock": {
"pk": 1,
"stock": 83,
"unit_type": "qty"
},
"active_categories": [
{
"pk": 67,
"category": {
"pk": 4,
...
}
}
],
"productimage_set": [],
"attribute_set": {
"pk": 151,
"name": "New feature set"
}
}
]
}
Last updated
Was this helpful?