Pre-Product
Within the pre-product domain, two distinct product types will be taken into consideration: Pre-Product and Pre-Miscellaneous.
The products integrated into the system undergo serialization using the PreProductViewSet
before being inserted into the product table. During this insertion process, they are assigned either the values of ProductTypes.pre_product
or ProductTypes.pre_miscellaneous
for the Products.product_type
parameter.
A signal is generated with every commit made to the Product table, and these signals are monitored by the product_receiver {omnitron.products.receivers.product_receiver()}
. This receiver disregards commits with product types pre_product
and pre_miscellaneous
.
After every product commit that comes before actualization, it will be updated with PreProductViewSet
, and during the update process, it will be actualized based on the value of approved=True
.
pre_product
It is a simple product that comes before productization. When productized, it will take the value ProductTypes.simple
as the product_type
.
pre_miscellaneous
It is a non-saleable product that comes before productization. When productized, it will take the value ProductTypes.miscellaneous
as the product_type
. Non-saleable products can be found in the cart, but their direct sales are prohibited (for example, shopping bags).
Serializer
The PreProductSerializer {omnitron.products.resources.serializers.PreProductSerializer}
extends the ProductSerializer
, but it includes additional fields that are different from the ProductSerializer
and are not present in the model: approved:BooleanField
and run_product_mapping:NullBooleanField
.
approved: BooleanField
When this boolean field is true, the ProductService._approve_pre_product()
method will be invoked during the update process to productize pre-products.
run_product_mapping: NullBooleanField
This boolean field is nullable. When it is true, the ProductService._run_product_mapping()
method will be called during the update process to perform attribute mapping for products.
Mapping
During the creation or update of pre-products, if run_product_mapping
is set to True, they undergo a mapping process. The mapping process depends on the key values defined in settings.PRODUCT_MAPPING_KEY_LIST
and the language
value sent as kwargs during the update process or obtained from translation.get_language() {django.utils.translation.get_language()}
.
Here's a pseudo example we can create for the mapping process:
The attribute key named size_erp
of our product has been converted to the size
key through mapping, and its value has been mapped from "Large" to "Büyük".
Service
There is no separate service for pre-products; instead, all service operations are conducted through the ProductService {omnitron.products.service.ProductService}
. The service structure will be detailed in the product documentation.
ViewSet
The PreProductViewSet {omnitron.products.resources.views.PreProductViewSet}
is extended from ModelViewSet
, MultiSerializerViewSetMixin
, and FileFilterableViewSetMixin
, and it can be accessed via the /api/v1/pre_products
endpoint.
Inherited from ModelViewSet
, it allows GET
, POST
, PUT
, PATCH
, and DELETE
methods. The perform_create()
and perform_update()
functions are overridden to perform create/update operations on the relevant service, ProductService
.
Inherited from MultiSerializerViewSetMixin
, it includes the detailed()
and detailed_list()
functions but does not override them. Within the serializer_action_classes
, ProductDetailedSerializer
is defined for both detailed
and detailed_list
.
Inherited from FileFilterableViewSetMixin
, it includes the filter_queryset()
, filter_import_queryset()
, and initialize_request()
functions but does not override them. It holds the file_filter_fieldname:List
list, which is used to intersect with the header fields of uploaded files in FileFilterableViewSetMixin
.
HTTP Methods
GET
Get List of All Pre-Products
GET
Get List of All Pre-ProductsPath: /api/v1/pre_products/
This method retrieves the products that fulfil the condition product_type__in=[ProductTypes.pre_product, ProductTypes.pre_miscellaneous]
from the Product table. It takes filter parameters found in ProductFilter {omnitron.products.resources.filters.ProductFilter}
as query parameters and has a wide range of filtering options.
Example Request
Example Response
POST
Create a Single Pre-Product
POST
Create a Single Pre-ProductPath: /api/v1/pre_products/
This method records new objects to the Products table. It's validated with PreProductSerializer
; if the data is not appropriate or the product_type
value is neither ProductTypes.pre_product
nor ProductTypes.pre_miscellaneous
, an HTTP 404 error is returned. The flawless data is sent to the ProductService.create_product()
method for processing, and the service executes the recording operation.
Example Request
Example Response
DELETE
Delete a Single Pre-Product
DELETE
Delete a Single Pre-ProductPath: /api/v1/pre_products/{pk}/
This method deletes the object from the Products table corresponding to the relevant primary key. An HTTP 404 error is returned if the object cannot be found.
Example Request
Example Response
GET
Get a Single Pre-Product
GET
Get a Single Pre-ProductPath: /api/v1/pre_products/{pk}/
This method retrieves the object from the Products table corresponding to the relevant primary key. An HTTP 404 error is returned if the object cannot be found.
Example Request
Example Response
PATCH
Update a Single Pre-Product
PATCH
Update a Single Pre-ProductPath: /api/v1/pre_products/{pk}/
This method partially updates the object from the Products table corresponding to the relevant primary key. It's validated with PreProductSerializer
; if the data is not appropriate or the product_type
value is neither ProductTypes.pre_product
nor ProductTypes.pre_miscellaneous
, an HTTP 404 error is returned. An HTTP 404 error is returned if the object cannot be found. The partial update method updates only the parameters sent as data.
PUT
Update a Single Pre-Product
PUT
Update a Single Pre-ProductPath: /api/v1/pre_products/{pk}/
This method updates the object from the Products table corresponding to the relevant primary key. It's validated with PreProductSerializer
; if the data is not appropriate or the product_type
value is neither ProductTypes.pre_product
nor ProductTypes.pre_miscellaneous
, an HTTP 404 error is returned. An HTTP 404 error is returned if the object cannot be found. The update method updates the entire object. The flawless data is sent to the ProductService.update_product()
method for processing, and the service executes the update operation.
POST
Bulk Create Pre-Products
POST
Bulk Create Pre-ProductsPath: /api/v1/pre_products/bulk_create/
This method asynchronously creates new objects in the Products table in bulk with an uploaded CSV or Excel file. Each creation process is delayed as a separate task. Since each task handles its own serialization, if there's an error, only the task that encountered the error will fail.
This method accepts formdata as a request and includes the path of the CSV or Excel file as filename
. As a response, it returns the cache_key
parameter stored in Redis for async tasks. In the creation process, the sku
parameter is mandatory and must be present in the file.
Example Request
Example Response
GET
Bulk Create Cache Key Status
GET
Bulk Create Cache Key StatusPath: /api/v1/pre_products/{cache_key}/bulk_create_status/
This method queries the status of an executed bulk create operation.
Example Request
Example Response
POST
Bulk Update Pre-Products
POST
Bulk Update Pre-ProductsPath: /api/v1/pre_products/bulk_update/
This method asynchronously updates objects in the Products table in bulk with an uploaded CSV or Excel file. Each update process is delayed as a separate task. Since each task handles its own serialization, if there's an error, only the task that encountered the error will fail.
This method accepts formdata as a request, and the path of the CSV or Excel file is sent within the filename
parameter. As a response, it returns the cache_key
parameter stored in Redis for async tasks. The update operation is performed similar to partial update based on the "sku" parameter in the file, updating only the parameters sent as data.
Example Request
Example Response
GET
Bulk Update Cache Key Status
GET
Bulk Update Cache Key StatusPath: /api/v1/pre_products/{cache_key}/bulk_update_status/
This method queries the status of an executed bulk update operation.
Example Request
Example Response
GET
Get List of All Pre-Products - Detailed
GET
Get List of All Pre-Products - DetailedPath: /api/v1/pre_products/detailed/
This method retrieves products from the Product table that fulfil the condition product_type__in=[ProductTypes.pre_product, ProductTypes.pre_miscellaneous]
. It uses ProductDetailedSerializer
instead of PreProductSerializer
, and in this ViewSet, it's specified as detailed_list
within the serializer_action_classes
inherited from MultiSerializerViewSetMixin
.
It takes filter parameters found in ProductFilter {omnitron.products.resources.filters.ProductFilter}
as query parameters and has a wide range of filtering options.
GET
Get a Single Pre-Product - Detailed
GET
Get a Single Pre-Product - DetailedPath: /api/v1/pre_products/{pk}/detailed/
This method retrieves the object from the Product table corresponding to the relevant primary key. An HTTP 404 error is returned if the object cannot be found. It uses ProductDetailedSerializer
instead of PreProductSerializer
, and in this ViewSet, it's specified as detailed within the serializer_action_classes
inherited from MultiSerializerViewSetMixin
.
Last updated
Was this helpful?