aljon ngo Posted July 26, 2014 Share Posted July 26, 2014 (edited) Hello guys, I created an Module and it is about the delivery tab . My module works fine but when i enable my cache an error occurs. Note that i already clear my cache at Back office and manually in the folder but still same error occurs Notice: Undefined index: product in root/cache/smarty/compile/0b/95/b2/0b95b2da34be544dfa9466aa879d8aa6c52c985e.file.shippingtab.tpl.php on line 34Notice: Im not sure but i think it is because the var $product that is generated by the ProductController.php {if $product->additional_shipping_cost == 0} code {else} {if $product->price|string_format:"%.2f" >= 10000} code {else} code {convertPrice price=$product->additional_shipping_cost} {/if} {/if} any suggestion how can i solve this problem? or code? Edited July 26, 2014 by aljon ngo (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted July 26, 2014 Share Posted July 26, 2014 does your module add the product variable to the smarty engine? if not, then you have 2 options 1) change your if statement to {if $product && $product->additional_shipping_cost == 0} 2) adjust your module hook to detect which product is being viewed, lookup that product and place it into smarty you don't describe what your module does, and what page you are on. have you considered that a product is not in context of the page you are working on? Link to comment Share on other sites More sharing options...
aljon ngo Posted July 28, 2014 Author Share Posted July 28, 2014 (edited) does your module add the product variable to the smarty engine? if not, then you have 2 options 1) change your if statement to {if $product && $product->additional_shipping_cost == 0} 2) adjust your module hook to detect which product is being viewed, lookup that product and place it into smarty you don't describe what your module does, and what page you are on. have you considered that a product is not in context of the page you are working on? I tried #1 solution but same error occurs. In your #2 solution .. can you explain it further thanks. My module is a product page tab that gives information about the shipping method per product .. this shipping info is only a plain text but it changes depending on the additional_shipping_cost and the product price.. the problem in my module i think is that when i activated the cache.. i cannot use the $product variable that is generated by the product page Edited July 28, 2014 by aljon ngo (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted July 28, 2014 Share Posted July 28, 2014 what hook are you using? what cache system are you using? Is it a module? Link to comment Share on other sites More sharing options...
aljon ngo Posted August 4, 2014 Author Share Posted August 4, 2014 what hook are you using? what cache system are you using? Is it a module? im using "productTab" and "productTabContent" hook i just enable the cache to 'YES' and select Force compilation under smarty category Yes it is a custom Module Link to comment Share on other sites More sharing options...
bellini13 Posted August 4, 2014 Share Posted August 4, 2014 With cache enabled, your template files are compiled and stored on the file system, but the ProductController is still called with every request, and places the Product object into smarty so that the compiled template can use it. I also reviewed the ProductController, and it makes no attempt to cache the output from the template, so it should have no bearing. You don't say what version of Prestashop or what theme, so I cannot test this out, but below are some code highlights for getting the product id, loading the Product object and placing it in smarty. I don't believe you need to do this and should focus on fixing the issue you have, but you could try this. get the product id from the page request $id_product = Tools::getValue('id_product'); use it to lookup the product $product = new Product($id_product); put it into smarty engine $this->smarty->assign(array( 'product' => $product, )); 1 Link to comment Share on other sites More sharing options...
aljon ngo Posted August 7, 2014 Author Share Posted August 7, 2014 With cache enabled, your template files are compiled and stored on the file system, but the ProductController is still called with every request, and places the Product object into smarty so that the compiled template can use it. I also reviewed the ProductController, and it makes no attempt to cache the output from the template, so it should have no bearing. You don't say what version of Prestashop or what theme, so I cannot test this out, but below are some code highlights for getting the product id, loading the Product object and placing it in smarty. I don't believe you need to do this and should focus on fixing the issue you have, but you could try this. get the product id from the page request $id_product = Tools::getValue('id_product'); use it to lookup the product $product = new Product($id_product); put it into smarty engine $this->smarty->assign(array( 'product' => $product, )); thanks i just generated the codes in my controller and it works perfectly fine =) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now