DirectProductPurchaseSerializer Documentation
This section outlines the serializer used in the Direct Product Purchase API. The DirectProductPurchaseSerializer is responsible for handling the process of adding a product to the cart directly with a specified variant and size (if applicable), ensuring that the product, variant, and size are valid before proceeding with the purchase.
Serializers
- Direct Product Purchase Serializer:
DirectProductPurchaseSerializer
1. Direct Product Purchase Serializer
Serializer Overview
DirectProductPurchaseSerializer is used to handle direct product purchases by adding a product, optionally selecting a variant and size, and validating that the product, variant, and size exist and match the expected criteria.
Fields
| Field | Type | Description |
|---|---|---|
product_id |
integer |
The ID of the product to be purchased. |
variant_id |
integer |
The ID of the variant of the product (optional). |
size |
string |
The size of the product (optional, required if a variant is selected). |
quantity |
integer |
The quantity of the product to be purchased. |
is_direct_purchase |
boolean |
Indicates whether the purchase is for a direct purchase. |
Serializer Methods
-
DirectProductPurchaseSerializer.validate(self, attrs)- It checks if the product with the provided
product_idexists. - If a
variant_idis provided, it validates that the variant exists and belongs to the specified product. - If a
sizeis provided, it checks that the size exists and matches the selected variant (if applicable). - The validated attributes (
product,variant, andsize) are then added to the attrs dictionary for further use.
- It checks if the product with the provided