首页 > 解决方案 > 如何在 Prestahop 模块上重新安装数据库?

问题描述

我正在尝试自定义 Prestashop 模块,我需要在表中添加两个新的冒号。

问题是数据库已经创建,我猜它是在模块初始化时创建的。因此,如果我现在更改代码,则不会出现更改,并且我不断收到此错误:

在此处输入图像描述

在配置中没有办法做到这一点,我想如果我删除模块,我的代码将会消失。

我能怎么做 ?

也许在一个通用方法中询问 delete 和 create 方法(仅一次)。

我是 Smarty 和 PHP 的新手,我发现这不是创建表的常用方法。

你可以帮帮我吗 ?

我是 Smarty 的新手,我该怎么做?看起来这不是创建表的方法。


$sql = array();
$sql[] =
    'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'opartdevis` (
        `id_opartdevis` int(10) NOT NULL AUTO_INCREMENT,
        `id_shop` int(10) NOT NULL,
        `id_cart` int(10) NOT NULL,
        `id_customer` int(10) NOT NULL,
        `name` varchar(128),
        `message_visible` TEXT,
        `id_customer_thread` int(10),
        `date_add` DATETIME NOT NULL,
        `status` int(2) DEFAULT 0,
        `id_order` int(10) NULL,
        `id_ordered_cart` int(10) NULL,
        `remise` int(10),
        `delivery` int(10),
        PRIMARY KEY (`id_opartdevis`)
    ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';

//1.6.1.0 specific price bug fix
if (version_compare(_PS_VERSION_, '1.6.1.0', '=')) {
    $sql[] = "ALTER TABLE "._DB_PREFIX_."specific_price DROP INDEX id_product_2";
    $sql[] = "ALTER TABLE "._DB_PREFIX_."specific_price ADD INDEX id_product_2 (id_product,id_shop,id_shop_group,id_currency,id_country,id_group,id_customer,id_product_attribute,from_quantity,id_specific_price_rule,id_cart,`from`,`to`)";
}

foreach ($sql as $s) {
    if (!Db::getInstance()->execute($s)) {
        return false;
    }
}

提前致谢

马拉里

标签: phpprestashopsmarty

解决方案


卸载模块时需要还原所有数据库更改。

uninstall()在基本模块文件中定义(或附加到现有)函数并DROP TABLE在创建的表上运行查询。例子:

public function uninstall() {
    if (!parent::uninstall()) {
        return false;
    }

    $sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'opartdevis`';
    if (!Db::getInstance()->execute($sql)) {
        return false;
    }

    return true;
}

这样,当您卸载模块时,该表将被删除(并在您再次安装时重新创建)。


推荐阅读