修改注册后端prestashop

q43xntqr  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(624)

我有一个prestashop 1.7网站。
我想在我的数据库中为我的客户添加一个列id\u public,随机id为16个字符。这应该在客户在站点上注册时创建。
我该怎么做?

/**
 * Creates a default 16 char long hexdec string
 * @param number $length
 * @return string
 */
function RandomString( $length = 16 )
{
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++)
    {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
sxpgvts3

sxpgvts31#

1/我建议您不要修改prestashop的本机表,而是创建一个新表。
2/使用actioncustomeraccountadd挂钩,您将能够为用户添加密钥

public function hookActionSubmitAccountBefore($params) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++)
    {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'tablecustom (id_customer, key_random) VALUES ('.(int)$params['id_customer'].',"'.pSQL($randomString).'")');
}

相关问题