restore composer.json, add mysqli extension
This commit is contained in:
@@ -1,15 +1,56 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.vendors.models import VendorproductModel, VendorModel, CategoryModel, SectionModel
|
||||
from core.apps.vendors.models import (
|
||||
VendorproductModel,
|
||||
VendorModel,
|
||||
CategoryModel,
|
||||
SectionModel,
|
||||
ProductVariantModel,
|
||||
ProductAttributeModel
|
||||
)
|
||||
|
||||
|
||||
from core.apps.vendors.serializers.vendor_product.ProductImage import ListProductimageSerializer
|
||||
|
||||
|
||||
class ProductVariantSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductVariantModel
|
||||
fields = [
|
||||
"id",
|
||||
"firestore_id",
|
||||
"price",
|
||||
"sku",
|
||||
"quantity",
|
||||
"image_url",
|
||||
"attribute_data",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
attr_data = ret.get("attribute_data")
|
||||
|
||||
if attr_data and isinstance(attr_data, list):
|
||||
# Resolve attribute names
|
||||
resolved_data = []
|
||||
for item in attr_data:
|
||||
if isinstance(item, dict):
|
||||
a_id = item.get("attribute_id")
|
||||
if a_id:
|
||||
# Try to get the name from the cache or DB
|
||||
attr_obj = ProductAttributeModel.objects.filter(firestore_id=a_id).first()
|
||||
item["attribute_name"] = attr_obj.name if attr_obj else "Unknown"
|
||||
resolved_data.append(item)
|
||||
ret["attribute_data"] = resolved_data
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
class BaseVendorproductSerializer(serializers.ModelSerializer):
|
||||
category = serializers.SlugRelatedField(slug_field='firestore_id', queryset=CategoryModel.objects.all(), required=False, allow_null=True)
|
||||
section = serializers.SlugRelatedField(slug_field='firestore_id', queryset=SectionModel.objects.all(), required=False, allow_null=True)
|
||||
images = ListProductimageSerializer(many=True, read_only=True)
|
||||
variants = ProductVariantSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = VendorproductModel
|
||||
@@ -27,7 +68,9 @@ class BaseVendorproductSerializer(serializers.ModelSerializer):
|
||||
"is_publish",
|
||||
"image",
|
||||
"images",
|
||||
"variants",
|
||||
"photos_json",
|
||||
"product_specification",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
||||
Reference in New Issue
Block a user