diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b98a718d8..55ebdf77d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - Support for new location of `generated` directory in Magento 2.2.0 + - Basic data generation can be turned off. Added configurable product and customer address generation ### Fixed diff --git a/README.md b/README.md index a9497c932d6..89efd01a38d 100755 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ * [Clear Magento cache](#clear-magento-cache) * [Switch between CE and EE](#switch-between-ce-and-ee) * [Sample data installation](#sample-data-installation) + * [Basic data generation](#basic-data-generation) * [Use Magento CLI (bin/magento)](#use-magento-cli-binmagento) * [Debugging with XDebug](#debugging-with-xdebug) * [Connecting to MySQL DB](#connecting-to-mysql-db) @@ -186,6 +187,16 @@ During initial project setup or during `bash init_project.sh -fc` (with `-fc` pr To install Magento with sample data set `install_sample_data` in [config.yaml](etc/config.yaml.dist) to `1` and run `bash m-switch-to-ce -f` or `bash m-switch-to-ee -f`, depending on the edition to be installed. To disable sample data, set this option to `0` and force-switch to necessary edition (using the same commands). +### Basic data generation + +Several entities are generated for testing purposes by default using REST API after Magento installation: +- Customer with address (credentials `customer@example.com`:`123123qQ`) +- Category +- Couple simple products +- Configurable product + +To disable this feature, set `magento/generate_basic_data` in [config.yaml](etc/config.yaml.dist) to `0` and run `bash m-switch-to-ce -f` or `bash m-switch-to-ee -f`, depending on the edition to be installed. + ### Use Magento CLI (bin/magento) Go to 'vagrant-magento' created earlier and run in command line: diff --git a/etc/config.yaml.dist b/etc/config.yaml.dist index 1ca8c3df8cb..92e3b8a4bc5 100644 --- a/etc/config.yaml.dist +++ b/etc/config.yaml.dist @@ -46,6 +46,8 @@ environment: magento: # [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] install_sample_data: 0 + # [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] Generate customer (customer@example.com:123123qQ), category, simple product, configurable product after successful Magento installation + generate_basic_data: 1 # [To apply changes: init_project.sh -f] host_name: "magento2.vagrant2" # [To apply changes: m-reinstall] diff --git a/scripts/guest/generate_basic_data b/scripts/guest/generate_basic_data new file mode 100755 index 00000000000..5a75c78aa19 --- /dev/null +++ b/scripts/guest/generate_basic_data @@ -0,0 +1,615 @@ +#!/usr/bin/env bash + +vagrant_dir="/vagrant" + +source "${vagrant_dir}/scripts/output_functions.sh" + +host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" + +status "Generating sample data" + +incrementNestingLevel + +adminToken=$(curl -sb -X POST "http://${host_name}/rest/V1/integration/admin/token" \ + -H "Content-Type:application/json" \ + -d '{"username":"admin", "password":"123123q"}') +adminToken=$(echo ${adminToken} | sed -e 's/"//g') + +category_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/categories" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "category": { + "parentId": 2, + "name": "Test Category", + "isActive": true, + "includeInMenu": true + } + }') + +pattern='\{\"id\":([0-9]+),' +if [[ "${category_creation_response}" =~ ${pattern} ]]; then + category_id=${BASH_REMATCH[1]} +fi + +attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "option": { + "label": "red" + } + }') + +attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "option": { + "label": "blue" + } + }') + +attribute_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attributes/color/options" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "option": { + "label": "green" + } + }') + +attribute_set_add_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products/attribute-sets/attributes" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "attributeSetId": 4, + "attributeGroupId": 7, + "attributeCode": "color", + "sortOrder": 0 + }') + +product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testSimpleProduct", + "name": "Test Simple Product", + "attribute_set_id": 4, + "price": 22, + "weight": 1, + "status": 1, + "visibility": 4, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 12345, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + } + ] + } + }') + +product_creation_response2=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testSimpleProduct2", + "name": "Test Simple Product 2", + "attribute_set_id": 4, + "price": 32, + "weight": 1, + "status": 1, + "visibility": 4, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 12345, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + } + ] + } + }') + +product_creation_response_child1=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testConfigProduct-red", + "name": "Test Red Configurable Product", + "attribute_set_id": 4, + "price": 10, + "weight": 1, + "status": 1, + "visibility": 1, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 1000, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + }, + { + "attribute_code": "color", + "value": "4" + } + ] + } + }') + +product_creation_response_child2=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testConfigProduct-blue", + "name": "Test Blue Configurable Product", + "attribute_set_id": 4, + "price": 10, + "weight": 1, + "status": 1, + "visibility": 1, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 1000, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + }, + { + "attribute_code": "color", + "value": "5" + } + ] + } + }') + +product_creation_response_child3=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testConfigProduct-green", + "name": "Test Green Configurable Product", + "attribute_set_id": 4, + "price": 10, + "weight": 1, + "status": 1, + "visibility": 1, + "type_id": "simple", + "extension_attributes": { + "stock_item": { + "qty": 1000, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + }, + { + "attribute_code": "color", + "value": "6" + } + ] + } + }') + +config_product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "sku": "testConfigProduct", + "name": "Test Configurable Product", + "attribute_set_id": 4, + "price": 10, + "weight": 1, + "status": 1, + "visibility": 4, + "type_id": "configurable", + "extension_attributes": { + "stock_item": { + "qty": 1000, + "is_in_stock": true + } + }, + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "'"${category_id}"'" + ] + } + ] + } + }') + +option_creation_resp=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/options" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "option": { + "attribute_id": "93", + "label": "Color", + "position": 0, + "values": [ + { + "value_index": 4 + }, + { + "value_index": 5 + }, + { + "value_index": 6 + } + ] + } + }') + +product_creation_response_child1=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "id": 3, + "sku": "testConfigProduct-red", + "name": "Test Red Configurable Product", + "attribute_set_id": 4, + "price": 10, + "status": 1, + "visibility": 1, + "type_id": "simple", + "weight": 1, + "extension_attributes": { + "website_ids": [ + 1 + ], + "category_links": [ + { + "position": 0, + "category_id": "3" + } + ], + "stock_item": { + "item_id": 3, + "product_id": 3, + "stock_id": 1, + "qty": 1000, + "is_in_stock": true, + "is_qty_decimal": false, + "show_default_notification_message": false, + "use_config_min_qty": true, + "min_qty": 0, + "use_config_min_sale_qty": 1, + "min_sale_qty": 1, + "use_config_max_sale_qty": true, + "max_sale_qty": 10000, + "use_config_backorders": true, + "backorders": 0, + "use_config_notify_stock_qty": true, + "notify_stock_qty": 1, + "use_config_qty_increments": true, + "qty_increments": 0, + "use_config_enable_qty_inc": true, + "enable_qty_increments": false, + "use_config_manage_stock": true, + "manage_stock": true, + "low_stock_date": null, + "is_decimal_divided": false, + "stock_status_changed_auto": 0 + } + }, + "product_links": [], + "options": [], + "media_gallery_entries": [], + "tier_prices": [], + "custom_attributes": [ + { + "attribute_code": "color", + "value": "4" + }, + { + "attribute_code": "category_ids", + "value": [ + "3" + ] + }, + { + "attribute_code": "options_container", + "value": "container2" + }, + { + "attribute_code": "required_options", + "value": "0" + }, + { + "attribute_code": "has_options", + "value": "0" + }, + { + "attribute_code": "url_key", + "value": "test-red-configurable-product" + }, + { + "attribute_code": "tax_class_id", + "value": "2" + } + ] + } + }') + +product_creation_response_child2=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "id": 4, + "sku": "testConfigProduct-blue", + "name": "Test Blue Configurable Product", + "attribute_set_id": 4, + "price": 10, + "status": 1, + "visibility": 1, + "type_id": "simple", + "created_at": "2017-09-12 01:50:09", + "updated_at": "2017-09-12 01:50:09", + "weight": 1, + "extension_attributes": { + "website_ids": [ + 1 + ], + "category_links": [ + { + "position": 0, + "category_id": "3" + } + ], + "stock_item": { + "item_id": 4, + "product_id": 4, + "stock_id": 1, + "qty": 1000, + "is_in_stock": true, + "is_qty_decimal": false, + "show_default_notification_message": false, + "use_config_min_qty": true, + "min_qty": 0, + "use_config_min_sale_qty": 1, + "min_sale_qty": 1, + "use_config_max_sale_qty": true, + "max_sale_qty": 10000, + "use_config_backorders": true, + "backorders": 0, + "use_config_notify_stock_qty": true, + "notify_stock_qty": 1, + "use_config_qty_increments": true, + "qty_increments": 0, + "use_config_enable_qty_inc": true, + "enable_qty_increments": false, + "use_config_manage_stock": true, + "manage_stock": true, + "low_stock_date": null, + "is_decimal_divided": false, + "stock_status_changed_auto": 0 + } + }, + "product_links": [], + "options": [], + "media_gallery_entries": [], + "tier_prices": [], + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "3" + ] + }, + { + "attribute_code": "options_container", + "value": "container2" + }, + { + "attribute_code": "required_options", + "value": "0" + }, + { + "attribute_code": "color", + "value": "5" + }, + { + "attribute_code": "has_options", + "value": "0" + }, + { + "attribute_code": "url_key", + "value": "test-blue-configurable-product" + }, + { + "attribute_code": "tax_class_id", + "value": "2" + } + ] + } + }') + +product_creation_response_child3=$(curl -sb -X PUT "http://${host_name}/rest/V1/products" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "product": { + "id": 5, + "sku": "testConfigProduct-green", + "name": "Test Green Configurable Product", + "attribute_set_id": 4, + "price": 10, + "status": 1, + "visibility": 1, + "type_id": "simple", + "created_at": "2017-09-12 01:50:10", + "updated_at": "2017-09-12 01:50:10", + "weight": 1, + "extension_attributes": { + "website_ids": [ + 1 + ], + "category_links": [ + { + "position": 0, + "category_id": "3" + } + ], + "stock_item": { + "item_id": 5, + "product_id": 5, + "stock_id": 1, + "qty": 1000, + "is_in_stock": true, + "is_qty_decimal": false, + "show_default_notification_message": false, + "use_config_min_qty": true, + "min_qty": 0, + "use_config_min_sale_qty": 1, + "min_sale_qty": 1, + "use_config_max_sale_qty": true, + "max_sale_qty": 10000, + "use_config_backorders": true, + "backorders": 0, + "use_config_notify_stock_qty": true, + "notify_stock_qty": 1, + "use_config_qty_increments": true, + "qty_increments": 0, + "use_config_enable_qty_inc": true, + "enable_qty_increments": false, + "use_config_manage_stock": true, + "manage_stock": true, + "low_stock_date": null, + "is_decimal_divided": false, + "stock_status_changed_auto": 0 + } + }, + "product_links": [], + "options": [], + "media_gallery_entries": [], + "tier_prices": [], + "custom_attributes": [ + { + "attribute_code": "category_ids", + "value": [ + "3" + ] + }, + { + "attribute_code": "options_container", + "value": "container2" + }, + { + "attribute_code": "required_options", + "value": "0" + }, + { + "attribute_code": "color", + "value": "6" + }, + { + "attribute_code": "has_options", + "value": "0" + }, + { + "attribute_code": "url_key", + "value": "test-green-configurable-product" + }, + { + "attribute_code": "tax_class_id", + "value": "2" + } + ] + } + }') + +child_create_response1=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{"childSku": "testConfigProduct-red"}') +child_create_response2=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{"childSku": "testConfigProduct-blue"}') +child_create_response3=$(curl -sb -X POST "http://${host_name}/rest/V1/configurable-products/testConfigProduct/child" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{"childSku": "testConfigProduct-green"}') + +customer_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/customers" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${adminToken}" \ + -d '{ + "customer": { + "group_id":1, + "email":"customer@example.com", + "firstname":"John", + "lastname":"Doe", + "store_id":1, + "addresses":[ + { + "region": { + "region_code": "TX", + "region": "Texas", + "region_id": 57 + }, + "region_id": 57, + "country_id": "US", + "street": [ + "7700 Parmer Lane" + ], + "telephone": "5555555555", + "postcode": "78729", + "city": "Austin", + "firstname": "John", + "lastname": "Doe", + "default_shipping": true, + "default_billing": true + } + ], + "disable_auto_group_change": 0 + }, + "password": "123123qQ" + }') + +decrementNestingLevel diff --git a/scripts/guest/generate_sample_data b/scripts/guest/generate_sample_data deleted file mode 100755 index 8efa864875f..00000000000 --- a/scripts/guest/generate_sample_data +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash - -vagrant_dir="/vagrant" - -source "${vagrant_dir}/scripts/output_functions.sh" - -host_name="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "magento_host_name")" - -status "Generating sample data" - -incrementNestingLevel - -adminToken=$(curl -sb -X POST "http://${host_name}/rest/V1/integration/admin/token" \ - -H "Content-Type:application/json" \ - -d '{"username":"admin", "password":"123123q"}') -adminToken=$(echo ${adminToken} | sed -e 's/"//g') - -category_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/categories" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer ${adminToken}" \ - -d '{ - "category": { - "parentId": 2, - "name": "Test Category", - "isActive": true, - "includeInMenu": true - } - }') - -pattern='\{\"id\":([0-9]+),' -if [[ "${category_creation_response}" =~ ${pattern} ]]; then - category_id=${BASH_REMATCH[1]} -fi - -product_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/products" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer ${adminToken}" \ - -d '{ - "product": { - "sku": "testSimpleProduct", - "name": "Test Simple Product", - "attribute_set_id": 4, - "price": 22, - "status": 1, - "visibility": 4, - "type_id": "simple", - "extension_attributes": { - "stock_item": { - "qty": 12345, - "is_in_stock": true - } - }, - "custom_attributes": [ - { - "attribute_code": "category_ids", - "value": [ - "'"${category_id}"'" - ] - } - ] - } - }') - -customer_creation_response=$(curl -sb -X POST "http://${host_name}/rest/V1/customers" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer ${adminToken}" \ - -d '{ - "customer": { - "group_id":1, - "email":"customer@example.com", - "firstname":"FirstName", - "lastname":"LastName", - "store_id":1, - "addresses":[], - "disable_auto_group_change": 0 - }, - "password": "123123qQ" - }') - -decrementNestingLevel diff --git a/scripts/guest/m-reinstall b/scripts/guest/m-reinstall index 5b5754dd169..f0d344cff7d 100755 --- a/scripts/guest/m-reinstall +++ b/scripts/guest/m-reinstall @@ -8,6 +8,7 @@ get_config_value="/vagrant/scripts/get_config_value.sh" magento_host_name="$(bash ${get_config_value} "magento_host_name")" use_nfs="$(bash "${vagrant_dir}/scripts/get_config_value.sh" "guest_use_nfs")" is_windows_host=${IS_WINDOWS_HOST} +generate_basic_data="$(bash ${get_config_value} "magento_generate_basic_data")" declare -A setupOptions setupOptions[admin_frontname]="$(bash ${get_config_value} "magento_admin_frontname")" @@ -105,7 +106,9 @@ if [[ ${is_windows_host} == 1 ]] || [[ ${use_nfs} == 0 ]]; then sudo chown -R vagrant:vagrant ${MAGENTO_ROOT} fi -bash generate_sample_data +if [[ ${generate_basic_data} != 0 ]]; then + bash generate_basic_data +fi bash configure_search_engine bash change_magento_config_for_functional_tests bash update_magento_config 'admin/security/session_lifetime' '86400'