├── src └── Generation │ └── Commands │ ├── Resources │ ├── extModel.txt │ ├── viewCatalog.txt │ ├── 3.x.x.x │ │ ├── viewCatalog.txt │ │ ├── view.txt │ │ └── extModController.txt │ ├── model.txt │ ├── lang.txt │ ├── modControllerCatalog.txt │ ├── extModControllerCatalog.txt │ ├── view.txt │ ├── language-en.php │ ├── modController.txt │ └── extModController.txt │ ├── CommandInterface.php │ ├── language │ ├── language.php │ └── english │ │ └── language.php │ ├── ClearCache.php │ ├── WkOcSql.php │ ├── SetUpOpencart.php │ ├── dummyData.php │ └── CreateExtension.php ├── app ├── install_oc.sh └── console ├── composer.json └── README.md /src/Generation/Commands/Resources/extModel.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/viewCatalog.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/3.x.x.x/viewCatalog.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/model.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Generation/Commands/CommandInterface.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpmaster/console_demo", 3 | "description": "creating console application", 4 | "require": { 5 | "php": ">=5.3.3", 6 | "symfony/console": "3.1" 7 | }, 8 | "autoload": { 9 | "psr-0": { 10 | "": "src/" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Generation/Commands/language/language.php: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/modControllerCatalog.txt: -------------------------------------------------------------------------------- 1 | load->language('module/consolefilename')); 7 | 8 | if (isset($this->error['warning'])) { 9 | $data['error_warning'] = $this->error['warning']; 10 | } else { 11 | $data['error_warning'] = ''; 12 | } 13 | 14 | return $this->load->view('module/consolefilename.tpl', $data); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/extModControllerCatalog.txt: -------------------------------------------------------------------------------- 1 | load->language('extension/module/consolefilename')); 7 | 8 | if (isset($this->error['warning'])) { 9 | $data['error_warning'] = $this->error['warning']; 10 | } else { 11 | $data['error_warning'] = ''; 12 | } 13 | 14 | return $this->load->view('extension/module/consolefilename', $data); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /app/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getFileName(), 0, strrpos($reflection->getFileName(), '/')); 20 | 21 | $collection = array_filter(scandir($pathToCommandsDir), function($path) use ($pathToCommandsDir) { 22 | if (($path != '.' || $path != '..') && is_file($pathToCommandsDir . "/" . $path) && !is_dir(is_file($pathToCommandsDir . "/" . $path))) { 23 | return true; 24 | } 25 | 26 | return false; 27 | }); 28 | 29 | foreach ($collection as $className) { 30 | $classPath = $reflection->getNamespaceName() . "\\" . substr($className, 0, strpos($className, '.')); 31 | $reflectionClass = new ReflectionClass($classPath); 32 | 33 | if ($reflectionClass->isInterface() || $reflectionClass->isAbstract()) { 34 | continue; 35 | } else if ($reflectionClass->getParentClass()->getName() != Command::class || false == $reflectionClass->isInstantiable()) { 36 | continue; 37 | } 38 | 39 | $app->add($reflectionClass->newInstance()); 40 | } 41 | 42 | $app->run(); 43 | 44 | ?> -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/3.x.x.x/view.txt: -------------------------------------------------------------------------------- 1 | {{ header }}{{ column_left }} 2 |
3 | 16 |
17 | {% if error_warning is defined and error_warning %} 18 |
{{ error_warning }} 19 | 20 |
21 | {% endif %} 22 |
23 |
24 |

{{ heading_title }}

25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 |
33 |
34 | {{ footer }} -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/view.txt: -------------------------------------------------------------------------------- 1 | 2 |
3 | 16 |
17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 |

