Product Price
Product Price Data
{
"pk": 2,
"product": 913,
"price": "62.44",
"price_list": 1,
"currency_type": "try",
"tax_rate": "8.00",
"retail_price": "249.75",
"extra_field": {},
"discount_percentage": "75.00",
"modified_date": "2017-01-23T18:29:23.716095Z"
}
In the data containing "productprice":
- The "product" part includes the product's PK in Omnitron.
- The "price" part contains the selling price.
- The "price_list" section has the ID information of the price list in Akinon.
- The "currency_type" part specifies the unit of the price information.
- The "tax_rate" section includes the tax rate.
- The "retail_price" part contains the store price of the product.
- The "discount_percentage" section provides information about the discount on the product.
- The "modified_date" indicates the last update date.
Tasks under channel_app_template.app.tasks related to product integration:
1. Insert Prices
This task retrieves Product Prices that need to be inserted for the first time into the sales side in Akinon sends this data to the command located in channel.commands.product_prices.SendInsertedPrices
. With this command, the product's price information is created in the sales channel. If desired, the price data can be enriched with the parameter values listed below.
The parameters and their explanations for the insert_product_prices
service within PriceService are as follows:
NOTE
Parameters for the insert_product_prices
service within Price Service:
- add_stock: Stock data is added to the product price. This means adding stock data to the product price data.
- add_product_objects: Product data is added to the product price. This means adding product data to the product price data.
- is_sync: Indicates whether the status is obtained immediately when the product price is sent to the sales channel. It specifies whether the process is Synchronous or Asynchronous.
classSendInsertedPrices(integration, objects=None, batch_request=None, **kwargs)
get_data()
This function prepares the data to be sent in the request for transmitting product price information from Omnitron to the sales channel. The response should return a list containing ProductPrice
.
validated_data(data)
This function takes the response returned by the get_data
function as a parameter. It is used if there is a need to validate the product prices being sent to the sales channel. If no validation is required, it should return the provided data as is.
transform_data(data)
This function takes the response returned by the validated_data
function as a parameter. It is used if changes need to be made to the data before sending it to the sales channel. It returns the final form of the data intended for transmission.
send_request(transformed_data)
This function takes the response returned by the transform_data
function as a parameter. It sends the provided data to the appropriate endpoint of the sales channel. It should return the response or the data received with the response.
NOTE
Since the response returned in this section will be passed to the normalize_response
function, care must be taken regarding data types when returning data.
normalize_response(data, validated_data, transformed_data, response)
This function gathers the data used to transmit our product prices to the sales channel during the insert_prices
step and finalizes it. The response from this function will be directly used in the insert_product_prices
function.
If the process is asynchronous, the remote_batch_id
returned from the sales channel should be processed into 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 here should consist of three parts:
- response_data: The processed version of the data returned from the sales channel. It can be a string or a list. If there is no data to be used in the returned response, returning an empty string is sufficient. If the returned response is to be used, it must be of type list, and its elements must be of type
BatchRequestResponseDto
. - report: The error reports created while processing the response from the sales channel.
- data: The first parameter received by our function, which is the response from the
get_data
function.
Example return:
return response_data, report, data
2. Update Prices
It retrieves the Product Prices that need to be updated on the sales side in Akinon and sends this data to the command located in channel.commands.product_prices.SendUpdatedPrices
. This command updates the price information of the product in the sales channel.
If desired, the Price Data can be enriched with the parameter values listed below.
The parameters and their descriptions related to the update_product_prices
service in PriceService are as follows.
NOTE
Parameters for the insert_product_prices
service within Price Service:
- add_stock: Stock data is added to the product price. This means adding stock data to the product price data.
- add_product_objects: Product data is added to the product price. This means adding product data to the product price data.
- is_sync: Indicates whether the status is obtained immediately when the product price is sent to the sales channel. It specifies whether the process is Synchronous or Asynchronous.
class SendUpdatedPrices(integration, objects=None, batch_request=None,kwargs)
get_data() In this function, the data to be sent in the request to relay the updated price information of products from Omnitron to the sales channel is prepared. The response must return a list containing ProductPrice.
validated_data(data)
This method takes the response returned by the get_data
function as a parameter. It is used if a validation needs to be performed on the product prices to be sent to the sales channel. If no validation is needed, the method should return the provided data
.
transform_data(data)
This method accepts the response returned by the validated_data
function as a parameter. It is used if modifications to the data are required before sending it to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This method takes the response returned by the transform_data
function as a parameter. It sends the data to the relevant endpoint of the sales channel. It should return either a response or the data that comes with the response.
NOTE
Since the response returned here will be passed to the normalize_response
function, care should be taken regarding data types when returning the data.
normalize_response(data, validated_data, transformed_data, response)
This function collects and finalizes the data we used to communicate the product prices to the sales channel in the update_prices
step. The response from this function will be directly used in the insert_product_prices
function.
If the process is asynchronous, the remote_batch_id
returned from the sales channel should be processed into 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 here must consist of three parts.
- response_data: The processed version of the data returned from the sales channel. It can be a string or a list. If there is no usable data in the returned response, returning an empty string is sufficient. If the response will be used, it must be of list type, and the items in it must be of type
BatchRequestResponseDto
. - report: The error reports created while processing the response from the sales channel.
- data: The first parameter received by our function, the response from the
get_data
function.
Example return:
return response_data, report, data
3. Check Prices
This function retrieves updated or created Batch Requests that are unknown in status asynchronously from Akinon and sends this data to the command located in channel.commands.product_prices.CheckPrices
. This command allows for checking whether the product price in the sales channel has been created or updated.
If desired, the Price Data can be enriched with the parameter values listed below.
The get_price_batch_requests
function in PriceService is used.
class CheckPrices(integration, objects=None, batch_request=None, kwargs)
get_data()
This function prepares the data to be sent in the request to check the status of the price information that has been sent to the sales channel. The response must return a list containing BatchRequest.
validated_data(data)
This method takes the response returned by the get_data
function as a parameter. It is used if validation needs to be performed on the product price data sent to the sales channel. If no validation is necessary, it should return the provided data
.
transform_data(data)
This method accepts the response returned by the validated_data
function as a parameter. It is used if modifications to the data are required before sending it to the sales channel. It returns the final version of the data to be sent.
send_request(transformed_data)
This method takes the response returned by the transform_data
function as a parameter. It sends the data to the relevant endpoint of the sales channel. It should return either a response or the data that comes with the response.
NOTE
Since the response returned here will be passed to the normalize_response
function, care should be taken regarding data types when returning the data.
normalize_response(data, validated_data, transformed_data, response)
This function gathers and finalizes the data we used to query the processing status of our product prices in the get_price_batch_requests
step. The response from this function will be directly used in the get_price_batch_requests
function.
NOTE
The response returned here must consist of three parts.
- response_data: The processed version of the data returned from the sales channel. It can be a string or a list. If there is no usable data in the returned response, returning an empty string is sufficient. If the response will be used, it must be of list type, and the items in it must be of type
BatchRequestResponseDto
. - report: The error reports created while processing the response from the sales channel.
- data: The first parameter received by our function, the response from the
get_data
function.
Example return:
return response_data, report, data
Adding Stock Data to Product Price Data
{
"pk": 2,
"product": 913,
"price": "62.44",
"price_list": 1,
"currency_type": "try",
"tax_rate": "8.00",
"retail_price": "249.75",
"extra_field": {},
"discount_percentage": "75.00",
"modified_date": "2017-01-23T18:29:23.716095Z",
"productstock": {
"pk": 1,
"product": 2250,
"stock": 46,
"stock_list": 1,
"unit_type": "qty",
"extra_field": {},
"sold_quantity_unreported": 0,
"modified_date": "2017-01-23T13:37:31.947171Z"
}
}
Adding Product Data to Product Price Data
{
"pk": 2,
"product": 913,
"price": "62.44",
"price_list": 1,
"currency_type": "try",
"tax_rate": "8.00",
"retail_price": "249.75",
"extra_field": {},
"discount_percentage": "75.00",
"modified_date": "2017-01-23T18:29:23.716095Z",
"product": {
"pk": 12227,
"name": "Red T-Shirt",
"base_code": "1KBATC0231",
"sku": "1KBATC0231001",
"product_type": "0",
"is_active": true,
"parent": null,
"attributes": {
"size": "34X34",
"color": "001",
"place_of_production": "Turkey",
"material": "%100 POLYESTER"
},
"productimage_set": [
{
"pk": 20044,
"status": "active",
"image": "http://localhost:8001/media/products/2021/10/17/12227/1bfe74b4-175e-4c1a-80f2-b355feae498c.jpg"
}
],
"attribute_set": 2,
"productization_date": "2017-01-23T16:40:58.578504Z"
}
}
Source Code
Source Code of the channel.commands.product_prices Item:
from typing import List, Tuple, Any
from channel_app.channel.commands.product_prices import (
SendUpdatedPrices as AppSendUpdatedPrices,
SendInsertedPrices as AppSendInsertedPrices,
CheckPrices as AppCheckPrices,
)
from channel_app.core.data import (
ErrorReportDto, BatchRequestResponseDto
)
from omnisdk.omnitron.models import BatchRequest, ProductPrice
class SendUpdatedPrices(AppSendUpdatedPrices):
param_sync = True
def get_data(self) -> List[ProductPrice]:
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[BatchRequestResponseDto],
ErrorReportDto, Any]:
raise NotImplementedError
class SendInsertedPrices(AppSendInsertedPrices):
param_sync = True
def get_data(self) -> List[ProductPrice]:
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[BatchRequestResponseDto],
ErrorReportDto, Any]:
raise NotImplementedError
class CheckPrices(AppCheckPrices):
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[BatchRequestResponseDto],
ErrorReportDto, Any]:
raise NotImplementedError