drtppp75155
2018-08-25 16:23
浏览 65
已采纳

prestashop 1.7 ps_emailalerts和一个外部模块

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.

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}. It takes this values from database, table ps_orders, values "codfee" and "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.

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

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}

What's wrong? I hope that somebody help me

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongyong6428 2018-08-26 14:33
    已采纳

    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/.

    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. 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. 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, ...).

    Good luck

    已采纳该答案
    打赏 评论
  • dpp10181 2018-08-28 09:13

    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'],
      
    打赏 评论
  • douyi1855 2019-01-29 15:43

    i had the same problem with a codfee module and solved modifying the ps_emailalerts.php class this way:

    1. added the getCodFeeByOrderID function:
        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:
        '{total_fee}' => Tools::displayPrice($order->codfee, $currency)
    
    打赏 评论

相关推荐 更多相似问题