Coder Social home page Coder Social logo

prestashop-shop-creator's Introduction

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.

Installation & configuration

To setup the configuration of the module, just run

composer install

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

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

      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:

          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.

        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:

        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:

        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:

      class: 'Carrier'
    3. sql (optional)

      Sql argument when want to add to help debugging

      Example:

      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:

      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:

      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:

      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:

    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 entity

    Example:

    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.

prestashop-shop-creator's People

Contributors

0x346e3730 avatar davidglezz avatar jocel1 avatar jolelievre avatar matks avatar mflasquin avatar pierrerambaud avatar quetzacoalt91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prestashop-shop-creator's Issues

[Shop creator V2] Handle hierarchical data

Categories follow a tree: parents have children which have subchildren.

Shop creator V2 must ensure that if category A which is parent to category B which is parent to category C, then A cannot be child of category C

[Shop creator V2] Handle association entities

There are association table in the fixtures, for example ps_category_products

id_category id_product position
2 1 1
2 2 2
2 8 8
6 11 1

It should be impossible to generate twice the same row. V2 must ensure this rules is enforced.

Improve this repository, add tests

This tool is doing amazing things but it can be improved. For example code complexity of class https://github.com/PrestaShop/prestashop-shop-creator/blob/master/src/Generator/EntityGenerator.php is high.

First thing needed to enable refactoring of this repository would be to add automated tests, and run them in a CI using GitHub Actions.

When this is done we will be able to use CI to detect whether our refactoring is breaking an existing feature / behavior or not.

I suppose that we can use this opportunity to add the standard CI helpers: phpstan, php-cs-fixer... see for example https://github.com/PrestaShop/ps_linklist/blob/dev/.github/workflows/php.yml

[Shop creator V2] Generation mode for associations

If shop creator V2 is tasked to generate 100 orders and 1000 products, depending on generation mode it should either generate 100 orders which each are linked up to 1000 products or 100 orders which each are linked up to 1000x100 products

Prestashop 8

This won't work for Prestashop 8
Any suggested alternative / solution ?

Thanks

Property "Address->dni" in the generated addresses is empty with Prestashop

Hi @Progi1984, guys,

Hope you are all well !

I know that you do not reply to issues from this repository but I try :-)

I used your creator for generating more data for fixtures but I have the following error when I try to install them with the index_cli.php file.
image

Screenshot 2021-02-05 at 06 53 35

Is there any way to ignore such errors ? Is there something to do for fixing it ?

Thanks for any insights or inputs on that.

Cheers,
Luc Michalski

[EPIC] Shop Creator V2

In order to be able to deliver #13 and #14 it seems we have no other choice than to build a version 2 of Shop Creator.

@FabienPapet has been working for a few weeks on it. Version 2 must be better decoupled, better tested, better structured, better documented and bring PrestaShop 8 compatibility.

Error "You first need to define an entry before using a relation with supplier"

Hello,
I get this message:

root@serverxxx:/var/www/performance-project/shop/prestashop-shop-creator# php -d memory_limit=1512M app/console.php 
Generating 25 carrier entities
Generating 87 category entities
Generating 22 manufacturer entities
Generating 0 supplier entities
Generating 2411 product entities
You first need to define an entry before using a relation with supplier

while generating sample data with the following input file:

parameters:
    shop_id: 1
    customers: 10
    manufacturers: 22
    suppliers: 0
    addresses: 10
    aliases: 2
    categories: 87
    warehouses: 0
    carriers: 25
    specific_prices: 8526
    attribute_groups: 1
    products: 2411
    attributes: 98
    carts: 1
    cart_rules: 1
    customizations: 0
    features: 0
    feature_values: 0
    orders: 10
    guests: 1
    order_histories: 2
    range_prices: 16
    range_weights: 7
    product_attributes: 9758
    images: 3 # each product has this count of images, be careful if you set an high product count
    order_messages: 10
    deliveries: 10
    connections: 100
    product_suppliers: 0
    order_carriers: 2
    order_details: 10
    feature_products: 5
    stores: 1
    profiles: 5
    stock_availables: 12172
    langs:
        - it_IT

I followed the steps stated at https://github.com/PrestaShop/performance-project/blob/master/shop/README.md, and I stopped ad the last of point 1, I changed the values according to what I have on a very similar Prestashop instance.

After the error, the generated directory contains the following files:

