Jump to content

Modifying smarty product variables from a module


Recommended Posts

Hello:

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.

Regards

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

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
Link to comment
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...