Search code examples
phpsmartyprestashop

Add fixed tax to prestashop order


I'd like to add a fixed tax of 2 euros per order to an existing prestashop website. I already added it to every step the client makes, until the last step in which I'm not able to:

the file I want to modify is "modules/bankwire/views/templates/hook/payment_return.tpl" in which I have this line:

{l s='Amount' mod='bankwire'}: <span class="price"><strong>{$total_to_pay}</strong>

If I change the previous line to:

{l s='Amount' mod='bankwire'}: <span class="price"><strong>{$total_to_pay+2}</strong>

my final displayed price is rounded and no € symbol appears (for example if my total price is 54.50 €, when I add 2 euros to it, it becomes 56 instead of 56,50 €)

How can i manage it?

Thanks


Solution

  • $total_to_pay is a formatted price ("56,90 €" instead of "56.90") defined in bankwire module:

    public function hookPaymentReturn($params)
    {
        if (!$this->active)
            return;
    
        $state = $params['objOrder']->getCurrentState();
        if (in_array($state, array(Configuration::get('PS_OS_BANKWIRE'), Configuration::get('PS_OS_OUTOFSTOCK'), Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'))))
        {
            $this->smarty->assign(array(
                'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false),
                'bankwireDetails' => Tools::nl2br($this->details),
                'bankwireAddress' => Tools::nl2br($this->address),
                'bankwireOwner' => $this->owner,
                'status' => 'ok',
                'id_order' => $params['objOrder']->id
            ));
            if (isset($params['objOrder']->reference) && !empty($params['objOrder']->reference))
                $this->smarty->assign('reference', $params['objOrder']->reference);
        }
        else
            $this->smarty->assign('status', 'failed');
        return $this->display(__FILE__, 'payment_return.tpl');
    }
    

    You can get the price like this using the order object:

    {displayPrice price=$objOrder->getOrdersTotalPaid()}