Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Assing sorted prices to variants in populatedb
Mira Szewczyk4f4156caa128
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 54b38be5c5..615fa91266 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -189,9 +189,9 @@ def get_variant_combinations(product):for combination in all_combinations]-def get_price_override(schema):+def get_price_override(schema, n):if schema.get('different_variant_prices'):- return fake.price()+ return iter(sorted([fake.price() for _ in range(n)], reverse=True))def create_products_by_class(product_class, schema,@@ -210,10 +210,14 @@ def create_products_by_class(product_class, schema,create_product_images(product, random.randrange(1, 5), class_placeholders)variant_combinations = get_variant_combinations(product)+ prices = get_price_override(schema, len(variant_combinations))for i, attr_combination in enumerate(variant_combinations, 1337):sku = '%s-%s' % (product.pk, i)- create_variant(product, attributes=attr_combination,- price_override=get_price_override(schema), sku=sku)+ kwargs = {'attributes': attr_combination, 'sku': sku}+ if schema.get('different_variant_prices'):+ kwargs['price_override'] = next(prices)+ create_variant(product, **kwargs)+if not variant_combinations:# Create min one variant for products without variant level attrssku = '%s-%s' % (product.pk, fake.random_int(1000, 100000))