Features: 1) Add rating field to Product object with description and GraphQL schema; 2) Implement resolve_rating to fetch the rating value for Product;
Fixes: None; Extra: 1) Update field lists in `Product` meta to include `rating`.
This commit is contained in:
parent
fe6316dae1
commit
018d8ca8e0
1 changed files with 5 additions and 0 deletions
|
|
@ -501,6 +501,7 @@ class ProductType(DjangoObjectType):
|
|||
feedbacks_count = Int(description=_("number of feedbacks"))
|
||||
personal_orders_only = Boolean(description=_("only available for personal orders"))
|
||||
seo_meta = Field(SEOMetaType, description=_("SEO Meta snapshot"))
|
||||
rating = Float(description=_("rating value from 1 to 10, inclusive, or 0 if not set."))
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
|
|
@ -521,6 +522,7 @@ class ProductType(DjangoObjectType):
|
|||
"attribute_groups",
|
||||
"images",
|
||||
"price",
|
||||
"rating",
|
||||
)
|
||||
filter_fields = ["uuid", "name"]
|
||||
description = _("products")
|
||||
|
|
@ -528,6 +530,9 @@ class ProductType(DjangoObjectType):
|
|||
def resolve_price(self: Product, _info) -> float:
|
||||
return self.price or 0.0
|
||||
|
||||
def resolve_rating(self: Product, _info) -> float:
|
||||
return self.rating or 0.0
|
||||
|
||||
def resolve_feedbacks(self: Product, _info):
|
||||
if _info.context.user.has_perm("core.view_feedback"):
|
||||
return Feedback.objects.filter(order_product__product=self)
|
||||
|
|
|
|||
Loading…
Reference in a new issue