Prestashop 1.7.8 Example for E-commerce

Andrew Chornyy - 001
Andrew Chornyy

CEO Plerdy — expert in SEO&CRO with over 14 years of experience.

For PrestaShop, you would be implementing this on the order confirmation page. This means you would need to alter the Order Confirmation Controller (controllers/front/OrderConfirmationController.php) and the corresponding template (themes/classic/templates/checkout/order-confirmation.tpl).

Here’s the basic structure of what you would do:

1.Modify the OrderConfirmationController
(controllers/front/OrderConfirmationController.php):

public function postProcess()
{
...
$order = $this->module->currentOrder;
$currency = $this->context->currency->iso_code;
$cart = $this->context->cart;

$money = $cart->getOrderTotal();
$quantity = $cart->nbProducts();

$this->context->smarty->assign('ids', $order);
$this->context->smarty->assign('money', $money);
$this->context->smarty->assign('quantity', $quantity);
...
}

In the code above, we get the current order number, the total amount of the order, and the total quantity of items in the order, and assign these to Smarty variables.

2.Add script to order confirmation page
(themes/classic/templates/checkout/order-confirmation.tpl):

<script type="text/javascript" defer>
var plerdysendData = {
'type':'commerce',
'data': {
'order_id': {$ids},
'money': {$money},
'quantity': {$quantity}
}
}
</script>

In this code, we use Smarty to output the variables you assigned earlier.

Please note that this is a simple solution, and you might need to handle more complex scenarios, such as dealing with different currencies or different types of products.

Also, don’t forget to backup your files before making changes and test everything thoroughly afterward. It’s generally a good idea to avoid editing core files if possible, and use override files or modules instead to maintain better compatibility with future updates. But for simplicity, this answer doesn’t take that into account.

This code should add the required script to the Order Confirmation page, allowing you to track orders with Plerdy.

Was this helpful?