1
votes

I'm using prestashop 1.7 and I have a file in the override / classes that is called Cart.php that has a function similar to this, its purpose is to return an array of objects, the code could be something like this

<?php

class Cart extends CartCore {

public static function getADXFromProducts($id){


    $adxProducts=array();
    return $adxProducts;
}

}

I have the problem from the smarty template "Tpl" where I try to make a call to the static method in this way.

By screen I don't receive any error, but if I activate xdebug in the above override file I do not see it enter the method.

  {assign var=bookProducts value={Cart::getADXFromProducts($cart.id)}}

Thanxs

2
it should be used {assign var=bookProducts value=Cart::getADXFromProducts($cart.id)} - sadlyblue

2 Answers

0
votes

At first, activate a debug mode in your Prestashop within your admin panel Advanced Parameters -> Performance -> Debug mode. It would help you to see any issue if you have it

At second, be sure that you put your override file in the correct path, it has to be 'override/classes/Cart.php'

At third, remove a file app/cache/dev/class_index.php it will be generated automatically and all routes will be regenerated

At last, if you want to get an array as a response you need to define your variable this way

{assign var='bookProducts' value=Cart::getADXFromProducts($cart.id)}

your way {assign var=bookProducts value={Cart::getADXFromProducts($cart.id)}} will work only with strings or numbers

0
votes

The static functions can be called directly in the Smarty files for example:

{Cart::getADXFromProducts($cart.id)}

But this is not recommended, you should call the function in PHP class file and then use the value in Smarty.

$this->context->smarty->assign('bookProducts', Cart::getADXFromProducts($cart.id));