Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Override get_price_range method in product
Mira26dffdf11ed7
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.pyindex ee28442672..56f617f0ef 100644--- a/saleor/product/models/base.py+++ b/saleor/product/models/base.py@@ -16,6 +16,7 @@ from django.utils import sixfrom django_prices.models import PriceFieldfrom mptt.managers import TreeManagerfrom mptt.models import MPTTModel+from prices import PriceRangefrom satchless.item import InsufficientStock, Item, ItemRangefrom text_unidecode import unidecode@@ -201,6 +202,12 @@ class Product(models.Model, ItemRange, index.Indexed):def set_attribute(self, pk, value_pk):self.attributes[smart_text(pk)] = smart_text(value_pk)+ def get_price_range(self, **kwargs):+ if not self.variants.exists():+ return PriceRange(self.price, self.price)+ else:+ return super(Product, self).get_price_range(**kwargs)+@python_2_unicode_compatibleclass ProductVariant(models.Model, Item):diff --git a/saleor/product/utils.py b/saleor/product/utils.pyindex cf128249fe..59911f341e 100644--- a/saleor/product/utils.py+++ b/saleor/product/utils.py@@ -55,15 +55,6 @@ ProductAvailability = namedtuple(def get_availability(product, discounts=None, local_currency=None):- if not product.variants.exists():- return ProductAvailability(- available=False,- price_range=None,- price_range_undiscounted=None,- discount=None,- price_range_local_currency=None,- discount_local_currency=None)-# In default currencyprice_range = product.get_price_range(discounts=discounts)undiscounted = product.get_price_range()diff --git a/saleor/static/js/components/categoryPage/ProductPrice.js b/saleor/static/js/components/categoryPage/ProductPrice.jsindex 4c5fdceac4..c420e19f13 100644--- a/saleor/static/js/components/categoryPage/ProductPrice.js+++ b/saleor/static/js/components/categoryPage/ProductPrice.js@@ -6,11 +6,10 @@ import SaleImg from '../../../images/sale_bg.svg';const ProductPrice = ({ availability, price }) => {const { discount, priceRange } = availability;const isPriceRange = priceRange && priceRange.minPrice.gross !== priceRange.maxPrice.gross;- const priceLocalized = priceRange ? priceRange.minPrice.grossLocalized : price.grossLocalized;return (<div><span itemProp="price">- {isPriceRange && <span>{gettext('from')} </span>} {priceLocalized}+ {isPriceRange && <span>{gettext('from')} </span>} {priceRange.minPrice.grossLocalized}</span>{discount && (<div className="product-list__sale"><img src={SaleImg}/><span>{gettext('Sale')}</span></div>