root@serverxxx:/var/www/performance-project/shop/prestashop-shop-creator# tree generated_data/
generated_data/
├── data
│   ├── carrier.xml
│   ├── category.xml
│   ├── manufacturer.xml
│   └── supplier.xml
├── img
│   ├── c
│   │   ├── ab.jpg
│   │   ├── ad.jpg
│   │   ├── autem.jpg
│   │   ├── aut.jpg
│   │   ├── consequatur.jpg
│   │   ├── doloremque.jpg
│   │   ├── doloribus.jpg
│   │   ├── dolor.jpg
│   │   ├── ea.jpg
│   │   ├── enim.jpg
│   │   ├── esse.jpg
│   │   ├── est.jpg
│   │   ├── et.jpg
│   │   ├── eveniet.jpg
│   │   ├── iste.jpg
│   │   ├── itaque.jpg
│   │   ├── molestiae.jpg
│   │   ├── nostrum.jpg
│   │   ├── quia.jpg
│   │   ├── quis.jpg
│   │   ├── quo.jpg
│   │   ├── reprehenderit.jpg
│   │   ├── sapiente.jpg
│   │   ├── sint.jpg
│   │   ├── sunt.jpg
│   │   ├── tempore.jpg
│   │   ├── ut.jpg
│   │   ├── vel.jpg
│   │   ├── voluptate.jpg
│   │   └── voluptatem.jpg
│   └── m
│       ├── et et.jpg
│       ├── et soluta.jpg
│       ├── eum dolores.jpg
│       ├── odio ut.jpg
│       ├── quia quisquam.jpg
│       └── sequi omnis.jpg
└── langs
    └── it
        └── data
            ├── carrier.xml
            ├── category.xml
            ├── manufacturer.xml
            └── supplier.xml

7 directories, 44 files

How can I solve "You first need to define an entry before using a relation with supplier" ?

Cover image only in the first image

Current behaviour: all generated images are cover:

<image id_product="4" id="13" cover="1"/>
<image id_product="4" id="14" cover="1"/>
<image id_product="4" id="15" cover="1"/>
<image id_product="4" id="16" cover="1"/>

then, only one image are added to the product:
image

If we modify cover value to be 0

<image id_product="3" id="9" cover="0"/>
<image id_product="3" id="10" cover="0"/>
<image id_product="3" id="11" cover="0"/>
<image id_product="3" id="12" cover="0"/>

image

But then... No cover image
image

EXPECTED OUTPUT: only one image with cover="1"

<image id_product="3" id="9" cover="1"/>
<image id_product="3" id="10" cover="0"/>
<image id_product="3" id="11" cover="0"/>
<image id_product="3" id="12" cover="0"/>

Parallel execution

Just an idea, but wouldn't be interesting to use execute generation in multiple threads to speed up the process?
I tested it and it's so long when you generate thousands of products, their images and so on.
But it depends if you use actively this tool, I don't know if it's still the case...

See https://github.com/amphp/parallel.

Can't install Prestashop with generated data because of Faker dependency

Describe the bug and add screenshots
Previously reported here: PrestaShop/PrestaShop#28726 (comment)
image

Steps to reproduce

  1. git clone https://github.com/PrestaShop/prestashop-shop-creator.git
  2. cd prestashop-shop-creator
  3. composer install
  4. php app/console.php
  5. Install PrestaShop with the generated data
  6. See error

Solution
Under Vendor/fakerphp/faker/src/Facker/Provider/Image.php, add the line below after this line curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');

Shop creator generates XML files that generate errors when used with PrestaShop 8.0.0

Describe the bug and add screenshots
The shop creator is not compatible with PS8.0.0, we have errors during the install
80x_shop_creator
Steps to reproduce

  1. git clone https://github.com/PrestaShop/prestashop-shop-creator.git
  2. cd prestashop-shop-creator
  3. Under Vendor/fakerphp/src/Facker/Provider/Image.php, add the line below after this line curl_setopt($ch, CURLOPT_FILE, $fp);
  4. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
  5. Execute composer install
  6. Setup the number of data you wish for each categories
  7. php app/console.php
  8. Begin installation of PrestaShop and stop at database configuration step
  9. Move generated data to install/fixtures/fashion folder of PrestaShop installation
  10. Under fashion/data, replace dni="" by dni="12345678A" in address.xml generated file.
  11. Continue installation
  12. See error

Incompatibility PHP >= 8.0

The composer.json file defines the compatibility for PHP to >=7.0.0.

But with PHP 8.0/8.1/8.2, I have these errors :
image

Generating huge quantity of data takes too much time, then the tool halts (it does not finish)

Describe the bug and add screenshots
It takes too much time when generating the default data (or more data) of the shop creator

parameters:
    shop_id: 1
    customers: 100
    manufacturers: 100
    suppliers: 10
    addresses: 100
    aliases: 100
    categories: 100
    warehouses: 2
    carriers: 3
    specific_prices: 100
    attribute_groups: 10
    products: 100
    attributes: 10
    carts: 1000
    cart_rules: 100
    customizations: 10
    features: 100
    feature_values: 5
    orders: 10
    guests: 10
    order_histories: 6
    range_prices: 100
    range_weights: 100
    product_attributes: 5
    images: 3
    order_messages: 100
    deliveries: 100
    connections: 1000
    product_suppliers: 10
    order_carriers: 2
    order_details: 10
    feature_products: 5
    stores: 100
    profiles: 10
    stock_availables: 1
    langs:
        - fr_FR
        - en_US

Steps to reproduce

  1. git clone https://github.com/PrestaShop/prestashop-shop-creator.git
  2. cd prestashop-shop-creator
  3. composer install
  4. Set the number of data by default data (or more data)
  5. php app/console.php
  6. See error > It takes too much time when generating the data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.