January 19, 2024

Magento 2 – Useful Commands for Developers – Part 2

Hey Magento devs, gather ’round! Today we’re diving into the lesser-known, yet incredibly useful world of Magento commands. Specifically, we’ll be exploring the setup:performance:generate-fixtures command – your secret weapon for generating tons of realistic dummy data on your local Magento setup.

Tired of Sample Data?

Let’s face it, Magento’s default sample data is helpful, but it’s limited. Sure, you get a few products and categories, but what about customers, orders, different product types, or complex rules? Testing with just a sprinkle of data simply doesn’t cut it.

bin/magento setup:performance:generate-fixtures

What does it do?

This command lets you configure and generate a vast array of dummy data, tailored to your testing needs. Think of it as your own personal data factory, churning out anything from simple products to complex configurable ones, even customers, orders, and promotions!

Why is it Useful?

It provides Magento developers with a robust mechanism to generate diverse and sizable datasets for testing purposes. This aids in fine-tuning code, analyzing performance, and ensuring seamless deployment on live servers. The command’s configurability and efficiency make it an indispensable tool in the arsenal of Magento developers striving for excellence in their development endeavors.

 

Introducing the Data Generator Powerhouse:

Enter setup:performance:generate-fixtures. This command lets you configure and generate a vast array of dummy data, tailored to your testing needs. Think of it as your own personal data factory, churning out anything from simple products to complex configurable ones, even customers, orders, and promotions!

Fine-Tuning the Data Flow:

The magic lies in the configuration files, found in setup/performance-toolkit/profiles/ce. There’s a range of pre-defined profiles like “small”, “medium”, and even “extra_large”. But the real power lies in creating your own custom profile.

Lets understand the xml file. Lets take small.xml for example.

				
					<admin_users>50</admin_users><!-- Number of admin users to generate -->
<websites>1</websites> <!-- Number of websites to generate -->
<store_groups>1</store_groups> <!--Number of stores-->
<store_views>1</store_views> <!-- Number of store views -->
<sources>1</sources> <!-- Number of sources to generate -->
<stocks>1</stocks> <!-- Number of stocks to generate -->
				
			

Here is the configuration to generate dummy data. You can pass how many admin_users you want to create or how many websites you want to generate.
The value set between the tags tells the data generator to generate the bulk amount.

Now, lets see the block which generates products. Here it is generating 800 simple products and 16 configurable products with two attributes and 3 and 8 attribute values respectively.

				
					<simple_products>800</simple_products> <!-- Simple products count -->
<configurable_products> <!-- Configurable product -->
	<config>
		<attributes>
			<attribute>
				<options>3</options>
				<swatches>image</swatches>
			</attribute>
			<attribute>
				<options>8</options>
			</attribute>
		</attributes>
		<sku>Configurable Product %s</sku>
		<products>16</products>
	</config>
</configurable_products>
				
			

Now, lets go ahead with generating other data as well.

				
					<categories>30</categories> <!-- Number of categories to generate -->
<categories_nesting_level>3</categories_nesting_level> <!-- Nesting level for categories -->
<customers>200</customers> <!-- Number of customers to generate -->

<catalog_price_rules>20</catalog_price_rules> <!-- Number of catalog price rules -->
<cart_price_rules>20</cart_price_rules> <!-- Number of cart price rules -->
<cart_price_rules_floor>2</cart_price_rules_floor>
<coupon_codes>20</coupon_codes> <!-- Number of coupon codes -->
		
<orders>80</orders> <!-- Orders count -->
				
			

Generating a Data Avalanche:

Once your custom profile is ready, simply run the command with its path:

				
					bin/magento setup:performance:generate-fixtures setup/performance-toolkit/profiles/ce/YOUR_FILE_NAME.xml
				
			

Sit back and watch the magic unfold! As the command executes, you’ll see each data type being generated, from admin users and websites to products and orders. And the best part? You’ll have a realistic, fully-fledged Magento environment to test your code to its limits.

Once the execution is complete, you will see an output like below.

				
					Generating profile with following params:
 |- Admin Users: 50
 |- Websites: 1
 |- Store Groups Count: 1
 |- Store Views Count: 1
 |- Categories: 30
 |- Attribute Sets (Default): 3
 |- Attribute Sets (Extra): 10
 |- Simple products: 800
 |- Configurable products: 16
 |- Product images: 100, 3 per product
 |- Customers: 200
 |- Cart Price Rules: 20
 |- Catalog Price Rules: 20
 |- Coupon Codes: 20
 |- Orders: 80
Config Changes...  done in 00:00:00
Generating admin users...  done in 00:00:00
Generating websites, stores and store views...  done in 00:00:00
Generating categories...  done in 00:00:00
Generating attribute sets...  done in 00:00:00
Generating simple products...  done in 00:00:00
Generating configurable EAV variations...  done in 00:00:00
Generating bundle products...  done in 00:00:00
Generating configurable products...  done in 00:00:00
Generating images...  done in 00:00:00
Generating customer groups...  done in 00:00:00
Generating customers...  done in 00:00:00
Generating cart price rules...  done in 00:00:03
Generating catalog price rules...  done in 00:00:00
Generating tax rates...  done in 00:00:01
Generating tax rules...  done in 00:00:00
Generating coupon codes...  done in 00:00:00
Generating orders...  done in 00:00:00
Optimize tables
Indexers Mode Changes...  done in 00:00:01
				
			

Beyond the Basics:

This command is just the tip of the iceberg. You can tweak and customize your profiles to generate specific data scenarios, test edge cases, and ensure your code performs flawlessly under even the most demanding conditions.


In essence, setup:performance:generate-fixtures provides Magento developers with a robust mechanism to generate diverse and sizable datasets for testing purposes. This aids in fine-tuning code, analyzing performance, and ensuring seamless deployment on live servers. The command’s configurability and efficiency make it an indispensable tool in the arsenal of Magento developers striving for excellence in their development endeavors.

So, Magento devs, what are you waiting for? Unleash the power of setup:performance:generate-fixtures and take your testing to the next level! Generate mountains of data, push your code, and build rock-solid Magento experiences with confidence.

Author

Share this post:
Facebook
Twitter
LinkedIn
WhatsApp

Discover more articles