简体   繁体   English

prestashop 1.7 ps_emailalerts和一个外部模块

[英]prestashop 1.7 ps_emailalerts and an external module

FIRST OF ALL: Sorry for my not-good english. 首先:对不起,我的英语不好。 If something is not understandable let me know, and I will try to explain it better! 如果有些事情无法理解,请告诉我,我会尽力向您解释!

Good evening, I am having some issues with prestashop 1.7 and an external module. 晚上好,我在使用prestashop 1.7和外部模块时遇到了一些问题。

I bought a module to add a fee on cash on delivery, this module got some e-mail variables, like {total_fee} or {total_fee_tax}. 我购买了一个模块来增加货到付款的费用,该模块有一些电子邮件变量,例如{total_fee}或{total_fee_tax}。 It takes this values from database, table ps_orders, values "codfee" and "codfeetax". 它从数据库,表ps_orders,值“ codfee”和“ codfeetax”中获取此值。

In standard mails (located in /themes/themename/mails/it/) the variables works properly, but with the e-mail alerts module (/modules/ps_emailalerts) that variables does NOT work at all. 在标准邮件(位于/ themes / themename / mails / it /中)中,变量可以正常工作,但在电子邮件警报模块(/ modules / ps_emailalerts)中,变量根本不起作用。

I ask to the developer if he could help me and he sent me 2 functions to include in /modules/ps_emailalerts/ps_emailalerts.php 我问开发人员是否可以帮助我,他给我发送了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);
        }

and these 2 variables in the same file 和这两个变量在同一文件中

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

But unfortunately, something don't work properly! 但不幸的是,某些东西无法正常工作! Testing it I see that both variables give the same result "1" instead of the expected "€4" for {total_fee} and "€0.88" for {total_fee_tax} 测试一下,我看到两个变量给出的结果都是“ 1”,而不是{total_fee}的预期结果“€4”和{total_fee_tax}的预期结果为“€0.88”

What's wrong? 怎么了? I hope that somebody help me 我希望有人帮助我

first of all, you should consider overriding the ps_emailalerts module class to add the functions and keep a clean native module: http://build.prestashop.com/howtos/module/how-to-override-modules/ . 首先,您应该考虑重写ps_emailalerts模块类以添加功能并保持干净的本机模块: http ://build.prestashop.com/howtos/module/how-to-override-modules/。

Your problem is that getRow() function returns an array in which the keys are the fields fetched (id_currency and codfee(tax)), not the final value you're expecting. 您的问题是getRow()函数返回一个数组,其中的键是获取的字段(id_currency和codfee(tax)),而不是您期望的最终值。 You have to use these values to calculate/convert the final amount you want, either in each of the function or after calling it. 您必须使用这些值来计算/转换所需的最终金额,无论是在每个函数中还是在调用之后。 If you just have one currency on your store, you can change the getRow() function by getValue() and removing the id_currency field retrieval. 如果您的商店只有一种货币,则可以通过getValue()更改getRow()函数,并删除id_currency字段检索。 It's still better to check the return value of the function (false if query failed), and make all the needed validation (currency matching between the one of the order and the one you want to display the information, ...). 最好检查该函数的返回值(如果查询失败,则返回false),并进行所有需要的验证(订单之一与您要显示信息的订单之间的货币匹配...)。

Good luck 祝好运

You still can use the functions the module developer gave you: 您仍然可以使用模块开发人员为您提供的功能:

  1. Assign the query results to variables 将查询结果分配给变量

     $codfee = $this->getCodFeeByOrderID((int)$params['id_order']); $codfeetax = $this->getCodFeeTaxByOrderID((int)$params['id_order']); 
  2. Get and assign the values you want to your smarty variables: 获取并将所需的值分配给智能变量:

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

i had the same problem with a codfee module and solved modifying the ps_emailalerts.php class this way: 我在codfee模块中遇到了同样的问题,并解决了以这种方式修改ps_emailalerts.php类的问题:

  1. added the getCodFeeByOrderID function: 添加了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. in hookActionValidateOrder function, added to vars array: 在hookActionValidateOrder函数中,添加到vars数组中:
    '{total_fee}' => Tools::displayPrice($order->codfee, $currency)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM