Search code examples
javascriptprestashopsmartyprestashop-1.6

Get order id and price without tax and shipping in Prestashop payment return


please how can i get order id and price without tax and shipping in themes/mytheme/modules/bankwire/views/templates/hook/payment_return.tpl to this script

<script type="text/javascript" id="xxxxxxxxxxx" src="https://login.dognet.sk/scripts/fj27g82d"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('xxxxxxxx');
var sale = PostAffTracker.createSale();
sale.setTotalCost( ***** ); //fill price without tax and shipping
sale.setOrderID( ***** ); //fill ID order

PostAffTracker.register();
</script>

sale.setTotalCost({$price_without_tax_and_shpping}); <-- this does not work

Prestashop 1.6.1.13 Is it for affiliate program.

thx for help.

so problem is here enter image description here

code from root/modules/bankwire/bankwire.php

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,
                'price_without_tax_and_shipping' => Tools::displayPrice($params['objOrder']->getTotalProductsWithoutTaxes(), $params['currencyObj'], false)
            ));
            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');
    }

Solution

  • Short way, edit the 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,
                'price_without_tax_and_shipping' => Tools::displayPrice($params['objOrder']->getTotalProductsWithoutTaxes(), $params['currencyObj'], false),
                'affiliate_price' => $params['objOrder']->getTotalProductsWithoutTaxes() // You have to add this
            ));
            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');
    }
    

    Then, try to adapt your script with smarty {literal} tag:

    <script type="text/javascript" id="xxxxxxxxxxx" src="https://login.dognet.sk/scripts/fj27g82d"></script>
    <script type="text/javascript">
    {literal}
        PostAffTracker.setAccountId('xxxxxxxx');
        var sale = PostAffTracker.createSale();
        sale.setTotalCost({/literal}{$affiliate_price}{literal}); //fill price without tax and shipping
        sale.setOrderID({/literal}{$id_order}{literal}); //fill ID order
    
        PostAffTracker.register();
    </script>
    {/literal}
    

    It should works at 99.99%