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.
Model(omnitron.promotions.models.ProductCollection)
The ProductCollection
model has been defined under omnitron.promotions.models.ProductCollection.
This model is inherited from models StarterModel
and BaseProductCollection
. As mentioned above the collection_type
field may be Dynamic or Static. Additionally, defaults field checks that the product is ready for sale. The ProductCollectionSerializer
class defined at omnitron.channels.integrations.omniweb.serializers
is used to validate the data.
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
is_active = models.BooleanField(default=True)
sort_option = models.ForeignKey('search.SortOption', null=True, blank=True)
expiration_date = models.DateTimeField(null=True, blank=True)
uuid = models.UUIDField(default=uuid.uuid4, unique=True)
collection_type = EnumField(ProductCollectionType)
catalog = models.ForeignKey('catalogs.Catalog')
kwargs = JSONField(default=dict)
defaults = {
'active_catalog_item__isnull': [False],
'active_price__isnull': [False],
'active_stock__isnull': [False],
}
Filter(omnitron.promotions.resources.filters.ProductCollectionFilter)
It serves to filter the data registered in the system with certain features. The filter list and its usage are as follows:
- created_date
- expiration_date
- collection_type
- catalog
The created_date
and expiration_date
fields can be filtered with a time range, expiration_date
has an additional lookup field that is null. Filtering can be done with multiple catalog
and collection_type
. Creation date and expiry date lookups are as follows:
lookups = [gt', 'gte', 'lt', 'lte','dategt', 'dategte',datelt', 'datelte']
Filter(omnitron.products.resources.filters.ProductFilter)
It serves to filter the data registered in the system with certain features. Filtering is available for each model and field that is linked to the ProductFilter
model. ProductCollectionViewSet
has some filter action classes like item_list
, product_list
, product_list_bulk_create
and item_list_bulk_delete
so that ProductFilter
is used for all these endpoints. It provides filtering with product fields like ID and SKU.
ViewSet(omnitron.promotions.resources.views.ProductCollectionViewSet)
create
, update
and delete
operations are linked to the service. They also have the item_list and product_list endpoints. To be able to work on ProductCollection, the user must have Catalog Authorization Group
. All ProductCollection
objects returning over the Viewset are filtered according to the catalog authorization group owned by the user. This is so that the user cannot access any catalog collections without authorization.
Example Request & Response
GET
Product Collection
Sample 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
Records 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
Allows 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
Allows 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
Allows 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
Update 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
With 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
Path: /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
Path: /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"
}
}
]
}