Files
drmaterac.pl/modules/ets_promotion/upgrade/upgrade-1.0.2.php
2025-01-06 20:47:25 +01:00

69 lines
2.5 KiB
PHP

<?php
/**
* Copyright ETS Software Technology Co., Ltd
*
* NOTICE OF LICENSE
*
* This file is not open source! Each license that you purchased is only available for 1 website only.
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future.
*
* @author ETS Software Technology Co., Ltd
* @copyright ETS Software Technology Co., Ltd
* @license Valid for 1 website (or project) for each purchase of license
*/
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_0_2($module)
{
$sqls= array();
if(!$module->checkCreatedColumn('ets_pr_action_rule','apply_discount_code'))
{
$sqls[]= 'ALTER TABLE `'._DB_PREFIX_.'ets_pr_action_rule` ADD `apply_discount_code` VARCHAR(10)';
}
if(!$module->checkCreatedColumn('ets_pr_action_rule','code'))
{
$sqls[]= 'ALTER TABLE `'._DB_PREFIX_.'ets_pr_action_rule` ADD `code` VARCHAR(222)';
}
if(!$module->checkCreatedColumn('ets_pr_action_rule','highlight'))
{
$sqls[]= 'ALTER TABLE `'._DB_PREFIX_.'ets_pr_action_rule` ADD `highlight` INT(1)';
}
if($sqls)
{
foreach($sqls as $sql)
{
Db::getInstance()->execute($sql);
}
}
$rules = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'ets_pr_rule');
if($rules)
{
foreach($rules as $rule)
{
if(isset($rule['code']) && $rule['code'])
{
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'ets_pr_action_rule` SET apply_discount_code="code",code="'.pSQL($rule['code']).'" '.($rule['highlight'] ? ',highlight ="1"':',highlight ="0"').' WHERE id_ets_pr_rule='.(int)$rule['id_ets_pr_rule']);
}
else
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'ets_pr_action_rule` SET apply_discount_code="auto",code="",highlight ="0" WHERE id_ets_pr_rule='.(int)$rule['id_ets_pr_rule']);
}
}
if(!$module->checkCreatedColumn('ets_pr_rule','code'))
{
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'ets_pr_rule` DROP `code`');
}
if(!$module->checkCreatedColumn('ets_pr_rule','highlight'))
{
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'ets_pr_rule` DROP `highlight`');
}
return true;
}