prestashop 1.7 ps_emailalerts 和一个外部模块

prestashop 1.7 ps_emailalerts and an external module

首先:抱歉我的英语不好。如果有什么不明白的地方告诉我,我会尽力解释得更好!

晚上好,我在使用 prestashop 1.7 和外部模块时遇到一些问题。

我买了一个模块来添加货到付款的费用,这个模块有一些电子邮件变量,比如 {total_fee} 或 {total_fee_tax}。它从数据库中获取这些值,table ps_orders,值 "codfee" 和 "codfeetax".

在标准邮件中(位于 /themes/themename/mails/it/)变量正常工作,但是对于电子邮件警报模块(/modules/ps_emailalerts)变量根本不起作用。

我询问开发人员是否可以帮助我,他向我发送了 2 个函数以包含在 /modules/ps_emailalerts/ps_emailalerts.php

public static function getCodFeeByOrderID($id_order)
        {
        return Db::getInstance()->getRow('SELECT id_currency, codfee FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id_order);
        }

public static function getCodFeeTaxByOrderID($id_order)
        {
        return Db::getInstance()->getRow('SELECT id_currency, codfeetax FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id_order);
        }

这两个变量在同一个文件中

        '{total_fee}' => $this->getCodFeeByOrderID((int)$params['order']->id),
        '{total_fee_tax}' => $this->getCodFeeTaxByOrderID((int)$params['order']->id),

但不幸的是,有些东西不能正常工作!测试它我看到两个变量给出相同的结果“1”,而不是 {total_fee} 的预期“€4”和 {total_fee_tax}

的预期“€0.88”

怎么了? 我希望有人能帮助我

首先,您应该考虑覆盖 ps_emailalerts 模块 class 以添加功能并保持干净的本机模块:http://build.prestashop.com/howtos/module/how-to-override-modules/.

您的问题是 getRow() 函数 returns 一个数组,其中的键是获取的字段 ( id_currency 和 codfee(tax)),而不是您期望的最终值。您必须使用这些值 calculate/convert 您想要的最终金额,无论是在每个函数中还是在调用它之后。如果您的商店只有一种货币,您可以通过 getValue 更改 getRow() 函数()并去掉id_currency字段检索。最好检查函数的 return 值(如果查询失败则为 false),并进行所有需要的验证(订单之一与要显示信息的订单之间的货币匹配,... ).

祝你好运

您仍然可以使用模块开发者给您的功能:

  1. 将查询结果赋值给变量

    $codfee = $this->getCodFeeByOrderID((int)$params['id_order']);
    $codfeetax = $this->getCodFeeTaxByOrderID((int)$params['id_order']);
    
  2. 获取您想要的值并将其分配给您的 smarty 变量:

    '{total_fee}' => $codfee['codfee'],
    '{total_fee_tax}' => $codfeetax['codfeetax'],
    

我在 codfee 模块上遇到了同样的问题,并解决了修改 ps_emailalerts.php class 这样的问题:

  1. 添加了 getCodFeeByOrderID 函数:
    public static function getCodFeeByOrderID($id_order)
        {
        return Db::getInstance()->getRow('SELECT id_currency, codfee FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id_order);        
        }
  1. 在 hookActionValidateOrder 函数中,添加到 vars 数组:
    '{total_fee}' => Tools::displayPrice($order->codfee, $currency)