Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Generate sample products with visible_in_listings set to False
IKarbowiak7b4b51bd0fa5
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 01ce764a8a..08f2ed22a0 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -209,10 +209,15 @@ def create_attributes_values(values_data):def create_products(products_data, placeholder_dir, create_images):- counter = 0# calculate threshold on 10% level that indicates the number of products# with available_for_purchase date in future- threshold = len(products_data) * 0.1+ purchase_threshold = len(products_data) * 0.1++ # calculate the threshold for setting visible_in_listings to False+ # for last 10% of products+ searchable_threshold = len(products_data) - purchase_threshold++ counter = 0for product in products_data:pk = product["pk"]# We are skipping products without images@@ -225,10 +230,15 @@ def create_products(products_data, placeholder_dir, create_images):defaults["product_type_id"] = defaults.pop("product_type")available_for_purchase = datetime.date.today()- if counter <= threshold:+ if counter <= purchase_threshold:available_for_purchase += datetime.timedelta(days=random.randrange(10, 365))defaults["available_for_purchase"] = available_for_purchase+ visible_in_listings = True+ if counter >= searchable_threshold:+ visible_in_listings = False+ defaults["visible_in_listings"] = visible_in_listings+product, _ = Product.objects.update_or_create(pk=pk, defaults=defaults)if create_images: