简体   繁体   中英

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.

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

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

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:

  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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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