项目作者: PrestaShop

项目描述 :
Generate random demo data to test your PrestaShop shop.
高级语言: PHP
项目地址: git://github.com/PrestaShop/prestashop-shop-creator.git
创建时间: 2017-12-05T08:23:02Z
项目社区:https://github.com/PrestaShop/prestashop-shop-creator

开源协议:

下载


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

Installation & configuration

To setup the configuration of the module, just run

  1. composer install

This will generates a configuration file in app/config/config.yml

How to run the script

  1. 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 generate

Entity 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:

      1. columns:
      2. id:
      3. type: increment
      4. id_state:
      5. relation: State
      6. exclusive_fields:
      7. id_customer:
      8. relation: Customer
      9. id_manufacturer:
      10. relation: Manufacturer
      11. id_supplier:
      12. relation: Supplier
      13. id_warehouse:
      14. value: 0
      15. alias:
      16. type: words
      17. args:
      18. - 10 #nb words
      19. id_customer:
      20. relation: Customer
      21. conditions:
      22. id_guest: 1
      23. name:
      24. type: word
      25. args:
      26. - 10 #nb chars
      27. hidden: true
      28. price:
      29. type: numberBetween
      30. args:
      31. - 1 #start
      32. - 1000 #stop
      33. wholesale_price:
      34. value: '{price}/100'
      1. the ‘type’ property

        • ‘increment’ is a simple autoincrement.

        • ‘conditionalValue’ allow to generate value depending on a condition.
          Example:

          1. default_on:
          2. type: conditionalValue
          3. args:
          4. - isNewValue({id_product}) # condition
          5. - 1 # value if condition is true
          6. - 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:

        1. fields:
        2. class: 'Combination'
        3. columns:
        4. id:
        5. type: increment
        6. id_product:
        7. relation: Product
        8. 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:

        1. fields:
        2. class: 'Guest'
        3. columns:
        4. id:
        5. type: increment
        6. id_customer:
        7. relation: Customer
        8. conditions:
        9. 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:

      1. class: 'Carrier'
    3. sql (optional)

      Sql argument when want to add to help debugging

      Example:

      1. 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:

      1. 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:

      1. primary: 'id_carrier, id_group'
      2. columns:
      3. id_carrier:
      4. relation: Carrier
      5. id_group:
      6. 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:

      1. image: 'c'
      2. image_width: 141
      3. image_height: 180
      4. image_category: abstract

      Possible image_category are:

      1. abstract
      2. animals
      3. business
      4. cats
      5. city
      6. food
      7. night
      8. life
      9. fashion
      10. people
      11. nature
      12. sports
      13. technics
      14. 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:

    1. fields_lang:
    2. id_shop: 1
    3. columns:
    4. name:
    5. type: words
    6. args:
    7. - 6
    8. description:
    9. type: sentence
    10. description_short:
    11. type: sentence
    12. args:
    13. - 4
    14. link_rewrite:
    15. type: slug
    16. available_now:
    17. 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 entity

    Example:

    1. entities:
    2. My_carrier:
    3. fields:
    4. id_reference: 2
    5. active: 1
    6. shipping_handling: 1
    7. range_behaviour: 0
    8. is_free: 0
    9. shipping_external: 0
    10. need_range: 0
    11. shipping_method: 0
    12. max_width: 0
    13. max_height: 0
    14. max_depth: 0
    15. max_weight: 0
    16. grade: 0
    17. name: My carrier
    18. url: ~
    19. fields_lang:
    20. 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.