Have you tried just calling your function from a my_changes.php admin controller to ensure you don't have any typos, filename issues or other not-so-easily-seen issues? I.e. ?dispatch=my_changes.test_my_function
Hi guys, thanks for the help. I adjusted smarty template to use $product_data.is_special_edition and it's still empty :( (but at least it doesn't error)
Could it be that the PHP hook get_product_data_post is triggered after my template hook product_data.post.tpl? So basically $product_data['is_special_edition'] is not set until after it's called in product template?
Or I'm initialising the PHP hook wrong? The template hook is definitely working as I'm able to output to the product detail page.
A PHP hook is always called before a template hook (unless a template variable modifier is using fn_get_prduct_data).
If you have added your 'is_special_edition' column to the database in the cscart_products table, then if you look at the $product_data in your get_product_data_post hook, you should see it there.
You should then see it in a template variable of {$product_data.is_special_edition}
The flow is PHP code/hooks, then template code/hooks.
in your product_data.post.tpl file you should be able to do:
and then go look for that comment in the resulting page.
Hi guys, thanks for the help. I adjusted smarty template to use $product_data.is_special_edition and it's still empty :( (but at least it doesn't error)
Could it be that the PHP hook get_product_data_post is triggered after my template hook product_data.post.tpl? So basically $product_data['is_special_edition'] is not set until after it's called in product template?
Or I'm initialising the PHP hook wrong? The template hook is definitely working as I'm able to output to the product detail page.
Did you copied and pasted suggested code? Try to temporary add the following line to the fn_my_changes_get_product_data_post function and check
Hmmm… Both your original test and the modified one based on input here seem to behave the same - func.php is not getting picked up, in the new test perhaps both init.php and func.php aren’t getting picked up. You’re not spelling out the complete path to files so lets start with basics to be sure you have init.php and func.php in the right place as you show both php and tpl hook code in just \addons. init.php and func.php go in \app\addons\my_changes\ Template overrides go in \design\themes\yourtheme\templates\addons\my_changes\
Hmmm.... Both your original test and the modified one based on input here seem to behave the same - func.php is not getting picked up, in the new test perhaps both init.php and func.php aren't getting picked up. You're not spelling out the complete path to files so lets start with basics to be sure you have init.php and func.php in the right place as you show both php and tpl hook code in just \addons. init.php and func.php go in \app\addons\my_changes\ Template overrides go in \design\themes\yourtheme\templates\addons\my_changes\
Thank you! I finally have my custom function triggering. I really missed this somehow. It was confusing as there are definitely some init.php and func.php in other adds on under templates.
So my function runs, but adding a variable into product_data as suggested, does not work. Now that I can actually run and debug, I see that product_data in this example is actually a product id., not an array. Any ideas?
The template variable {$product_data} should ALWAYS be an array (even if it's empty). My guess is that your php hook is clobbering the $product_data before it's being set as a template variable.
The template variable {$product_data} should ALWAYS be an array (even if it's empty). My guess is that your php hook is clobbering the $product_data before it's being set as a template variable.
Sorry I should have been more clear.
{$product_data} is populated, I can output it in my template and browse all the vars.
However, I don't get access to it in my function. As suggested in one of the earlier replies, I would be able to access $product_data in my PHP function and add a var to it.
e.g
function fn_my_changes_get_product_data_post(&$product_data, &$auth, &$preview, &$lang_code)
{
$product_data['is_special_edition'] = 'yay';
}
But $product_data is actually the product id above. If I change parameter to product_id, product_data is still null.
{$product_data} is populated, I can output it in my template and browse all the vars.
However, I don't get access to it in my function. As suggested in one of the earlier replies, I would be able to access $product_data in my PHP function and add a var to it.
e.g
function fn_my_changes_get_product_data_post(&$product_data, &$auth, &$preview, &$lang_code)
{
$product_data['is_special_edition'] = 'yay';
}
But $product_data is actually the product id above. If I change parameter to product_id, product_data is still null.
Sorry ignore me, I'd switched to pre when trying to resolve my issues.