Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Properly display price in local currency
Marcin Gębala6b7c702f4eab
diff --git a/saleor/product/utils.py b/saleor/product/utils.pyindex b35e6bc2c1..cf128249fe 100644--- a/saleor/product/utils.py+++ b/saleor/product/utils.py@@ -118,8 +118,8 @@ def products_for_cart(user):return products-def get_variant_picker_data(product, discounts=None):- availability = get_availability(product, discounts)+def get_variant_picker_data(product, discounts=None, local_currency=None):+ availability = get_availability(product, discounts, local_currency)variants = product.variants.all()data = {'variantAttributes': [], 'variants': []}@@ -135,18 +135,25 @@ def get_variant_picker_data(product, discounts=None):for variant in variants:price = variant.get_price_per_item(discounts)price_undiscounted = variant.get_price_per_item()+ if local_currency:+ price_local_currency = to_local_currency(price, local_currency)+ else:+ price_local_currency = Nonevariant_data = {'id': variant.id,'price': price_as_dict(price),'priceUndiscounted': price_as_dict(price_undiscounted),- 'attributes': variant.attributes}+ 'attributes': variant.attributes,+ 'priceLocalCurrency': price_as_dict(price_local_currency)}data['variants'].append(variant_data)data['availability'] = {'discount': price_as_dict(availability.discount),'priceRange': price_range_as_dict(availability.price_range),'priceRangeUndiscounted': price_range_as_dict(- availability.price_range_undiscounted)}+ availability.price_range_undiscounted),+ 'priceRangeLocalCurrency': price_range_as_dict(+ availability.price_range_local_currency)}return datadiff --git a/saleor/product/views.py b/saleor/product/views.pyindex f91157b554..3a861fcc22 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -62,7 +62,8 @@ def product_details(request, slug, product_id, form=None):type(product).__name__.lower(),)templates = [template_name, 'product/details.html']product_images = get_product_images(product)- variant_picker_data = get_variant_picker_data(product, request.discounts)+ variant_picker_data = get_variant_picker_data(+ product, request.discounts, request.currency)product_attributes = get_product_attributes_data(product)show_variant_picker = all([v.attributes for v in product.variants.all()])return TemplateResponse(diff --git a/saleor/static/js/components/variantPicker/VariantPrice.js b/saleor/static/js/components/variantPicker/VariantPrice.jsindex a151cc4dc3..98b531169c 100644--- a/saleor/static/js/components/variantPicker/VariantPrice.js+++ b/saleor/static/js/components/variantPicker/VariantPrice.js@@ -10,7 +10,7 @@ export default class VariantPrice extends Component {}render() {- let priceText, priceUndiscountedText, isDiscount;+ let priceText, priceUndiscountedText, priceLocalCurrency, isDiscount;const { availability, store } = this.props;const variant = store.variant;if (!store.isEmpty) {@@ -18,12 +18,18 @@ export default class VariantPrice extends Component {isDiscount = variant.price.gross !== variant.priceUndiscounted.gross;priceText = `${variant.price.grossLocalized}`;priceUndiscountedText = `${variant.priceUndiscounted.grossLocalized}`;+ if (variant.priceLocalCurrency) {+ priceLocalCurrency = variant.priceLocalCurrency.grossLocalized;+ }} else {// if there's no variant, fall back to product priceconst { discount, priceRange, priceRangeUndiscounted } = availability;isDiscount = discount && !!Object.keys(discount).length;priceText = `${priceRange.minPrice.grossLocalized}`;priceUndiscountedText = `${priceRangeUndiscounted.minPrice.grossLocalized}`;+ if (availability.priceRangeLocalCurrency) {+ priceLocalCurrency = availability.priceRangeLocalCurrency.minPrice.grossLocalized;+ }}return (<h2 itemProp="offers" className="product__info__price" itemScope itemType="http://schema.org/Offer">@@ -31,6 +37,9 @@ export default class VariantPrice extends Component {{isDiscount && (<small className="product__info__price__undiscounted">{priceUndiscountedText}</small>)}+ {priceLocalCurrency && (+ <p><small className="text-info">≈ {priceLocalCurrency}</small></p>+ )}</h2>);}diff --git a/templates/product/details.html b/templates/product/details.htmlindex 79b79e5ccf..6f7224d850 100644--- a/templates/product/details.html+++ b/templates/product/details.html@@ -82,7 +82,7 @@{% endif %}{% if availability.price_range_local_currency %}<br>- <small>+ <small class="text-info">≈{% gross availability.price_range_local_currency.min_price html=True %}</small>