66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php
|
|
|
|
use Empik\Marketplace\Adapter\ConfigurationAdapter;
|
|
use Empik\Marketplace\Cache\CacheClearer;
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @param EmpikMarketplace $object
|
|
* @return bool
|
|
*/
|
|
function upgrade_module_1_2_0($object)
|
|
{
|
|
(new CacheClearer($object))->clear();
|
|
|
|
$result = true;
|
|
|
|
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'empik_product` (
|
|
`id_empik_product` INT(11) NOT NULL AUTO_INCREMENT,
|
|
`id_product` INT(11) NOT NULL,
|
|
`id_product_attribute` INT(11) NOT NULL,
|
|
`logistic_class` INT(4) NOT NULL DEFAULT 2,
|
|
`product_export` INT(1) NOT NULL DEFAULT 0,
|
|
`offer_export` INT(1) NOT NULL DEFAULT 0,
|
|
`offer_price` DECIMAL(20, 2) NOT NULL DEFAULT 0,
|
|
`offer_price_reduced` DECIMAL(20, 2) NOT NULL DEFAULT 0,
|
|
UNIQUE (`id_product`, `id_product_attribute`),
|
|
PRIMARY KEY (`id_empik_product`)
|
|
)';
|
|
|
|
$sql[] = 'INSERT INTO `' . _DB_PREFIX_ . 'empik_product` (`id_product`, `id_product_attribute`, `logistic_class`, `product_export`, `offer_export`, `offer_price`, `offer_price_reduced`)
|
|
SELECT `id_product`, 0, 0, IF(`empik_product_disabled`, 0, 1), IF(`empik_offer_disabled`, 0, 1), `empik_offer_price`, `empik_offer_price_reduced`
|
|
FROM `' . _DB_PREFIX_ . 'product`
|
|
WHERE (`empik_product_disabled` = 0 OR `empik_offer_disabled` = 0)
|
|
';
|
|
|
|
$sql[] = 'INSERT INTO `' . _DB_PREFIX_ . 'empik_product` (`id_product`, `id_product_attribute`, `logistic_class`, `product_export`, `offer_export`, `offer_price`, `offer_price_reduced`)
|
|
SELECT `id_product`, `id_product_attribute`, 0, 1, 1, `empik_offer_price`, `empik_offer_price_reduced`
|
|
FROM `' . _DB_PREFIX_ . 'product_attribute`
|
|
WHERE (`empik_offer_price` > 0 OR `empik_offer_price_reduced` > 0)
|
|
';
|
|
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product` DROP COLUMN `empik_product_disabled`;';
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product` DROP COLUMN `empik_offer_disabled`;';
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product` DROP COLUMN `empik_offer_price`;';
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product` DROP COLUMN `empik_offer_price_reduced`;';
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product_attribute` DROP COLUMN `empik_offer_price`;';
|
|
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'product_attribute` DROP COLUMN `empik_offer_price_reduced`;';
|
|
|
|
foreach ($sql as $query) {
|
|
$result &= Db::getInstance()->execute($query);
|
|
}
|
|
|
|
if (($tab = Tab::getIdFromClassName('AdminEmpikProductsPrice'))) {
|
|
$tab = new Tab($tab);
|
|
foreach (Language::getLanguages() as $language) {
|
|
$tab->name[$language['id_lang']] = $object->l('Products parameters');
|
|
}
|
|
$result &= $tab->save();
|
|
}
|
|
|
|
return $result;
|
|
}
|