|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * 2007-2020 PrestaShop and Contributors |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Academic Free License 3.0 (AFL-3.0) |
| 8 | + * that is bundled with this package in the file LICENSE.txt. |
| 9 | + * It is also available through the world-wide-web at this URL: |
| 10 | + * https://opensource.org/licenses/AFL-3.0 |
| 11 | + * If you did not receive a copy of the license and are unable to |
| 12 | + * obtain it through the world-wide-web, please send an email |
| 13 | + * to license@prestashop.com so we can send you a copy immediately. |
| 14 | + * |
| 15 | + * @author PrestaShop SA <contact@prestashop.com> |
| 16 | + * @copyright 2007-2020 PrestaShop SA and Contributors |
| 17 | + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) |
| 18 | + * International Registered Trademark & Property of PrestaShop SA |
| 19 | + */ |
| 20 | + |
| 21 | +namespace PrestaShop\Module\Ps_Googleanalytics\Database; |
| 22 | + |
| 23 | +use Db; |
| 24 | +use Ps_Googleanalytics; |
| 25 | +use Shop; |
| 26 | + |
| 27 | +class Install |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var Ps_Googleanalytics |
| 31 | + */ |
| 32 | + private $module; |
| 33 | + |
| 34 | + public function __construct(Ps_Googleanalytics $module) |
| 35 | + { |
| 36 | + if (Shop::isFeatureActive()) { |
| 37 | + Shop::setContext(Shop::CONTEXT_ALL); |
| 38 | + } |
| 39 | + |
| 40 | + $this->module = $module; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * installTables |
| 45 | + * |
| 46 | + * @return bool |
| 47 | + */ |
| 48 | + public function installTables() |
| 49 | + { |
| 50 | + $sql = []; |
| 51 | + |
| 52 | + $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ganalytics` ( |
| 53 | + `id_google_analytics` int(11) NOT NULL AUTO_INCREMENT, |
| 54 | + `id_order` int(11) NOT NULL, |
| 55 | + `id_customer` int(10) NOT NULL, |
| 56 | + `id_shop` int(11) NOT NULL, |
| 57 | + `sent` tinyint(1) DEFAULT NULL, |
| 58 | + `date_add` datetime DEFAULT NULL, |
| 59 | + PRIMARY KEY (`id_google_analytics`), |
| 60 | + KEY `id_order` (`id_order`), |
| 61 | + KEY `sent` (`sent`) |
| 62 | + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1'; |
| 63 | + |
| 64 | + $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ganalytics_data` ( |
| 65 | + `id_cart` int(11) NOT NULL, |
| 66 | + `id_shop` int(11) NOT NULL, |
| 67 | + `data` TEXT DEFAULT NULL, |
| 68 | + PRIMARY KEY (`id_cart`) |
| 69 | + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'; |
| 70 | + |
| 71 | + foreach ($sql as $query) { |
| 72 | + if (!Db::getInstance()->execute($query)) { |
| 73 | + return false; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Register Module hooks |
| 82 | + * |
| 83 | + * @return bool |
| 84 | + */ |
| 85 | + public function registerHooks() |
| 86 | + { |
| 87 | + return $this->module->registerHook('displayHeader') && |
| 88 | + $this->module->registerHook('displayAdminOrder') && |
| 89 | + $this->module->registerHook('displayFooter') && |
| 90 | + $this->module->registerHook('displayHome') && |
| 91 | + $this->module->registerHook('displayFooterProduct') && |
| 92 | + $this->module->registerHook('displayOrderConfirmation') && |
| 93 | + $this->module->registerHook('actionProductCancel') && |
| 94 | + $this->module->registerHook('actionCartSave') && |
| 95 | + $this->module->registerHook('displayBackOfficeHeader') && |
| 96 | + $this->module->registerHook('actionCarrierProcess'); |
| 97 | + } |
| 98 | +} |
0 commit comments