-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example how to show the price in the ProductList view§
- Loading branch information
Martijn Jacobs
committed
Dec 18, 2017
1 parent
4e498ad
commit 03a9e56
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
from rest_framework import serializers | ||
|
||
from oscar.core.loading import get_class | ||
|
||
from oscarapi.serializers.checkout import PriceSerializer | ||
from oscarapi.serializers.product import ( | ||
ProductImageSerializer, ProductLinkSerializer) | ||
ProductImageSerializer, ProductLinkSerializer | ||
) | ||
|
||
|
||
Selector = get_class('partner.strategy', 'Selector') | ||
|
||
|
||
class MyProductLinkSerializer(ProductLinkSerializer): | ||
images = ProductImageSerializer(many=True, required=False) | ||
price = serializers.SerializerMethodField() | ||
|
||
class Meta(ProductLinkSerializer.Meta): | ||
fields = ('url', 'id', 'title', 'images') | ||
fields = ('url', 'id', 'title', 'images', 'price') | ||
|
||
def get_price(self, obj): | ||
request = self.context.get("request") | ||
strategy = Selector().strategy( | ||
request=request, user=request.user) | ||
ser = PriceSerializer( | ||
strategy.fetch_for_product(obj).price, | ||
context={'request': request}) | ||
return ser.data |