Products
Tasks related to product integration under channel_app_template.app.tasks
.
1. Insert Products
This task retrieves the products that need to be inserted into the sales side of Akinon for the first time and sends these products to the command located at channel.commands.products.SendInsertedProducts
. This command generates product information for the sales channel.
If desired, the product data can be enriched with the parameter values listed below.
The parameters and their descriptions for the insert_products
service within ProductService are as follows:
NOTE
Parameters for the insert_products
service within Product Service
- add_mapped: Mapping information is added to the product data. Mapping Data in the Product.
- add_stock: Product stock information is added to the product data. Stock Data in the Product.
- add_price: Product price information is added to the product data. Price Data in the Product.
- add_categories: Product category information is added to the product data. Category Data in the Product.
- is_sync: Indicates whether the status is obtained immediately when the product is sent to the sales channel. It specifies whether the process is Synchronous or Asynchronous.
class SendInsertedProducts(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the data to be sent in the request for transmitting products from Omnitron to the sales channel. The response should return a list of products.
transform_data(data)
This function takes the response from the validated_data
function as a parameter. It is used when changes need to be made to the data before sending it to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This function takes the response from the transform_data
function as a parameter. It sends the data to the relevant endpoint of the sales channel. The response should return either the response itself or the data received with the response.
Note
Care should be taken regarding data types when returning data, as the response will be passed to the normalize_response
function.
normalize_response(data, validated_data, transformed_data, response)
This function is where we gather and finalize the data used to transmit our products to the sales channel during the insert_product
step. The response from this function will be directly used in the insert_products
function.
If the process is asynchronous, the remote_batch_id
returned from the sales channel should be processed in the batch_request
.
remote_batch_id = response.get("remote_batch_request_id")
self.batch_request.remote_batch_id = remote_batch_id
return "", report, data
Note
The response returned from this part must consist of three components:
- response_data: This is the processed data returned from the sales channel. It can be of type string or list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the response is to be used, it must be of list type, and the elements within it must be of type
ProductBatchRequestResponseDto
. - report: These are the error reports created while processing the response from the sales channel.
- data: This is the first parameter our function receives, which is the response from the
get_data
function.
Example return:
return response_data, report, data
2. Update Products
This function retrieves products that have previously been inserted into Akinon but need to be updated. It sends these products to the command channel.commands.products.SendUpdatedProducts
. This command updates the existing product information in the sales channel.
If needed, the product data can be enriched with the parameter values listed below.
The parameters and explanations for the update_products
service within ProductService
are as follows:
NOTE
Parameters for the update_products
service within Product Service
- add_mapped: Mapping information is added to the product data. Mapping Data in the Product.
- add_stock: Product stock information is added to the product data. Stock Data in the Product.
- add_price: Product price information is added to the product data. Price Data in the Product.
- add_categories: Product category information is added to the product data. Category Data in the Product.
- is_sync: Indicates whether the status is obtained immediately when the product is sent to the sales channel. It specifies whether the process is Synchronous or Asynchronous.
class SendUpdatedProducts(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the data to be sent in the request for transmitting updates from Omnitron to the sales channel for the products that have been sent. The response should return a list of products.
validated_data(data)
This function takes the response from the get_data
function as a parameter. It is used when there is a need to validate the products to be updated in the sales channel. If no validation is required, it should return the data passed as a parameter.
transform_data(data)
This function takes the response from the validated_data
function as a parameter. It is used when changes need to be made to the data before sending it to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This function takes the response from the transform_data
function as a parameter. It sends the data to the relevant endpoint of the sales channel. The response should return either the response itself or the data received with the response.
Note
Care should be taken regarding data types when returning data, as the response will be passed to the normalize_response
function.
normalize_response(data, validated_data, transformed_data, response)
This function is where we gather and finalize the data used to update our products in the sales channel during the update_product
step. The response from this function will be directly used in the update_products
function.
If the process is asynchronous, the remote_batch_id
returned from the sales channel should be processed in the batch_request
.
remote_batch_id = response.get("remote_batch_request_id")
self.batch_request.remote_batch_id = remote_batch_id
return "", report, data
Note
The response returned from this part must consist of three components:
- response_data: This is the processed data returned from the sales channel. It can be of type string or list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the response is to be used, it must be of list type, and the elements within it must be of type
ProductBatchRequestResponseDto
. - report: These are the error reports created while processing the response from the sales channel.
- data: This is the first parameter our function receives, which is the response from the
get_data
function.
Example return:
return response_data, report, data
3. Delete Products
This function retrieves products that have previously been inserted into Akinon but are requested to be deleted. It sends these products to the command channel.commands.products.SendDeletedProducts
. This command deletes the existing products in the sales channel.
If needed, the execution of the command can be enriched with the following parameter:
- is_sync: Indicates whether the deletion status is obtained immediately when the product is sent to the sales channel. It specifies whether the process is synchronous or asynchronous.
class SendDeletedProducts(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the data to be sent in the request for transmitting the products to be deleted from Omnitron to the sales channel. The response should return a list of products.
validated_data(data)
This function takes the response from the get_data
function as a parameter. It is used when there is a need to validate the products to be deleted in the sales channel. If no validation is required, it should return the data passed as a parameter.
transform_data(data)
This function takes the response from the validated_data
function as a parameter. It is used when changes need to be made to the data before sending it to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This function takes the response from the transform_data
function as a parameter. It sends the data to the relevant endpoint of the sales channel. The response should return either the response itself or the data received with the response.
Note
This part requires careful attention to data types when returning data, as the response will be passed to the normalize_response
function.
normalize_response(data, validated_data, transformed_data, response)
This function is where we gather and finalize the data used to convey the information that products have been deleted to the sales channel during the delete_product
step. The response from this function will be directly used in the delete_products
function.
If the process is asynchronous, the remote_batch_id
returned from the sales channel should be processed in the batch_request
.
remote_batch_id = response.get("remote_batch_request_id")
self.batch_request.remote_batch_id = remote_batch_id
return "", report, data
Note
The response returned from this section must consist of three components:
- response_data: This is the processed data returned from the sales channel. It can be of type string or list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the response is to be used, it must be of list type, and the elements within it must be of type
ProductBatchRequestResponseDto
. - report: These are the error reports created while processing the response from the sales channel.
- data: This is the first parameter our function receives, which is the response from the
get_data
function.
Example return:
return response_data, report, data
4. Check Delete Products
This function sends previously requested deletions to the sales channel for products whose deletion status is unknown due to asynchronous processing. It uses the command in channel.commands.products.CheckDeletedProducts
to inquire about the status of deletion requests sent to the sales channel.
class CheckDeletedProducts(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the necessary data to check the status of deletion requests sent to the sales channel. It should return a BatchRequest
as a response.
validated_data(data)
This function takes the response from the get_data
function as a parameter. It is used to validate products for which the deletion status is being queried. If no validation is needed, it should return the given data.
transform_data(data)
This function takes the response from the validated_data
function as a parameter. It is used if any modifications are needed before sending data to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This function takes the response from the transform_data
function as a parameter. It is the endpoint where the data is sent to the sales channel. It should return either the response or the data received with the response.
Note
Care should be taken regarding data types when returning data, as this part will be passed to the normalize_response
function.
normalize_response(data, validated_data, transformed_data, response)
This function gathers and finalizes the data used to read whether products have been deleted during the check_delete_products
step. The response from this function will be directly used in the delete_products
function.
Note
The response returned from this section must consist of three components:
- response_data: This is the processed data returned from the sales channel. It can be of type string or list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the response is to be used, it must be of list type, and the elements within it must be of type
ProductBatchRequestResponseDto
. - report: These are the error reports created while processing the response from the sales channel.
- data: This is the first parameter our function receives, which is the response from the
get_data
function.
Example return:
return response_data, report, data
5. Check Products
This function sends products for which creation or update requests were previously made to Akinon’s sales side but for which the results are unknown due to asynchronous processing. It uses the command in channel.commands.products.CheckProducts
to inquire about the status of the creation or update requests sent to the sales channel.
class CheckProducts(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the necessary data to check the status of creation or update requests sent to the sales channel. It should return a BatchRequest
as a response.
validated_data(data)
This function takes the response from the get_data
function as a parameter. It is used if there needs to be validation on the BatchRequest
for which the creation or update status is being queried. If no validation is needed, it should return the given data.
transform_data(data)
This function takes the response from the validated_data
function as a parameter. It is used if any modifications are needed before sending data to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This function takes the response from the transform_data
function as a parameter. It is the endpoint where the data is sent to the sales channel. It should return either the response or the data received with the response.
Note
Care should be taken regarding data types when returning data, as this part will be passed to the normalize_response
function.
normalize_response(data, validated_data, transformed_data, response)
This function gathers and finalizes the data used to read whether products have been created or updated during the check_products
step. The response from this function will be directly used in the get_product_batch_requests
function.
Note
The response returned from this section must consist of three components:
- response_data: This is the processed data returned from the sales channel. It can be of type string or list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the response is to be used, it must be of list type, and the elements within it must be of type
ProductBatchRequestResponseDto
. - report: These are the error reports created while processing the response from the sales channel.
- data: This is the first parameter our function receives, which is the response from the
get_data
function.
Example return:
return response_data, report, data
Source Code
Source Code of the channel.commands.products Item:
from typing import List, Tuple, Any
from channel_app.channel.commands.products import (
SendInsertedProducts as AppSendInsertedProducts,
SendUpdatedProducts as AppSendUpdatedProducts,
SendDeletedProducts as AppSendDeletedProducts,
CheckProducts as AppCheckProducts,
CheckDeletedProducts as AppCheckDeletedProducts
)
from channel_app.core.data import (
ProductBatchRequestResponseDto,
ErrorReportDto
)
from omnisdk.omnitron.models import Product, BatchRequest
class SendInsertedProducts(AppSendInsertedProducts):
param_sync = True
def get_data(self) -> List[Product]:
raise NotImplementedError
def validated_data(self, data) -> object:
raise NotImplementedError
def transform_data(self, data) -> object:
raise NotImplementedError
def send_request(self, transformed_data) -> object:
raise NotImplementedError
def normalize_response(self, data, validated_data, transformed_data,
response) -> Tuple[
List[ProductBatchRequestResponseDto],
List[ErrorReportDto],
Any]:
raise NotImplementedError
class SendUpdatedProducts(AppSendUpdatedProducts):
param_sync = True
def get_data(self) -> List[Product]:
raise NotImplementedError
def validated_data(self, data) -> object:
raise NotImplementedError
def transform_data(self, data) -> object:
raise NotImplementedError
def send_request(self, transformed_data) -> object:
raise NotImplementedError
def normalize_response(self, data, validated_data, transformed_data,
response) -> Tuple[ProductBatchRequestResponseDto,
ErrorReportDto, Any]:
raise NotImplementedError
class SendDeletedProducts(AppSendDeletedProducts):
param_sync = True
def get_data(self) -> List[Product]:
raise NotImplementedError
def validated_data(self, data) -> object:
raise NotImplementedError
def transform_data(self, data) -> object:
raise NotImplementedError
def send_request(self, transformed_data) -> object:
raise NotImplementedError
def normalize_response(self, data, validated_data, transformed_data,
response) -> Tuple[ProductBatchRequestResponseDto,
ErrorReportDto, Any]:
raise NotImplementedError
class CheckProducts(AppCheckProducts):
def get_data(self) -> BatchRequest:
raise NotImplementedError
def validated_data(self, data) -> object:
raise NotImplementedError
def transform_data(self, data) -> object:
raise NotImplementedError
def send_request(self, transformed_data) -> object:
raise NotImplementedError
def normalize_response(self, data, validated_data, transformed_data,
response) -> Tuple[List[ProductBatchRequestResponseDto],
ErrorReportDto, Any]:
raise NotImplementedError
class CheckDeletedProducts(AppCheckDeletedProducts):
def get_data(self) -> BatchRequest:
raise NotImplementedError
def validated_data(self, data) -> object:
raise NotImplementedError
def transform_data(self, data) -> object:
raise NotImplementedError
def send_request(self, transformed_data) -> object:
raise NotImplementedError
def normalize_response(self, data, validated_data, transformed_data,
response) -> Tuple[List[ProductBatchRequestResponseDto],
ErrorReportDto, Any]:
raise NotImplementedError