akeneo/data-generator-bundle
Installation:
composer require akeneo-labs/data-generator-bundle:~0.3
Register the bundle in app/AppKernel.php:
$bundles[] = new Pim\Bundle\DataGeneratorBundle\PimDataGeneratorBundle();
Prerequisites: Ensure Akeneo PIM (v1.3–1.6) is installed with channels, locales, and currencies preconfigured.
First Use Case: Generate base fixtures (attributes, families) and product CSV files separately:
# Step 1: Generate fixtures (e.g., attributes, families)
php bin/console pim:generate:fixtures config/fixtures.yaml
# Step 2: Generate product CSV (requires fixtures to exist)
php bin/console pim:generate:products-file config/products.yaml
Configuration Files:
Start with the example YAML templates in Resources/examples.
Two-Phase Generation:
# config/fixtures.yaml
data_generator:
output_dir: /tmp/fixtures/
entities:
attributes:
count: 100
identifier_attribute: "sku"
families:
count: 20
attributes_count: 50
# config/products.yaml
data_generator:
output_dir: /tmp/products/
entities:
products:
count: 5000
mandatory_attributes: [sku, name]
force_values: { brand: "TestBrand" }
Integration with Fixtures:
app/import/fixtures/ and update installer_data in config/config.yml:
installer_data:
attributes: ["/tmp/fixtures/attributes.csv"]
families: ["/tmp/fixtures/families.csv"]
Automated Testing:
// tests/Functional/DataGeneratorTest.php
public function testProductGeneration()
{
$this->generateFixtures('config/fixtures.yaml');
$this->generateProducts('config/products.yaml');
$this->assertFileExists('/tmp/products/products.csv');
}
CI/CD Pipelines:
# .github/workflows/deploy.yml
- name: Generate test data
run: |
php bin/console pim:generate:fixtures config/fixtures.yaml
php bin/console pim:generate:products-file config/products.yaml
name, text, address) for realistic data:
force_values:
description: "{{ sentence(5) }}" # Faker syntax
filled_attributes_count and categories_count to simulate real-world complexity.delimiter: ";"
Order Dependency:
Command "pim:generate:products-file" failed: Missing attribute "sku".pim:generate:fixtures first to populate attributes/families.Output Directory Permissions:
Failed to write to /tmp/fixtures/attributes.csv: Permission denied.output_dir is writable:
chmod -R 777 /tmp/fixtures
Faker Version Conflicts:
Class 'Faker\Provider\Base' not found.~1.4.0 in composer.json to match the bundle’s requirement.Locale/Channel Mismatches:
name_en_US).force_values:
name_en_US: "Product {{ randomNumber(1000) }}"
yaml-lint or php bin/console debug:config data_generator to check syntax.php bin/console pim:generate:products-file config/products.yaml --env=dev
count: 10) before scaling to 10,000+ products.Custom Faker Providers:
Extend Faker to add domain-specific data (e.g., ProductNameProvider):
// src/Akeneo/DataGeneratorBundle/Faker/ProductNameProvider.php
class ProductNameProvider extends \Faker\Provider\Base
{
public function productName() { ... }
}
Register it in config/services.yaml:
services:
Faker\Generator:
calls:
- [addProvider, ['@akeneo.data_generator.faker.product_name']]
Post-Generation Hooks: Use Symfony’s event system to process generated files:
// src/EventListener/DataGeneratorListener.php
class DataGeneratorListener implements KernelEvents
{
public function onKernelTerminate(KernelEvents::TERMINATE, Event $event)
{
if ($event->getRequest()->get('_route') === 'pim_generate_products_file') {
$this->postProcess('/tmp/products/products.csv');
}
}
}
Parallel Generation: For large datasets, split product generation into chunks using a loop:
for i in {1..10}; do
php bin/console pim:generate:products-file config/products_${i}.yaml
done
start_index:
Useful for paginated imports (e.g., start_index: 1000 for batch 2).force_values vs. mandatory_attributes:
force_values: Overrides any occurrence of the attribute.mandatory_attributes: Ensures the attribute is always filled (but with random data).families.attributes_count: 0, products may fail validation. Set a minimum (e.g., 2).How can I help you explore Laravel packages today?