25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 |
33 |
34 | -------------------------------------------------------------------------------- /src/Generation/Commands/language/english/language.php: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/language-en.php: -------------------------------------------------------------------------------- 1 | 32 | -------------------------------------------------------------------------------- /src/Generation/Commands/ClearCache.php: -------------------------------------------------------------------------------- 1 | setName("clearcache") 22 | ->setDescription("Clear cache of the project"); 23 | } 24 | 25 | protected function execute(InputInterface $input, OutputInterface $output) { 26 | 27 | require_once('language/language.php'); 28 | 29 | $this->confirmation = array( 30 | 'y', 31 | 'Y', 32 | 'n', 33 | 'N', 34 | ); 35 | 36 | $helper = $this->getHelper('question'); 37 | $q1 = new Question('' . $language['question1'] . ': '); 38 | $q2 = new Question('' . $language['question2'] . ' : '); 39 | $q3 = new Question('' . $language['confirm'] . ' :'); 40 | 41 | while(!$this->status) { 42 | 43 | $username = $helper->ask($input, $output, $q1); 44 | $password = $helper->ask($input, $output, $q2); 45 | 46 | $conn = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD,DB_DATABASE); 47 | 48 | if (!$conn) { 49 | 50 | $output->writeln($language['connection_error']); 51 | } 52 | 53 | $query = "SELECT * from `" . DB_PREFIX . "user` where username = '" . $username . "' and (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . htmlspecialchars($password, ENT_QUOTES) . "'))))) OR password = '" . md5($password) . "') "; 54 | 55 | $result = mysqli_query($conn,$query); 56 | 57 | if (mysqli_num_rows($result) > 0) { 58 | 59 | $output->writeln($language['login_success']); 60 | $this->status = 1; 61 | } else { 62 | $output->writeln($language['login_error']); 63 | $this->status = 0; 64 | } 65 | } 66 | if($this->status) { 67 | $confirm = $helper->ask($input, $output, $q3); 68 | while (!in_array($confirm,$this->confirmation)) { 69 | $confirm = $helper->ask($input, $output, $q3); 70 | } 71 | } 72 | if($confirm == 'y' || $confirm == 'Y') { 73 | array_map('unlink', glob(DIR_SYSTEM . "storage/cache/*.*")); 74 | $output->writeln($language['cache_clear']); 75 | }else { 76 | $output->writeln($language['bye_bye']); 77 | } 78 | 79 | } 80 | } 81 | ?> 82 | -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/modController.txt: -------------------------------------------------------------------------------- 1 | load->language('module/consolefilename')); 16 | 17 | $this->document->setTitle($this->language->get('heading_title')); 18 | 19 | $this->load->model('setting/setting'); 20 | 21 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 22 | $this->model_setting_setting->editSetting('consolefilename', $this->request->post); 23 | 24 | $this->session->data['success'] = $this->language->get('text_success'); 25 | 26 | $this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')); 27 | } 28 | 29 | if (isset($this->error['warning'])) { 30 | $data['error_warning'] = $this->error['warning']; 31 | } else { 32 | $data['error_warning'] = ''; 33 | } 34 | 35 | $data['breadcrumbs'] = array(); 36 | 37 | $data['breadcrumbs'][] = array( 38 | 'text' => $this->language->get('text_home'), 39 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL') 40 | ); 41 | 42 | $data['breadcrumbs'][] = array( 43 | 'text' => $this->language->get('text_module'), 44 | 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL') 45 | ); 46 | 47 | $data['breadcrumbs'][] = array( 48 | 'text' => $this->language->get('heading_title'), 49 | 'href' => $this->url->link('module/consolefilename', 'token=' . $this->session->data['token'], 'SSL') 50 | ); 51 | 52 | $data['action'] = $this->url->link('module/consolefilename', 'token=' . $this->session->data['token'], 'SSL'); 53 | 54 | $data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'); 55 | 56 | $data['header'] = $this->load->controller('common/header'); 57 | $data['column_left'] = $this->load->controller('common/column_left'); 58 | $data['footer'] = $this->load->controller('common/footer'); 59 | 60 | $this->response->setOutput($this->load->view('module/consolefilename.tpl', $data)); 61 | } 62 | 63 | protected function validate() { 64 | if (!$this->user->hasPermission('modify', 'module/consolefilename')) { 65 | $this->error['warning'] = $this->language->get('error_permission'); 66 | } 67 | 68 | return !$this->error; 69 | } 70 | } -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/extModController.txt: -------------------------------------------------------------------------------- 1 | load->language('extension/module/consolefilename')); 16 | 17 | $this->document->setTitle($this->language->get('heading_title')); 18 | 19 | $this->load->model('setting/setting'); 20 | 21 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 22 | $this->model_setting_setting->editSetting('consolefilename', $this->request->post); 23 | 24 | $this->session->data['success'] = $this->language->get('text_success'); 25 | 26 | $this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)); 27 | } 28 | 29 | if (isset($this->error['warning'])) { 30 | $data['error_warning'] = $this->error['warning']; 31 | } else { 32 | $data['error_warning'] = ''; 33 | } 34 | 35 | $data['breadcrumbs'] = array(); 36 | 37 | $data['breadcrumbs'][] = array( 38 | 'text' => $this->language->get('text_home'), 39 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) 40 | ); 41 | 42 | $data['breadcrumbs'][] = array( 43 | 'text' => $this->language->get('text_extension'), 44 | 'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true) 45 | ); 46 | 47 | $data['breadcrumbs'][] = array( 48 | 'text' => $this->language->get('heading_title'), 49 | 'href' => $this->url->link('extension/module/consolefilename', 'token=' . $this->session->data['token'], true) 50 | ); 51 | 52 | $data['action'] = $this->url->link('extension/module/consolefilename', 'token=' . $this->session->data['token'], true); 53 | 54 | $data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true); 55 | 56 | $data['header'] = $this->load->controller('common/header'); 57 | $data['column_left'] = $this->load->controller('common/column_left'); 58 | $data['footer'] = $this->load->controller('common/footer'); 59 | 60 | $this->response->setOutput($this->load->view('extension/module/consolefilename', $data)); 61 | } 62 | 63 | protected function validate() { 64 | if (!$this->user->hasPermission('modify', 'extension/module/consolefilename')) { 65 | $this->error['warning'] = $this->language->get('error_permission'); 66 | } 67 | 68 | return !$this->error; 69 | } 70 | } -------------------------------------------------------------------------------- /src/Generation/Commands/Resources/3.x.x.x/extModController.txt: -------------------------------------------------------------------------------- 1 | load->language('extension/module/consolefilename')); 16 | 17 | $this->document->setTitle($this->language->get('heading_title')); 18 | 19 | $this->load->model('setting/setting'); 20 | 21 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 22 | 23 | $this->model_setting_setting->editSetting('module_consolefilename', $this->request->post); 24 | 25 | $this->session->data['success'] = $this->language->get('text_success'); 26 | 27 | $this->response->redirect($this->url->link('extension/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); 28 | } 29 | 30 | if (isset($this->error['warning'])) { 31 | $data['error_warning'] = $this->error['warning']; 32 | } else { 33 | $data['error_warning'] = ''; 34 | } 35 | 36 | $data['breadcrumbs'] = array(); 37 | 38 | $data['breadcrumbs'][] = array( 39 | 'text' => $this->language->get('text_home'), 40 | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 41 | ); 42 | 43 | $data['breadcrumbs'][] = array( 44 | 'text' => $this->language->get('text_extension'), 45 | 'href' => $this->url->link('extension/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) 46 | ); 47 | 48 | $data['breadcrumbs'][] = array( 49 | 'text' => $this->language->get('heading_title'), 50 | 'href' => $this->url->link('extension/module/consolefilename', 'user_token=' . $this->session->data['user_token'], true) 51 | ); 52 | 53 | $data['action'] = $this->url->link('extension/module/consolefilename', 'user_token=' . $this->session->data['user_token'], true); 54 | 55 | $data['cancel'] = $this->url->link('extension/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); 56 | 57 | $data['header'] = $this->load->controller('common/header'); 58 | $data['column_left'] = $this->load->controller('common/column_left'); 59 | $data['footer'] = $this->load->controller('common/footer'); 60 | 61 | $this->response->setOutput($this->load->view('extension/module/consolefilename', $data)); 62 | } 63 | 64 | protected function validate() { 65 | if (!$this->user->hasPermission('modify', 'extension/module/consolefilename')) { 66 | $this->error['warning'] = $this->language->get('error_permission'); 67 | } 68 | 69 | return !$this->error; 70 | } 71 | } -------------------------------------------------------------------------------- /src/Generation/Commands/WkOcSql.php: -------------------------------------------------------------------------------- 1 | setName('app:oc-sql') 22 | ->addArgument('commond_name', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Please enter product name.'); 23 | } 24 | 25 | protected function execute(InputInterface $input, OutputInterface $output) { 26 | 27 | if(isset($input->getArgument('commond_name')[0])) 28 | { 29 | if($input->getArgument('commond_name')[0]=='oc_tables') { 30 | $this->getTables($output); 31 | } elseif ($input->getArgument('commond_name')[0]=='export') { 32 | if (isset($input->getArgument('commond_name')[1]) && $input->getArgument('commond_name')[1]!='') { 33 | $this->exportTable($output,$input->getArgument('commond_name')[1]); 34 | } else { 35 | $output->writeln('Invalid parameter.'); 36 | die; 37 | } 38 | } elseif($input->getArgument('commond_name')[0]=='import') { 39 | if (isset($input->getArgument('commond_name')[1]) && $input->getArgument('commond_name')[1]!='') { 40 | $this->importTable($output,$input->getArgument('commond_name')[1]); 41 | // $output->writeln('Invalid parameter.'); 42 | } else { 43 | $output->writeln('Invalid parameter.'); 44 | die; 45 | } 46 | 47 | 48 | } else { 49 | $output->writeln('Please select valid action name.'); 50 | die; 51 | } 52 | } 53 | } 54 | 55 | private function connObject() { 56 | $conn = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD,DB_DATABASE); 57 | return $conn; 58 | } 59 | 60 | private function getTables($output) { 61 | $db = $this->connObject(); 62 | 63 | $output->writeln(DIR_SYSTEM . 'library/db.php'); 64 | $data = "SELECT table_name FROM information_schema.tables WHERE table_schema='" . DB_DATABASE . "'"; 65 | 66 | $result = mysqli_query($db,$data); 67 | $i=1; 68 | while($row = $result->fetch_assoc()) { 69 | $output->writeln($i . ' Table name : ' . $row['table_name']); 70 | $i++; 71 | } 72 | } 73 | private function exportTable($output, $table_name) { 74 | if (!is_dir('sql_export')) { 75 | mkdir('sql_export', 0777, true); 76 | } 77 | 78 | if ($table_name== 'all') { 79 | $command = 'mysqldump -u ' . DB_USERNAME . ' -p ' . DB_DATABASE . ' > ./sql_export/' . DB_DATABASE . '.sql'; 80 | exec($command); 81 | $output->writeln(' Database successfully export.'); 82 | } else { 83 | $command = 'mysqldump -u ' . DB_USERNAME . ' -p ' . DB_DATABASE . ' ' . $table_name . '> ./sql_export/' . $table_name . '.sql'; 84 | exec($command); 85 | $output->writeln(' Table name successfully export : ' . $table_name); 86 | } 87 | } 88 | private function importTable($output,$file_name) { 89 | if (!is_dir('sql_import')) { 90 | mkdir('sql_import', 0777, true); 91 | } 92 | $command = 'mysql -u ' . DB_USERNAME . ' -p ' . DB_DATABASE . ' < ./sql_import/' . $file_name . '.sql'; 93 | $output->writeln($command); 94 | exec($command); 95 | $output->writeln(' Table import successfully: ' . $file_name); 96 | } 97 | 98 | } 99 | // console end 100 | 101 | ?> 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Webkul opencart console application 2 | 3 | ## Overview 4 | 5 | Webkul opencart console application is used to automate the opencart installation, module creation, clearing the cache files and database import/export via console commands. 6 | 7 | ## Getting started 8 | 9 | Clone this project over the directory where you will keep your opencart root setup. 10 | 11 | ## Prerequisite 12 | 13 | Before using this app, you must have opencart installed (not for the opencart installer console) on your server and composer on your system. If composer is not installed on your system then run the following commands- 14 | - Syntax: curl -s http://getcomposer.org/installer | php 15 | - Syntax: php composer.phar install 16 | - After successfully installation of composer, you will see "vendor" and "composer.phar" directory and file (PHP Archive). 17 | 18 | 19 | ## Installing 20 | 21 | Please follow the instruction to use this with opencart platform. 22 | 23 | 1) Put app and src folder and composer.json file on your installation root 24 | 25 | 2) Open your command/terminal and go to your desired installation directory 26 | 27 | 3) To download run command [composer install] and if you have made any changes to in your composer.json file for version then run command [composer update] 28 | 29 | 4) After the composer is installed successfully, now you can use the console commands by following below instruction. 30 | 31 | ### Opencart Installer 32 | This console command is used to install the opencart on your system 33 | 34 | #### How to use 35 | By using this console app you can create Opencart setup for the 2.x.x.x,3.x.x.x versions. 36 | - Step 1: Execute the following command on console 37 | - Syntax: app/console setup:install-opencart 38 | - Step 2: Required values e.g hostname, username, etc so either you can enter manually or pass with command. 39 | - Step 2: Enter required options. 40 | - Manual Syntax: --manual=1 You will be asked to enter each values. 41 | - Automatic Syntax: --db_hostname=localhost --db_username=root --db_password=root --db_database=console --db_port=80 --db_prefix=oc_ --username=admin --password=admin --email=johndoe@console.com --http_server=http://127.0.0.1/opencart-install/ --oc_version=2.3.0.2 --destination=/path/of-the-your/opencart-setup 42 | - Step 3: If all the options are valid then required opencart will be downloaded and installed. 43 | - Step 4: You will get your store and admin url with success message. 44 | 45 | ### Module genrator 46 | 47 | This console command is used to create skeleton of the basic module file structure on admin and catalog as well. 48 | 49 | #### How to use 50 | run command [app/console generate:module] and answer the questions and at last your extension will be ready, which you can see at your admin side and now you can start writing your logic for particular extension. 51 | 52 | ### Database import/export 53 | 54 | This console command is used to export/import sql from/on the opencart database. 55 | 56 | ### How to use 57 | 58 | #### For Show all list of opencart table 59 | 60 | command : php app/console app:oc-sql oc_tables 61 | 62 | #### Export all table 63 | 64 | command : php app/console app:oc-sql export all 65 | 66 | #### Export single table 67 | 68 | command : php app/console app:oc-sql export table_name 69 | 70 | #### Import table 71 | 72 | command : php app/console app:oc-sql import table_name 73 | 74 | Note : For import table we put the sql file inside the sql_import folder 75 | 76 | and export command file will be in sql_export folder 77 | 78 | ### Opencart cache clear 79 | 80 | This console command is used to clear the cache of your project using the command mentioned below. 81 | 82 | Run the command 83 | - app/console clearcache 84 | 85 | ### Opencart create dummy data 86 | 87 | This console command is used to create dummy data for Customer, Order, Product, Category. 88 | 89 | ### How to use 90 | 91 | #### for create dummy product 92 | command : php app/console app:dummy-data create-product 93 | 94 | #### for create dummy customer 95 | command : php app/console app:dummy-data create-customer 96 | 97 | #### for create dummy category 98 | command : php app/console app:dummy-data create-category 99 | 100 | #### for create dummy order 101 | command : php app/console app:dummy-data create-order 102 | 103 | ## Deployment 104 | This project is still under process. There are some command need to add. 105 | 106 | 107 | ## Versioning 108 | 1.0.0.0 109 | . 110 | 111 | ## Author 112 | * **Webkul Software Private Limited (https://webkul.com)** - 113 | 114 | ## License 115 | 116 | This project is licensed under the *Webkul Software Private Limited* License - see the [LICENSE.md](https://store.webkul.com/license.html) file for details 117 | 118 | ## Acknowledgments 119 | 120 | * This project is using symfony bundle to create commands (https://github.com/symfony/console) 121 | -------------------------------------------------------------------------------- /src/Generation/Commands/SetUpOpencart.php: -------------------------------------------------------------------------------- 1 | setName('setup:install-opencart') 65 | 66 | // the short description shown while running "php bin/console list" 67 | ->setDescription('Download Opencart and Setup Opencart with Database.') 68 | 69 | // the full command description shown when running the command with 70 | // the "--help" option 71 | ->setHelp('This command allows you to download and install any version of the opencart...') 72 | 73 | // the "--db_hostname=localhost" option 74 | ->addOption( 75 | 'db_hostname', 76 | null, 77 | InputOption::VALUE_REQUIRED, 78 | 'If set, will be used as database host' 79 | ) 80 | 81 | // the "--db_username=webkul" option 82 | ->addOption( 83 | 'db_username', 84 | null, 85 | InputOption::VALUE_REQUIRED, 86 | 'If set, will be used as database username' 87 | ) 88 | 89 | // the "--db_password=webkul" option 90 | ->addOption( 91 | 'db_password', 92 | null, 93 | InputOption::VALUE_REQUIRED, 94 | 'If set, will be used as database password' 95 | ) 96 | 97 | // the "--db_database=console" option 98 | ->addOption( 99 | 'db_database', 100 | null, 101 | InputOption::VALUE_REQUIRED, 102 | 'If set, will be used as database name' 103 | ) 104 | 105 | // the "--db_prefix=_oc" option 106 | ->addOption( 107 | 'db_prefix', 108 | null, 109 | InputOption::VALUE_REQUIRED, 110 | 'If set, will be used as database tables prefix' 111 | ) 112 | 113 | // the "--db_port=80" option 114 | ->addOption( 115 | 'db_port', 116 | null, 117 | InputOption::VALUE_REQUIRED, 118 | 'If set, will be used as database port' 119 | ) 120 | 121 | // the "--username=admin" option 122 | ->addOption( 123 | 'username', 124 | null, 125 | InputOption::VALUE_REQUIRED, 126 | 'If set, will be used as admin panel username' 127 | ) 128 | 129 | // the "--password=admin" option 130 | ->addOption( 131 | 'password', 132 | null, 133 | InputOption::VALUE_REQUIRED, 134 | 'If set, will be used as admin panel password' 135 | ) 136 | 137 | // the "--email=johndoe@opencart.com" option 138 | ->addOption( 139 | 'email', 140 | null, 141 | InputOption::VALUE_REQUIRED, 142 | 'If set, will be used as admin user email' 143 | ) 144 | 145 | // the "--http_server=127.0.0.1" option 146 | ->addOption( 147 | 'http_server', 148 | null, 149 | InputOption::VALUE_REQUIRED, 150 | 'If set, will be used as server path' 151 | ) 152 | 153 | // the "--oc_version=2.3.0.2" option 154 | ->addOption( 155 | 'oc_version', 156 | null, 157 | InputOption::VALUE_REQUIRED, 158 | 'If set, will install provided opencart version' 159 | ) 160 | 161 | // the "--destination=/home/users/user_name/www/html/opencart_install" option 162 | ->addOption( 163 | 'destination', 164 | null, 165 | InputOption::VALUE_REQUIRED, 166 | 'If set, will install provided opencart version into destination path' 167 | ) 168 | 169 | // the "--manual=1" option 170 | ->addOption( 171 | 'manual', 172 | null, 173 | InputOption::VALUE_OPTIONAL, 174 | 'If set, will ask for all required values to enter manually' 175 | ); 176 | } 177 | 178 | protected function execute(InputInterface $input, OutputInterface $output) 179 | { 180 | require_once('language/english/language.php'); 181 | $this->language = $data; 182 | 183 | $this->output = $output; 184 | 185 | $values_collection = array(); 186 | if ($input->getOption('manual')) { 187 | $helper = $this->getHelper('question'); 188 | foreach($this->required_options as $option) { 189 | $question = new Question('' . $this->language[$option] . ': '); 190 | $values_collection[$option] = $helper->ask($input, $output, $question); 191 | 192 | //Restrict for blank value 193 | while(!$values_collection[$option]) { 194 | $output->writeln("\n" . $this->language['error_wrong_answer'] . "\n"); 195 | $values_collection[$option] = $helper->ask($input, $output, $question); 196 | } 197 | 198 | //validate for versions 199 | if ($option == 'oc_version') { 200 | while(!in_array($values_collection[$option],$this->opencart_versions)) { 201 | $output->writeln("\n" . $this->language['error_version'] . "\n"); 202 | foreach($this->opencart_versions as $version) { 203 | $output->writeln($version . "\n"); 204 | } 205 | $values_collection[$option] = $helper->ask($input, $output, $question); 206 | } 207 | } 208 | 209 | } 210 | $this->options = $values_collection; 211 | 212 | //function call to validate directory 213 | while (!is_dir($this->options['destination'])) { 214 | $output->writeln("\n" . $this->language['error_wrong_answer'] . "\n"); 215 | $this->options['destination'] = $helper->ask($input, $output, new Question(''.$this->language['destination'] . ': ')); 216 | } 217 | } else { 218 | // to check all required options 219 | foreach($this->required_options as $option) { 220 | if (!$input->getOption($option)) { 221 | $this->error[$option] = $option; 222 | $output->writeln(ucwords(str_replace("_"," ",$option)) . $this->language['text_option_required']); 223 | } else { 224 | $values_collection[$option] = $input->getOption($option); 225 | } 226 | } 227 | $this->options = $values_collection; 228 | } 229 | if ($this->error) { 230 | exit; 231 | } else { 232 | $output->writeln([ 233 | '', 234 | '******** ' . $this->language["text_welcome"] . ' ********', 235 | '===========================================', 236 | '', 237 | '', 238 | ]); 239 | $destination = $this->options['destination']; 240 | if (!$destination || !is_dir($destination)) { 241 | exit($this->language['error_destination']); 242 | } else { 243 | $this->destination = $destination; 244 | $this->dir_path = getcwd(); 245 | 246 | // to check database details and if database not found then create 247 | $this->checkDatabase(); 248 | } 249 | } 250 | 251 | // To download provided opencart version 252 | if ($this->downloadOpencartZip()) { 253 | 254 | if (version_compare($this->options['oc_version'],'2.3.0.0','>=')) { 255 | $file = $this->options['destination'] . 'opencart-'.$this->options['oc_version'] . '/upload/system/startup.php'; 256 | if (is_file($file)) { 257 | $contents = file_get_contents($file); 258 | $find = html_entity_decode('if ((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) || $_SERVER['SERVER_PORT'] == 443) {',ENT_QUOTES,"UTF-8"); 259 | $find1 = html_entity_decode('if (is_file(DIR_STORAGE . 'vendor/autoload.php')) {',ENT_QUOTES,"UTF-8"); 260 | $replace = html_entity_decode('if ((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) {',ENT_QUOTES,"UTF-8"); 261 | $replace1 = html_entity_decode('if (defined('DIR_STORAGE') && is_file(DIR_STORAGE . 'vendor/autoload.php')) {',ENT_QUOTES,"UTF-8"); 262 | $contents = str_replace($find,$replace,$contents); 263 | $contents = str_replace($find1,$replace1,$contents); 264 | file_put_contents($file,$contents); 265 | } 266 | } 267 | $output->writeln([ 268 | '', 269 | '******** ' . $this->language["text_install_step"] . ' ********', 270 | '===========================================', 271 | '', 272 | '', 273 | ]); 274 | $version = '/opencart-' . $this->options['oc_version']; 275 | $command = 'php ' . $this->destination . $version . '/upload/install/cli_install.php install' . ' --db_hostname ' . $this->options['db_hostname'] . ' --db_username ' . $this->options['db_username'] . ' --db_password ' . $this->options['db_password'] . ' --db_database ' . $this->options['db_database'] . ' --db_driver mysqli --db_port ' . $this->options['db_port'] . ' --db_prefix ' . $this->options['db_prefix'] . ' --username ' . $this->options['username'] . ' --password ' . $this->options['password'] . ' --email ' . $this->options['email'] . ' --http_server ' . $this->options['http_server'] . $version . '/upload/'; 276 | echo shell_exec($command); 277 | 278 | unlink($this->dir_path . '/' . $this->options['oc_version'] . '.zip'); 279 | } else { 280 | exit($this->language['error_download']); 281 | } 282 | } 283 | 284 | public function downloadOpencartZip() 285 | { 286 | $status = false; 287 | $path = $this->dir_path . '/' . $this->options['oc_version'] . '.zip'; 288 | $output = shell_exec($this->dir_path . '/app/install_oc.sh ' . $this->options['oc_version']); 289 | 290 | if ((int)$output) { 291 | if (file_exists($path)) { 292 | $version_zip= new \ZipArchive; 293 | if ($version_zip->open($path) === TRUE) { 294 | $version_zip->extractTo($this->destination); 295 | $version_zip->close(); 296 | $status = true; 297 | } 298 | } 299 | } 300 | return $status; 301 | } 302 | 303 | public function checkDatabase() 304 | { 305 | $connection = @mysqli_connect($this->options['db_hostname'],$this->options['db_username'],$this->options['db_password']); 306 | 307 | if(!$connection) { 308 | exit($this->language['error_connection']."\n\n"); 309 | } else { 310 | $db = $this->options['db_database']; 311 | if(!mysqli_select_db($connection,$db)) { 312 | $sql = "CREATE DATABASE IF NOT EXISTS " . $db; 313 | mysqli_query($connection,$sql); 314 | } 315 | } 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /src/Generation/Commands/dummyData.php: -------------------------------------------------------------------------------- 1 | setName('app:dummy-data') 24 | ->addArgument('command_name', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Please enter command name.'); 25 | 26 | } 27 | 28 | protected function execute(InputInterface $input, OutputInterface $output) { 29 | 30 | $command = $input->getArgument('command_name')[0]; 31 | if($command == 'create-product') { 32 | $this->createProduct($input , $output); 33 | } else if($command == 'create-customer') { 34 | $this->createUser($input , $output); 35 | } else if($command == 'create-category') { 36 | $this->createCategory($input , $output); 37 | } else if($command == 'create-order') { 38 | $this->createOrder($input , $output); 39 | } else { 40 | $output->writeln('Command not found'); 41 | } 42 | } 43 | 44 | public function createProduct($input , $output) { 45 | $helper = $this->getHelper('question'); 46 | $q1 = new Question("Product Name: "); 47 | $q2 = new Question("Model: "); 48 | $q3 = new Question("Product meta title: "); 49 | $q4 = new Question("Product Price: "); 50 | $q5 = new Question("Product Quantity: "); 51 | $q6 = new Question("No of Product: "); 52 | 53 | $data = array(); 54 | $data['name'] = $name = $helper->ask($input, $output, $q1); 55 | $data['model'] = $model = $helper->ask($input, $output, $q2); 56 | $data['meta_title'] = $meta_title = $helper->ask($input, $output, $q3); 57 | $data['price'] = (int)$helper->ask($input, $output, $q4); 58 | $data['quantity'] = (int)$helper->ask($input, $output, $q5); 59 | $no_of_product = (int)$helper->ask($input, $output, $q6); 60 | if($this->validateProduct($data)) { 61 | $this->addProduct($data); 62 | for($i = 1; $i <= $no_of_product; $i++) { 63 | $data['name'] = $name . ' ' . $i; 64 | $data['model'] = $model . ' ' . $i; 65 | $data['meta_title'] = $meta_title . ' ' . $i; 66 | $this->addProduct($data); 67 | } 68 | } else { 69 | $output->writeln('Empty not allow..!'); 70 | die(); 71 | } 72 | $output->writeln($no_of_product . ' product have been created'); 73 | } 74 | 75 | public function createUser($input , $output) { 76 | $helper = $this->getHelper('question'); 77 | $q1 = new Question("Enter First Name: "); 78 | $q2 = new Question("Enter Last Name: "); 79 | $q3 = new Question("Enter Email: "); 80 | $q4 = new Question("Enter Telephone: "); 81 | $q5 = new Question("Enter Password: "); 82 | $q6 = new Question("Enter the number of customer "); 83 | 84 | $data = array(); 85 | $data['first_name'] = $first_name = $helper->ask($input, $output, $q1); 86 | $data['last_name'] = $last_name = $helper->ask($input, $output, $q2); 87 | $data['email'] = $helper->ask($input, $output, $q3); 88 | $data['phone'] = $helper->ask($input, $output, $q4); 89 | $data['password'] = $helper->ask($input, $output, $q5); 90 | $no_of_customer = (int)$helper->ask($input, $output, $q6); 91 | if($this->validateUser($data)) { 92 | $this->addUser($data); 93 | for($i = 1; $i <= $no_of_customer; $i++) { 94 | $rand = rand(4,9999); 95 | $data['last_name'] = $last_name . ' ' . $i; 96 | $data['email'] = $first_name . $rand . '@gmail.com'; 97 | $this->addUser($data); 98 | } 99 | } else { 100 | $output->writeln('Empty not allow..!'); 101 | die(); 102 | } 103 | $output->writeln($no_of_customer . ' customer have been created'); 104 | } 105 | 106 | public function validateUser($data) { 107 | $status = true; 108 | if(empty($data['first_name']) || empty($data['last_name']) || empty($data['email']) || empty($data['phone']) || empty($data['password'])) { 109 | $status = false; 110 | } 111 | return $status; 112 | } 113 | 114 | public function validateProduct($data) { 115 | $status = true; 116 | if(empty($data['name']) || empty($data['model']) || empty($data['meta_title'])) { 117 | $status = false; 118 | } 119 | return $status; 120 | } 121 | 122 | public function createCategory($input , $output) { 123 | $helper = $this->getHelper('question'); 124 | $q1 = new Question("Category Name: "); 125 | $q2 = new Question("category meta title: "); 126 | $q3 = new Question("No of Category: "); 127 | 128 | $data = array(); 129 | $data['name'] = $name = $helper->ask($input, $output, $q1); 130 | $data['meta_title'] = $meta_title = $helper->ask($input, $output, $q2); 131 | $no_of_category = (int)$helper->ask($input, $output, $q3); 132 | if($this->validateCategory($data)) { 133 | $this->addCategory($data); 134 | for($i = 1; $i <= $no_of_category; $i++) { 135 | $rand = rand(4,9999); 136 | $data['name'] = $name . ' ' . $rand; 137 | $data['meta_title'] = $meta_title . ' ' . $rand; 138 | $this->addCategory($data); 139 | } 140 | } else { 141 | $output->writeln('Empty not allow..!'); 142 | die(); 143 | } 144 | $output->writeln($no_of_category . ' Category have been created'); 145 | } 146 | 147 | public function validateCategory($data) { 148 | $status = true; 149 | if(empty($data['name']) || empty($data['meta_title'])) { 150 | $status = false; 151 | } 152 | return $status; 153 | } 154 | 155 | public function createOrder($input , $output) { 156 | $data = array(); 157 | $helper = $this->getHelper('question'); 158 | $q1 = new Question("No of Orders: "); 159 | $no_of_orders = (int)$helper->ask($input, $output, $q1); 160 | $data = $this->getDefaultOrder(); 161 | 162 | for ($i = 0; $i < $no_of_orders; $i++) { 163 | $data['invoice_prefix'] = 'INV-2019-' . $i; 164 | $this->addOrder($data); 165 | } 166 | $output->writeln($no_of_orders . ' Order have been created'); 167 | } 168 | 169 | public function addUser($data) { 170 | $conn = $this->connObject(); 171 | $query = "INSERT INTO `" . DB_PREFIX . "customer` SET customer_group_id = '" . $this->getSetting('config_customer_group_id') . "' ,store_id = '" . $this->getSetting('config_store_id') . "', language_id = '" . $this->getSetting('config_language_id') . "',firstname ='" . $this->escape($data['first_name']) . "' , lastname = '" . $this->escape($data['last_name']) . "' , email = '" . $this->escape($data['email']) . "' , telephone = '" . $this->escape($data['phone']) . "', fax = 'test', salt = '" . $this->escape($salt = $this->token(9)) . "' , password = '" . $this->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', custom_field = 'test', ip = '111.11.11.11', safe = '1', token = 'test', `code` = 'test', status = '1', date_added = NOW()"; 172 | $result = mysqli_query($conn,$query); 173 | return $conn->insert_id; 174 | } 175 | 176 | public function addProduct($data) { 177 | $conn = $this->connObject(); 178 | 179 | $query = "INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->escape($data['model']) . "', sku = 'test', upc = 'test', ean = 'test', jan = 'test', isbn = 'test', mpn = 'test', location = 'test', quantity = '" . (int)$data['quantity'] . "', tax_class_id = '9', stock_status_id = '7', date_available = NOW(), manufacturer_id = '0', price = '" . (float)$data['price'] . "', `status` = '1', date_added = NOW(), date_modified = NOW()"; 180 | mysqli_query($conn,$query); 181 | $product_id = $conn->insert_id; 182 | 183 | $query = "INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '1', name = '" . $this->escape($data['name']) . "', description = '" . $this->escape($data['name']) . "', tag = 'test', meta_title = '" . $this->escape($data['meta_title']) . "', meta_description = '" . $this->escape($data['meta_title']) . "', meta_keyword = '" . $this->escape($data['meta_title']) . "'"; 184 | $result = mysqli_query($conn,$query); 185 | 186 | $query = "INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '0'"; 187 | $result = mysqli_query($conn,$query); 188 | } 189 | 190 | public function addCategory($data) { 191 | $conn = $this->connObject(); 192 | $query = "INSERT INTO " . DB_PREFIX . "category SET parent_id = '0', `top` = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', `column` = '0', `sort_order` = '0', status = '1', date_modified = NOW(), date_added = NOW()"; 193 | mysqli_query($conn,$query); 194 | $category_id = $conn->insert_id; 195 | 196 | $query = "INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '1', name = '" . $this->escape($data['name']) . "', description = '" . $this->escape($data['name']) . "', meta_title = '" . $this->escape($data['meta_title']) . "', meta_description = '" . $this->escape($data['meta_title']) . "', meta_keyword = '" . $this->escape($data['meta_title']) . "'"; 197 | mysqli_query($conn,$query); 198 | 199 | $query = "INSERT INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_id . "', `path_id` = '" . (int)$category_id . "', `level` = '0'"; 200 | mysqli_query($conn,$query); 201 | 202 | $query = "INSERT INTO `" . DB_PREFIX . "category_to_store` SET `category_id` = '" . (int)$category_id . "', `store_id` = '0'"; 203 | mysqli_query($conn,$query); 204 | } 205 | 206 | public function addOrder($data) { 207 | $conn = $this->connObject(); 208 | $query = "INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->escape($data['store_name']) . "', store_url = '" . $this->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->escape($data['firstname']) . "', lastname = '" . $this->escape($data['lastname']) . "', email = '" . $this->escape($data['email']) . "', telephone = '" . $this->escape($data['telephone']) . "', fax = '" . $this->escape($data['fax']) . "', custom_field = '" . $this->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : '') . "', payment_firstname = '" . $this->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->escape($data['payment_lastname']) . "', payment_company = '" . $this->escape($data['payment_company']) . "', payment_address_1 = '" . $this->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->escape($data['payment_address_2']) . "', payment_city = '" . $this->escape($data['payment_city']) . "', payment_postcode = '" . $this->escape($data['payment_postcode']) . "', payment_country = '" . $this->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->escape($data['payment_address_format']) . "', payment_custom_field = '" . $this->escape(isset($data['payment_custom_field']) ? json_encode($data['payment_custom_field']) : '') . "', payment_method = '" . $this->escape($data['payment_method']) . "', payment_code = '" . $this->escape($data['payment_code']) . "', shipping_firstname = '" . $this->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->escape($data['shipping_address_format']) . "', shipping_custom_field = '" . $this->escape(isset($data['shipping_custom_field']) ? json_encode($data['shipping_custom_field']) : '') . "', shipping_method = '" . $this->escape($data['shipping_method']) . "', shipping_code = '" . $this->escape($data['shipping_code']) . "', comment = '" . $this->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', order_status_id = '" . (int)$data['order_status_id'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', marketing_id = '" . (int)$data['marketing_id'] . "', tracking = '" . $this->escape($data['tracking']) . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->escape($data['ip']) . "', forwarded_ip = '" . $this->escape($data['forwarded_ip']) . "', user_agent = '" . $this->escape($data['user_agent']) . "', accept_language = '" . $this->escape($data['accept_language']) . "', date_added = NOW(), date_modified = NOW()"; 209 | mysqli_query($conn , $query); 210 | $order_id = $conn->insert_id; 211 | $product = $data['order_product']; 212 | 213 | $query = "INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->escape($product['name']) . "', model = '" . $this->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', reward = '" . (int)$product['reward'] . "'"; 214 | mysqli_query($conn , $query); 215 | 216 | foreach($data['order_total'] as $total) { 217 | $query = "INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->escape($total['code']) . "', title = '" . $this->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'"; 218 | mysqli_query($conn , $query); 219 | } 220 | 221 | $history = $data['order_history']; 222 | 223 | $query = "INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$history['order_status_id'] . "', notify = '" . (int)$history['notify'] . "', comment = '" . $this->escape($history['comment']) . "', date_added = NOW()"; 224 | mysqli_query($conn , $query); 225 | 226 | } 227 | 228 | public function connObject() { 229 | $conn = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD,DB_DATABASE); 230 | return $conn; 231 | } 232 | 233 | public function escape($param) { 234 | return $param; 235 | } 236 | 237 | public function getSetting($key) { 238 | $conn = $this->connObject(); 239 | $store_id = 0; 240 | $code = "config"; 241 | $setting_data = array(); 242 | $query = "SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->escape($code) . "'"; 243 | 244 | $results = mysqli_query($conn,$query); 245 | 246 | foreach ($results as $result) { 247 | if (!$result['serialized']) { 248 | $setting_data[$result['key']] = $result['value']; 249 | } else { 250 | $setting_data[$result['key']] = json_decode($result['value'], true); 251 | } 252 | } 253 | return isset($setting_data[$key]) && $setting_data[$key] ? $setting_data[$key] : 0 ; 254 | } 255 | 256 | function token($length = 32) { 257 | $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 258 | $max = strlen($string) - 1; 259 | $token = ''; 260 | for ($i = 0; $i < $length; $i++) { 261 | $token .= $string[mt_rand(0, $max)]; 262 | } 263 | return $token; 264 | } 265 | 266 | public function getDefaultOrder() { 267 | 268 | $cust['first_name'] = 'Jhon'; 269 | $cust['last_name'] = 'Doe'; 270 | $cust['email'] = 'jhondoe' . rand(4,9999) . '@webkul.com'; 271 | $cust['phone'] = '1234567891'; 272 | $cust['password'] = 'test'; 273 | $customer_id = $this->addUser($cust); 274 | $conn = $this->connObject(); 275 | $query = "SELECT * FROM `" . DB_PREFIX . "customer` WHERE customer_id = '". (int)$customer_id . "'"; 276 | $result = mysqli_query($conn , $query); 277 | $customer = mysqli_fetch_array($result); 278 | $data['invoice_no'] = 0; 279 | $data['invoice_prefix'] = 'INV-2019-00'; 280 | $data['store_id'] = 0; 281 | $data['store_name'] = 'Your Store'; 282 | $data['store_url'] = 'http://akhileshkumar.com/d1/'; 283 | $data['customer_id'] = $customer['customer_id']; 284 | $data['customer_group_id'] =$customer['customer_group_id']; 285 | $data['firstname'] = $customer['firstname']; 286 | $data['lastname'] = $customer['lastname']; 287 | $data['email'] = $customer['email']; 288 | $data['telephone'] = $customer['telephone']; 289 | $data['fax'] = ''; 290 | $data['payment_firstname'] = $customer['firstname']; 291 | $data['payment_lastname'] = $customer['lastname']; 292 | $data['payment_company'] = ''; 293 | $data['payment_address_1'] = 'Noida'; 294 | $data['payment_address_2'] = ''; 295 | $data['payment_city'] = 'Noida'; 296 | $data['payment_postcode'] = '110092'; 297 | $data['payment_country'] = 'India'; 298 | $data['payment_country_id'] = 99; 299 | $data['payment_zone'] = 'Uttar Pradesh'; 300 | $data['payment_zone_id'] = 1505; 301 | $data['payment_address_format'] = ''; 302 | $data['payment_method'] = 'Bank Transfer'; 303 | $data['payment_code'] = 'bank_transfer'; 304 | $data['shipping_firstname'] = ''; 305 | $data['shipping_lastname'] = ''; 306 | $data['shipping_company'] = ''; 307 | $data['shipping_address_1'] = ''; 308 | $data['shipping_address_2'] = ''; 309 | $data['shipping_city'] = ''; 310 | $data['shipping_postcode'] = ''; 311 | $data['shipping_country'] = ''; 312 | $data['shipping_country_id'] = 0; 313 | $data['shipping_zone'] = ''; 314 | $data['shipping_zone_id'] = 0; 315 | $data['shipping_address_format'] = ''; 316 | $data['shipping_method'] = ''; 317 | $data['shipping_code'] = ''; 318 | $data['comment'] = ''; 319 | $data['total'] = 500.0000; 320 | $data['order_status_id'] = 5; 321 | $data['affiliate_id'] = 0; 322 | $data['commission'] = 0.0000; 323 | $data['marketing_id'] = 0; 324 | $data['tracking'] = ''; 325 | $data['language_id'] = 1; 326 | $data['currency_id'] = 2; 327 | $data['currency_code'] = 'USD'; 328 | $data['currency_value'] = 1.00000000; 329 | $data['ip'] = '192.168.15.165'; 330 | $data['forwarded_ip'] = ''; 331 | $data['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'; 332 | $data['accept_language'] = 'en-GB,en-US;q=0.9,en;q=0.8'; 333 | 334 | $history['order_status_id'] = 5; 335 | $history['notify'] = 1; 336 | $history['comment'] = 'Bank Transfer Instructions test Your order will not ship until we receive payment'; 337 | 338 | $data['order_history'] = $history; 339 | 340 | $product['product_id'] = 43; 341 | $product['name'] = 'MacBook'; 342 | $product['model'] = 'Product 16'; 343 | $product['quantity'] = 1; 344 | $product['price'] = 500.0000; 345 | $product['total'] = 500.0000; 346 | $product['tax'] = 0.0000; 347 | $product['reward'] = 600; 348 | 349 | $data['order_product'] = $product; 350 | 351 | $orderTotal[] = array( 352 | 'code' => 'sub_total', 353 | 'title' => 'Sub-Total', 354 | 'value' => 500.0000, 355 | 'sort_order' => 1 356 | ); 357 | 358 | $orderTotal[] = array( 359 | 'code' => 'total', 360 | 'title' => 'Total', 361 | 'value' => 500.0000, 362 | 'sort_order' => 9 363 | ); 364 | 365 | $data['order_total'] = $orderTotal; 366 | 367 | return $data; 368 | } 369 | } 370 | -------------------------------------------------------------------------------- /src/Generation/Commands/CreateExtension.php: -------------------------------------------------------------------------------- 1 | setName("generate:module") 34 | ->setDescription("It is to create new extension for opencart"); 35 | } 36 | 37 | protected function execute(InputInterface $input, OutputInterface $output) { 38 | require_once('Resources/language-en.php'); 39 | $this->language = $language; 40 | $this->confirmation = array( 41 | 'y', 42 | 'Y', 43 | 'n', 44 | 'N', 45 | ); 46 | 47 | $style = new OutputFormatterStyle('red'); 48 | $output->getFormatter()->setStyle('error', $style); 49 | $helper = $this->getHelper('question'); 50 | $q1 = new Question('' . $this->language['text_ask_version'] . ': '); 51 | $q2 = new Question('' . $this->language['text_ask_ext_name'] . ' : '); 52 | $q3 = new Question('' . $this->language['text_ask_file_name'] . ' : '); 53 | $q4 = new Question('' . $this->language['text_ask_model_file'] . ': '); 54 | $q5 = new Question('' . $this->language['text_ask_catalog_module'] . ': '); 55 | $q6 = new Question('' . $this->language['text_ask_confirm'] . ''); 56 | $details = array(); 57 | 58 | $details['version'] = $helper->ask($input, $output, $q1); 59 | if($details['version'] != '') { 60 | while (!$this->checkVersion($details['version'])) { 61 | $output->writeln("" . sprintf($this->language['error_version'], $details['version']) . ""); 62 | $details['version'] = $helper->ask($input, $output, $q1); 63 | } 64 | } else { 65 | // Not working in loop 66 | $output->writeln("\n" . $this->language['error_version_blank'] . "\n"); 67 | $details['version'] = $helper->ask($input, $output, $q1); 68 | } 69 | $details['ext_name'] = $helper->ask($input, $output, $q2); 70 | 71 | while (!$this->checkExtName($details)) { 72 | $output->writeln("" . $this->ext_name_error . ""); 73 | $details['ext_name'] = $helper->ask($input, $output, $q2); 74 | } 75 | 76 | $details['file_name'] = $helper->ask($input, $output, $q3); 77 | if($details['file_name'] == '') { 78 | $details['file_name'] = $details['ext_name']; 79 | } 80 | 81 | if (!$this->checkFileName($details)) { 82 | $output->writeln("" . $this->ext_file_error . ""); 83 | $details['file_name'] = $helper->ask($input, $output, $q3); 84 | } 85 | 86 | $details['isModel'] = $helper->ask($input, $output, $q4); 87 | while (!$this->checkModelConfirmation($details)) { 88 | $output->writeln("" . $this->language['error_no_answer'] . ""); 89 | $details['isModel'] = $helper->ask($input, $output, $q4); 90 | } 91 | 92 | $details['isCatalog'] = $helper->ask($input, $output, $q5); 93 | 94 | while (!$this->checkCatalogModConfirmation($details)) { 95 | $output->writeln("" . $this->language['error_no_answer'] . ""); 96 | $details['isCatalog'] = $helper->ask($input, $output, $q5); 97 | } 98 | 99 | $output->writeln(sprintf($this->language['text_opencart_version'], $details['version'])); 100 | $output->writeln(sprintf($this->language['text_extension_name'], $details['ext_name'])); 101 | $output->writeln(sprintf($this->language['text_filename'], $details['file_name'])); 102 | $output->writeln(sprintf($this->language['text_model_file'], $details['isModel'])); 103 | $output->writeln(sprintf($this->language['text_at_catalog'], $details['isCatalog'])); 104 | 105 | $details['confirmation'] = $helper->ask($input, $output, $q6); 106 | 107 | while (!$this->checkModConfirmation($details)) { 108 | $output->writeln("" . $this->language['error_no_answer'] . ""); 109 | $details['confirmation'] = $helper->ask($input, $output, $q6); 110 | } 111 | 112 | if($details['confirmation'] == 'y' || $details['confirmation'] == 'Y') { 113 | $details['file_name'] = preg_replace('/[^a-zA-Z_\.]/', '_', $details['file_name']); 114 | $this->generateExt($details); 115 | $output->writeln('' . $this->language['success_mod_created'] . ''); 116 | } else { 117 | $output->writeln('' . $this->language['success_abort_process'] . ''); 118 | } 119 | } 120 | 121 | private function checkVersion($version) { 122 | $versions = array( 123 | '2.0.0.0', 124 | '2.0.1.0', 125 | '2.0.1.1', 126 | '2.0.2.0', 127 | '2.0.3.1', 128 | '2.1.0.1', 129 | '2.1.0.2', 130 | '2.2.0.0', 131 | '2.3.0.0', 132 | '2.3.0.1', 133 | '2.3.0.2', 134 | '3.0.2.0', 135 | '3.0.3.1', 136 | '3.0.3.2', 137 | ); 138 | if(in_array($version, $versions)) { 139 | // require_once('index.php'); 140 | // if(VERSION != $version) { 141 | // $this->error = "your current system is not running the same version"; 142 | // return false; 143 | // } else { 144 | // $this->error = "version is not allowed"; 145 | // } 146 | return true; 147 | } else { 148 | return false; 149 | } 150 | } 151 | 152 | public function checkModelConfirmation($details) { 153 | if($details['isModel'] == '' || !in_array($details['isModel'], $this->confirmation)) { 154 | return false; 155 | } else { 156 | return true; 157 | } 158 | } 159 | 160 | public function checkCatalogModConfirmation($details) { 161 | if($details['isCatalog'] == '' || !in_array($details['isCatalog'], $this->confirmation)) { 162 | return false; 163 | } else { 164 | return true; 165 | } 166 | } 167 | 168 | public function checkModConfirmation($details) { 169 | if($details['confirmation'] == '' || !in_array($details['confirmation'], $this->confirmation)) { 170 | return false; 171 | } else { 172 | return true; 173 | } 174 | } 175 | 176 | private function checkExtName($details) { 177 | if($details['ext_name'] == '') { 178 | $this->ext_name_error = $this->language['error_ext_name']; 179 | return false; 180 | } else { 181 | $cur_path = getcwd() . '/'; 182 | if(version_compare($details['version'], '2.2.0.0') >= 0) { 183 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 184 | $path = $cur_path . 'admin/' . $this->dir_admin_lang3; 185 | } else { 186 | $path = $cur_path . 'admin/' . $this->dir_admin_lang2; 187 | } 188 | } else { 189 | $path = $cur_path . 'admin/' . $this->dir_admin_lang1; 190 | } 191 | // if(!file_exists($path)) { 192 | // $this->ext_name_error = $this->language['error_dir_structure']; 193 | // return false; 194 | // } 195 | if(file_exists($path)) { 196 | $files = scandir($path); 197 | unset($files[0]);unset($files[1]); 198 | foreach ($files as $key => $file) { 199 | if(file_exists($path . $file)) { 200 | include_once($path . $file); 201 | if(isset($_) && $_ && isset($_['heading_title']) && $_['heading_title'] == ucfirst($details['ext_name'])) { 202 | $this->ext_name_error = $this->language['error_extension_exist']; 203 | return false; 204 | } 205 | } 206 | } 207 | } 208 | return true; 209 | } 210 | } 211 | 212 | private function checkFileName($details) { 213 | if($details['file_name'] == '') { 214 | $this->ext_file_error = $this->language['error_file_name']; 215 | return false; 216 | } else { 217 | $cur_path = getcwd() . '/'; 218 | if (version_compare($details['version'], '2.3.0.0', '>=')) { 219 | $path = $cur_path . 'admin/' . $this->dir_admin_controller2; 220 | } else { 221 | $path = $cur_path . 'admin/' . $this->dir_admin_controller1; 222 | } 223 | 224 | if(file_exists($path . $details['file_name'] . '.php')) { 225 | $this->ext_file_error = $this->language['error_file_exist']; 226 | return false; 227 | } 228 | return true; 229 | } 230 | } 231 | 232 | private function generateExt($details) { 233 | $this->constructController($details); 234 | $this->constructView($details); 235 | $this->constructLanguage($details); 236 | if($details['isModel'] == 'y' || $details['isModel'] == 'Y' || $details['isModel'] != '') { 237 | $this->constructModel($details); 238 | } 239 | if($details['isCatalog'] == 'y' || $details['isCatalog'] == 'Y') { 240 | $this->constructControllerCatalog($details); 241 | $this->constructViewCatalog($details); 242 | $this->constructLanguageCatalog($details); 243 | if($details['isModel'] == 'y' || $details['isModel'] == 'Y' || $details['isModel'] != '') { 244 | $this->constructModelCatalog($details); 245 | } 246 | } 247 | } 248 | 249 | private function constructController($details) { 250 | $cur_path = getcwd() . '/'; 251 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 252 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_controller2)) { 253 | mkdir($cur_path . 'admin/' . $this->dir_admin_controller2, 0777, true); 254 | } 255 | $controller_write = fopen($cur_path . 'admin/' . $this->dir_admin_controller2 . $details['file_name'] . ".php", "w"); 256 | $controller = $this->genExtModController($details,$cur_path); 257 | } else { 258 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_controller1)) { 259 | mkdir($cur_path . 'admin/' . $this->dir_admin_controller1, 0777, true); 260 | } 261 | $controller_write = fopen($cur_path . 'admin/' . $this->dir_admin_controller1 . $details['file_name'] . ".php", "w"); 262 | $controller = $this->genModController($details,$cur_path); 263 | } 264 | 265 | fwrite($controller_write, $controller); 266 | fclose($controller_write); 267 | } 268 | 269 | private function constructControllerCatalog($details) { 270 | $cur_path = getcwd() . '/'; 271 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 272 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_controller2)) { 273 | mkdir($cur_path . 'catalog/' . $this->dir_admin_controller2, 0777, true); 274 | } 275 | $controller_write = fopen($cur_path . 'catalog/' . $this->dir_admin_controller2 . $details['file_name'] . ".php", "w"); 276 | $controller = $this->genExtModControllerCatalog($details,$cur_path); 277 | } else { 278 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_controller1)) { 279 | mkdir($cur_path . 'catalog/' . $this->dir_admin_controller1, 0777, true); 280 | } 281 | $controller_write = fopen($cur_path . 'catalog/' . $this->dir_admin_controller1 . $details['file_name'] . ".php", "w"); 282 | $controller = $this->genModControllerCatalog($details,$cur_path); 283 | } 284 | 285 | fwrite($controller_write, $controller); 286 | fclose($controller_write); 287 | } 288 | 289 | private function constructView($details) { 290 | $cur_path = getcwd() . '/'; 291 | $view = $this->genView($details,$cur_path); 292 | if (version_compare($details['version'], '3.0.0.0') >= 0) { 293 | 294 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_view2)) { 295 | mkdir($cur_path . 'admin/' . $this->dir_admin_view2, 0777, true); 296 | } 297 | $view_write = fopen($cur_path . 'admin/' . $this->dir_admin_view2 . $details['file_name'] . ".twig", "w"); 298 | 299 | } elseif (version_compare($details['version'], '2.3.0.0') >= 0) { 300 | 301 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_view2)) { 302 | mkdir($cur_path . 'admin/' . $this->dir_admin_view2, 0777, true); 303 | } 304 | 305 | $view_write = fopen($cur_path . 'admin/' . $this->dir_admin_view2 . $details['file_name'] . ".tpl", "w"); 306 | } else { 307 | 308 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_view1)) { 309 | mkdir($cur_path . 'admin/' . $this->dir_admin_view1, 0777, true); 310 | } 311 | 312 | $view_write = fopen($cur_path . 'admin/' . $this->dir_admin_view1 . $details['file_name'] . ".tpl", "w"); 313 | } 314 | 315 | fwrite($view_write, $view); 316 | fclose($view_write); 317 | } 318 | 319 | private function constructViewCatalog($details) { 320 | $cur_path = getcwd() . '/'; 321 | $view = $this->genViewCatalog($details,$cur_path); 322 | if (version_compare($details['version'], '3.0.0.0') >= 0) { 323 | 324 | if (!is_dir($cur_path . $this->dir_catalog_view2)) { 325 | mkdir($cur_path . $this->dir_catalog_view2, 0777, true); 326 | } 327 | $view_write = fopen($cur_path . $this->dir_catalog_view2 . $details['file_name'] . ".twig", "w"); 328 | 329 | } elseif (version_compare($details['version'], '2.3.0.0') >= 0) { 330 | if (!is_dir($cur_path . $this->dir_catalog_view2)) { 331 | mkdir($cur_path . $this->dir_catalog_view2, 0777, true); 332 | } 333 | $view_write = fopen($cur_path . $this->dir_catalog_view2 . $details['file_name'] . ".tpl", "w"); 334 | } else { 335 | if (!is_dir($cur_path . $this->dir_catalog_view1)) { 336 | mkdir($cur_path . $this->dir_catalog_view1, 0777, true); 337 | } 338 | $view_write = fopen($cur_path . $this->dir_catalog_view1 . $details['file_name'] . ".tpl", "w"); 339 | } 340 | } 341 | 342 | private function constructLanguage($details) { 343 | $cur_path = getcwd() . '/'; 344 | $language = $this->genLang($details,$cur_path); 345 | if(version_compare($details['version'], '2.2.0.0') >= 0) { 346 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 347 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_lang3)) { 348 | mkdir($cur_path . 'admin/' . $this->dir_admin_lang3, 0777, true); 349 | } 350 | $language_write = fopen($cur_path . 'admin/' . $this->dir_admin_lang3 . $details['file_name'] . ".php", "w"); 351 | } else { 352 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_lang2)) { 353 | mkdir($cur_path . 'admin/' . $this->dir_admin_lang2, 0777, true); 354 | } 355 | $language_write = fopen($cur_path . 'admin/' . $this->dir_admin_lang2 . $details['file_name'] . ".php", "w"); 356 | } 357 | } else { 358 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_lang1)) { 359 | mkdir($cur_path . 'admin/' . $this->dir_admin_lang1, 0777, true); 360 | } 361 | $language_write = fopen($cur_path . 'admin/' . $this->dir_admin_lang1 . $details['file_name'] . ".php", "w"); 362 | } 363 | fwrite($language_write, $language); 364 | fclose($language_write); 365 | } 366 | 367 | private function constructLanguageCatalog($details) { 368 | $cur_path = getcwd() . '/'; 369 | // $language = $this->genLang($details,$cur_path); 370 | if(version_compare($details['version'], '2.2.0.0') >= 0) { 371 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 372 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_lang3)) { 373 | mkdir($cur_path . 'catalog/' . $this->dir_admin_lang3, 0777, true); 374 | } 375 | $language_write = fopen($cur_path . 'catalog/' . $this->dir_admin_lang3 . $details['file_name'] . ".php", "w"); 376 | } else { 377 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_lang2)) { 378 | mkdir($cur_path . 'catalog/' . $this->dir_admin_lang2, 0777, true); 379 | } 380 | $language_write = fopen($cur_path . 'catalog/' . $this->dir_admin_lang2 . $details['file_name'] . ".php", "w"); 381 | } 382 | } else { 383 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_lang1)) { 384 | mkdir($cur_path . 'catalog/' . $this->dir_admin_lang1, 0777, true); 385 | } 386 | $language_write = fopen($cur_path . 'catalog/' . $this->dir_admin_lang1 . $details['file_name'] . ".php", "w"); 387 | } 388 | // fwrite($languageWrite, $language); 389 | // fclose($languageWrite); 390 | } 391 | 392 | private function constructModel($details) { 393 | $cur_path = getcwd() . '/'; 394 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 395 | if(!file_exists($cur_path . "admin/model/extension/module")) { 396 | mkdir($cur_path . "admin/model/extension/module", 0777, true); 397 | } 398 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_model2)) { 399 | mkdir($cur_path . 'admin/' . $this->dir_admin_model2, 0777, true); 400 | } 401 | $model_write = fopen($cur_path . 'admin/' . $this->dir_admin_model2 . $details['file_name'] . ".php", "w"); 402 | $model = $this->genExtModel($details,$cur_path); 403 | } else { 404 | if(!file_exists($cur_path . "admin/model/module")) { 405 | mkdir($cur_path . "admin/model/module", 0777, true); 406 | } 407 | if (!is_dir($cur_path . 'admin/' . $this->dir_admin_model1)) { 408 | mkdir($cur_path . 'admin/' . $this->dir_admin_model1, 0777, true); 409 | } 410 | $model_write = fopen($cur_path . 'admin/' . $this->dir_admin_model1 . $details['file_name'] . ".php", "w"); 411 | $model = $this->genModel($details,$cur_path); 412 | } 413 | fwrite($model_write, $model); 414 | fclose($model_write); 415 | } 416 | 417 | private function constructModelCatalog($details) { 418 | 419 | $cur_path = getcwd() . '/'; 420 | 421 | if (version_compare($details['version'], '2.3.0.0') >= 0) { 422 | 423 | if(!file_exists($cur_path . "catalog/model/extension/module")) { 424 | mkdir($cur_path . "catalog/model/extension/module", 0777, true); 425 | } 426 | 427 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_model2)) { 428 | mkdir($cur_path . 'catalog/' . $this->dir_admin_model2, 0777, true); 429 | } 430 | 431 | $model_write = fopen($cur_path . 'catalog/' . $this->dir_admin_model2 . $details['file_name'] . ".php", "w"); 432 | $model = $this->genExtModel($details,$cur_path); 433 | } else { 434 | 435 | if(!file_exists($cur_path . "catalog/model/module")) { 436 | mkdir($cur_path . "catalog/model/module", 0777, true); 437 | } 438 | 439 | if (!is_dir($cur_path . 'catalog/' . $this->dir_admin_model1)) { 440 | mkdir($cur_path . 'catalog/' . $this->dir_admin_model1, 0777, true); 441 | } 442 | 443 | $model_write = fopen($cur_path . 'catalog/' . $this->dir_admin_model1 . $details['file_name'] . ".php", "w"); 444 | $model = $this->genModel($details,$cur_path); 445 | } 446 | fwrite($model_write, $model); 447 | fclose($model_write); 448 | } 449 | 450 | private function genExtModController($details,$cur_path) { 451 | 452 | $file_content = ''; 453 | 454 | if (version_compare($details['version'], '3.0.0.0') >= 0) { 455 | 456 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/3.x.x.x/extModController.txt', 'w'); 457 | } else { 458 | 459 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/extModController.txt', 'w'); 460 | } 461 | 462 | $file = str_replace("consolefilename", $details['file_name'], $file); 463 | $file_content = str_replace("-" . $details['file_name'], ucfirst($this->clearString($details['file_name'])), $file); 464 | 465 | return $file_content; 466 | } 467 | 468 | private function genExtModControllerCatalog($details,$cur_path) { 469 | 470 | $file_content = ''; 471 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/extModControllerCatalog.txt', 'w'); 472 | $file = str_replace("consolefilename", $details['file_name'], $file); 473 | $file_content = str_replace("-" . $details['file_name'], ucfirst($this->clearString($details['file_name'])), $file); 474 | 475 | return $file_content; 476 | } 477 | 478 | private function genModController($details, $cur_path) { 479 | 480 | $file_content = ''; 481 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/extModController.txt', 'w'); 482 | $file = str_replace("consolefilename", $details['file_name'], $file); 483 | $file_content = str_replace("-" . $details['file_name'], ucfirst($this->clearString($details['file_name'])), $file); 484 | return $file_content; 485 | } 486 | 487 | private function genModControllerCatalog($details, $cur_path) { 488 | 489 | $file_content = ''; 490 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/modControllerCatalog.txt', 'w'); 491 | $file = str_replace("consolefilename", $details['file_name'], $file); 492 | $file_content = str_replace("-" . $details['file_name'], ucfirst($this->clearString($details['file_name'])), $file); 493 | return $file_content; 494 | } 495 | 496 | private function genView($details, $cur_path) { 497 | 498 | $file_content = ''; 499 | if (version_compare($details['version'], '3.0.0.0') >= 0) { 500 | 501 | $file_content = str_replace("consolefilename", $details['file_name'], file_get_contents($cur_path . 'src/Generation/Commands/Resources/3.x.x.x/view.txt', 'w')); 502 | } else { 503 | 504 | $file_content = str_replace("consolefilename", $details['file_name'], file_get_contents($cur_path . 'src/Generation/Commands/Resources/view.txt', 'w')); 505 | } 506 | return $file_content; 507 | } 508 | 509 | private function genViewCatalog($details, $cur_path) { 510 | 511 | $file_content = ''; 512 | if (version_compare($details['version'], '3.0.0.0') >= 0) { 513 | 514 | $file_content = file_get_contents($cur_path . 'src/Generation/Commands/Resources/3.x.x.x/viewCatalog.txt', 'w'); 515 | } else { 516 | $file_content = file_get_contents($cur_path . 'src/Generation/Commands/Resources/viewCatalog.txt', 'w'); 517 | } 518 | return $file_content; 519 | } 520 | 521 | private function genLang($details, $cur_path) { 522 | 523 | $file_content = ''; 524 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/lang.txt', 'w'); 525 | $file_content = str_replace("consolefilename", ucfirst($this->clearString($details['ext_name'])), $file); 526 | return $file_content; 527 | } 528 | 529 | private function genModel($details, $cur_path) { 530 | 531 | $file_content = ''; 532 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/model.txt', 'w'); 533 | $file_content = str_replace("-consolefilename", ucfirst($this->clearString($details['file_name'])), $file); 534 | return $file_content; 535 | } 536 | 537 | private function genExtModel($details, $cur_path) { 538 | 539 | $file_content = ''; 540 | $file = file_get_contents($cur_path . 'src/Generation/Commands/Resources/extModel.txt', 'w'); 541 | $file_content = str_replace("-consolefilename", ucfirst($this->clearString($details['file_name'])), $file); 542 | return $file_content; 543 | } 544 | 545 | private function clearString($string) { 546 | 547 | $string = str_replace(' ', ' ', $string); 548 | 549 | return preg_replace('/[^A-Za-z0-9\-]/', '', $string); 550 | } 551 | } 552 | --------------------------------------------------------------------------------