Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestashop/prestashop-shop-creator
Generate random demo data to test your PrestaShop shop.
https://github.com/prestashop/prestashop-shop-creator
data fixture-generator generator hacktoberfest prestashop random shop
Last synced: 4 months ago
JSON representation
Generate random demo data to test your PrestaShop shop.
- Host: GitHub
- URL: https://github.com/prestashop/prestashop-shop-creator
- Owner: PrestaShop
- Created: 2017-12-05T08:23:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-12T09:54:10.000Z (7 months ago)
- Last Synced: 2024-10-07T10:58:14.294Z (4 months ago)
- Topics: data, fixture-generator, generator, hacktoberfest, prestashop, random, shop
- Language: PHP
- Homepage:
- Size: 237 KB
- Stars: 24
- Watchers: 19
- Forks: 13
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
About PrestaShop Shop Generator
--------The shop generator generates a list of folders & xml files into 'generated_data' dir which should be copied in the
/install/fixtures/fashion directory of PrestaShop, to generate at the installation a shop initialized with the specified
number of entities.> [!NOTE]
> In 2023, we attempted to fix multiple issues regarding this tool. Sadly, we found out its design (using XML files as output) made it very hard to output a controlled format.
> Another way to load heavy loads of data into a shop is being tried on this repository: [PrestaShop/ps_fixturescreator](https://github.com/PrestaShop/ps_fixturescreator)Installation & configuration
--------To setup the configuration of the module, just run
```
composer install
```
This will generates a configuration file in app/config/config.ymlHow to run the script
--------
```
php app/console.php
```
Make sure to have enough memory allocated to php, as it could eat a lot of memory depending on the number of entities
you want to generateEntity Model syntax
--------
Each entity model is described in the src/Model directory.If you want to add a new Model, create of file with the same name the class it's related to, and an entry in the
app/config/config.yml.dist file (the name should be the pluralized & tablized version of the model name).The model file is in yml format, and contains three main section:
1. The fields section (required)
This section describes the list of fields of an entity (not language related).
Available options in this section:
1. columns (required)Describe each field of the entity we want to generate.
Syntax:
```yaml
columns:
id:
type: increment
id_state:
relation: State
exclusive_fields:
id_customer:
relation: Customer
id_manufacturer:
relation: Manufacturer
id_supplier:
relation: Supplier
id_warehouse:
value: 0
alias:
type: words
args:
- 10 #nb words
id_customer:
relation: Customer
conditions:
id_guest: 1
name:
type: word
args:
- 10 #nb chars
hidden: true
price:
type: numberBetween
args:
- 1 #start
- 1000 #stop
wholesale_price:
value: '{price}/100'
```
1. the 'type' property
* 'increment' is a simple autoincrement.
* 'conditionalValue' allow to generate value depending on a condition.
Example:
```yaml
default_on:
type: conditionalValue
args:
- isNewValue({id_product}) # condition
- 1 # value if condition is true
- null # value if condition is false
```
The isNewValue is a special function which checks if the value related to the field {id_product}
has changed since the last time we have generated an entity.
* other properly value allows to generate random value. , another types
available are described from the faker module: https://github.com/FakerPHP/Faker
If you need to pass an argument to a faker function, just add the 'args:' tag like in the above example.
If you want to generate a field, but hide it from the final result, add the "hidden: true" property
(only useful if the field in question is referenced as an "id", but only present in the field_lang)
2. the 'relation' property
The 'relation' property indicates it should generates the value from an another entity (it will use a value
from the 'id' of the other entity).
If the 'generate_all' property is used in conjunction with a relation type, it means we should use
all the existing relations instead of just choosing a random one. It's especially usefull if we want for
example generate combinations for every product in the database:
```yaml
fields:
class: 'Combination'
columns:
id:
type: increment
id_product:
relation: Product
generate_all: true
```
If the 'conditions' property is used in conjunction with a relation type, it means all the fields specified
should have the specified value in the related entity:
```yaml
fields:
class: 'Guest'
columns:
id:
type: increment
id_customer:
relation: Customer
conditions:
is_guest: 1
```
3. the 'value' property
The 'value' property sets a specific value for the column. It could also be a reference to another
column, or a mathematical expression, like the "wholesale_price" in the example above.
4. the 'exclusive_fields' property
Some columns should have a value only if other column are not set.
That's the purpose of this property. In the example above only one randomly chosen field
among id_customer/id_manufacturer/id_supplier will be set.
2. class (optional)
The name of the class related to the entity.
Example:
```yaml
class: 'Carrier'
```
3. sql (optional)
Sql argument when want to add to help debugging
Example:
```yaml
sql: 'a.id_carrier > 1'
```
4. id
The 'id' tag sets which field inside the 'columns' property should be considered as a the reference unique field
for relation resolution.
Example:
```yaml
id: 'name'
```
5. primary
When the primary tag is used, the script iterate over all the existing values, excepted if there's a
'generate_all: true' tag present (the fields in the 'primary' tag should be described as relations to other
entities)
Example:
```yaml
primary: 'id_carrier, id_group'
columns:
id_carrier:
relation: Carrier
id_group:
relation: Group
```
6. image (optional)
Generate random images in the given relative path of the generated_data/img/ directory for each entity.
It's used in conjonction with image_width, image_height and image_category.
Example:
```yaml
image: 'c'
image_width: 141
image_height: 180
image_category: abstract
```
Possible image_category are:
```
abstract
animals
business
cats
city
food
night
life
fashion
people
nature
sports
technics
transport
```2. The fields_lang section (optional)
This section describes the list of fields present in the language related part of the entity (if any).
You can set an optional 'id_shop' tag and a 'columns' property which support the type same 'value' and 'type' than the
'fields' section.
Example:
```yaml
fields_lang:
id_shop: 1
columns:
name:
type: words
args:
- 6
description:
type: sentence
description_short:
type: sentence
args:
- 4
link_rewrite:
type: slug
available_now:
value: In stock
```3. The entities section (optional)
This section describes any custom entities we want to create (no random generation for those one).
The key of each entry used will be used as the 'id' of the entityExample:
```yaml
entities:
My_carrier:
fields:
id_reference: 2
active: 1
shipping_handling: 1
range_behaviour: 0
is_free: 0
shipping_external: 0
need_range: 0
shipping_method: 0
max_width: 0
max_height: 0
max_depth: 0
max_weight: 0
grade: 0
name: My carrier
url: ~
fields_lang:
delay: Delivery next day!
```Default xml data
--------
If you want to use a default xml file instead of generating one using the entity model, just put it in the default_data
directory.It will be automatically parsed by the script and will be taken into account for the existing entity relations.