Jump to content

Modifying smarty product variables from a module

Recommended Posts

Is it possible to modify a smarty product variable (for example $product.show_price) from a display hook associated to the product page (for example displayProductAdditionalInfo) in a module?

Share this post

Link to post
Share on other sites


Yes you can. Just assign again the variable you want and it will be overrided. Remember that $product.show_price  is not a variable, you must override the complet $product variable.


Share this post

Link to post
Share on other sites
  • 2 weeks later...


Thank you for your message. I got one step further, but I still don't know how to update show_price. For example if I do:

            $product = $params['smarty']->getTemplateVars('product');
            print_r('ProductAdditionalInfo - show_price: ' . $product['show_price']);

inside the hook displayProductAdditionalInfo, I get the expected value "ProductAdditionalInfo - show_price: 1". However if I try to update show_price within $product:

            $product->show_price = 0;

I get the error: "Trying to set the index show_price of the LazyArray PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductLazyArray already defined by a method is not allowed"

I tried to find how to update fields of LazyArray but without any success.

If I try to do the similarly in the hook FilterProductContent

        $product = $params['object'];
        print_r('FilterProductContent - show_price: ' . $product['show_price']);
        $product['show_price'] = 0;

I get the same error.

I general I think that the hook FilterProductContent is more appropriate for changing show_price, but I am stuck with this simple problem of updating this field.

  • Like 1

Share this post

Link to post
Share on other sites
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More