matusstafura / faker-commerce
A PHP lib to generate dummy data for ecommerce
Requires
- php: ^8.3
Requires (Dev)
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.2
README
Generates meaningful dummy data for ecommerce use — product names, categories, prices, reviews and more — where the popular fzaninotto/faker-style generators only give you generic words or lorem-ipsum text.
Requirements
PHP 8.3, 8.4, or 8.5.
Install the package
composer require matusstafura/faker-commerce
Usage
use FakerCommerce\Faker\FakerFactory; // Use a factory to initialize $faker = FakerFactory::create(); $faker->availability(); // "out of stock" $faker->breadcrumbs(4, ">"); // "Radio>Instruments>Materials & Supplies>Accessories" $faker->category(); // "Action Figures" $faker->color(); // "Coral" $faker->condition(); // "Very Good" $faker->name(); // "Quilted Leather Jacket" $faker->name(2); // "Cropped Denim Jacket" $faker->name(0); // "Jacket" (just the product type, no descriptors) $faker->attribute(); // "Chunky" $faker->type(); // "Cardigan" $faker->payment(); // "cash on delivery" $faker->price(); // "557.00" $faker->review(); // "Expensive for the quality." $faker->getAllMethods(); // lists all available methods, grouped by dataset class
Available generators
| Method | Returns |
|---|---|
availability() |
Stock status, e.g. "in stock" |
breadcrumbs(int $subcategories, string $separator) |
A category breadcrumb trail |
category() |
A single product category |
color() |
A CSS-style color name |
condition() |
A listing condition, e.g. "Like New" |
name(int $attributes = 1) |
A composed product name (attributes + type) |
attribute() |
A single material/style descriptor |
type() |
A single product type noun |
payment() |
A payment method |
price(int $min, int $max, int $decimals) |
A formatted price |
review() |
A product review sentence |
getAllMethods() |
Every available method, grouped by dataset |
Extending with your own datasets
Register a custom dataset class and its public methods become available on $faker too,
as long as none of its method names collide with an existing one:
use FakerCommerce\Faker\Dataset; use FakerCommerce\Faker\Faker; $dataset = new Dataset(); $dataset->addDataset(MyApp\Faker\Sku::class); $faker = new Faker($dataset->getDatasets()); $faker->sku();
addDataset() throws if the class doesn't exist, is already registered, or defines a
method name that already exists in another registered dataset.
Tests
Run the tests with Pest PHP
composer test
License
The MIT License (MIT). Please see License File for more information.
Contribution
Contributions are welcome and will be fully credited. Please, add tests if required.
Support
You can leave a star, or support ongoing development via GitHub Sponsors or Buy Me a Coffee.
Security
If you discover any security-related issues, please email us instead of using the issue tracker.
TODO
Please see TODO.md file.