Skip to content

Product Serializer Documentation

Overview

This document provides detailed information on the ProductSerializer class and its related serializers. These serializers are designed to handle the product representation in an e-commerce application, including features like category relationships, color variants, reviews, ratings, wishlist functionality, and shop details.


ProductWishlistInProductSerializer

Purpose

Handles the serialization of product wishlist data.

Fields

  • id: The primary key of the wishlist entry.
  • user: The user who added the product to the wishlist.
  • is_wished: Indicates whether the product is wished.
  • created_at: Timestamp when the wishlist entry was created.

SpecificChildCategorySerializer

Purpose

Serializes data for a specific child category of a product.

Fields

  • id: The primary key of the category.
  • name: The name of the category.
  • slug: The URL-friendly identifier of the category.
  • description: A short description of the category.
  • banner_image: Banner image URL of the category.
  • thumbnail_image: Thumbnail image URL of the category.
  • created_at: Timestamp when the category was created.
  • updated_at: Timestamp when the category was last updated.

ParentCategoryWithAllAndSpecificChildSerializer

Purpose

Handles serialization for parent categories, including all children and a specific child category.

Fields

  • id: The primary key of the parent category.
  • name: The name of the parent category.
  • slug: The URL-friendly identifier of the parent category.
  • description: A short description of the parent category.
  • banner_image: Banner image URL of the parent category.
  • thumbnail_image: Thumbnail image URL of the parent category.
  • all_children: Serialized data for all child categories.
  • specific_child: Serialized data for a specific child category (if applicable).
  • created_at: Timestamp when the parent category was created.
  • updated_at: Timestamp when the parent category was last updated.

Method: get_specific_child

  • Checks if a product has a specific child category. Returns serialized data for that category.

ProductSerializer

Purpose

Handles the complete serialization of a product, including associated data like images, variants, categories, and reviews.

Fields

  • id: The primary key of the product.
  • name: The name of the product.
  • slug: The URL-friendly identifier of the product.
  • vendor: The vendor offering the product.
  • shop: The shop associated with the product.
  • price: The price of the product.
  • discount_percent: Discount percentage applied to the product.
  • discounted_price: Calculated discounted price.
  • description: A detailed description of the product.
  • is_featured: Indicates if the product is featured.
  • is_active: Indicates if the product is active.
  • images: Serialized data for product images.
  • video: Video URL associated with the product.
  • color_variants: Details of available color variants.
  • parent_category: Details of the parent category, including children.
  • average_rating: Average rating of the product.
  • total_reviews: Total number of reviews for the product.
  • rating_summary: Summary of ratings (e.g., counts of 5-star, 4-star ratings).
  • brand: The brand of the product.
  • color: The color of the product.
  • size: The size of the product.
  • fabric: The fabric of the product.
  • popularity: Popularity score of the product.
  • wishlisted: Details of users who have wishlisted the product.
  • collection: Details of the collection the product belongs to.
  • collection_id: ID of the collection (write-only field).
  • shop_details: Details of the shop offering the product.
  • created_at: Timestamp when the product was created.
  • updated_at: Timestamp when the product was last updated.

Methods

get_color_variants

  • Groups color variants based on availability and stock.
  • Returns detailed information on sizes, prices, and variant images.

get_shop_details

  • Fetches and returns details of the shop associated with the product.
  • Includes follower count and average ratings.

calculate_average_ratings

  • Calculates average ratings and a summary for each star level.

get_parent_category

  • Fetches details of the parent category, including children and a specific child category.

to_representation

  • Adds additional fields like discounted price and wishlist status to the serialized representation of a product.

Notes

  • Ensure proper context is provided to the serializers to fetch user-related data (e.g., wishlist and shop details).
  • Use ProductImageSerializer for serializing product images.
  • Use ChildCategorySerializer for serializing all children of a category.
  • Use SignatureCollection for managing product collections.