trenttdogg Posted April 20, 2019 Share Posted April 20, 2019 Hello, I'm using version 7.7 and trying to edit the products.tpl (premium comparison). i am trying to figure out how to put some text in the price-area for each product. Ideally, i would like to put it under the $price/month field. I added a field to DB (tblproducts) called priceDetails and tried to get it to display on the page using: <h3 id="product{$product@iteration}-priceDetails">{$product.priceDetails}</h4> ... it was a shot in the dark which did not work. Any ideas? Thanks, Trent 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 21, 2019 Share Posted April 21, 2019 HI Trent, On 20/04/2019 at 07:14, trenttdogg said: i am trying to figure out how to put some text in the price-area for each product. Ideally, i would like to put it under the $price/month field. I added a field to DB (tblproducts) called priceDetails i'm not sure it was a good idea to add a new column to an existing table - not least because $products is a complex array and it's not just generated from a simple query of the tblproducts table by WHMCS internally. I think the better way might have been to use a new table (perhaps with pid & pricedetails as columns) and used a hook to add it to the products array.... however, we are where we are... On 20/04/2019 at 07:14, trenttdogg said: it was a shot in the dark which did not work. Any ideas? first thought would be to double check that the new variable doesn't exist in the array (logically it shouldn't, and your lack of output seems to confirm that - but confirmation is always good to have!) 🙂 you can do that by adding {debug} to the end of the products.tpl template, refreshing the page in the browser and you should get a popup window of all (actually it's only some) the available Smarty arrays & variables to the template... I suspect the values won't be there... don't forget to remove {debug} from the template when you've finished. if it is missing, then you can add it simply by using a hook - if you had used a separate table, it would have made the database query slightly more complicated than it is, but not by much. <?php # Add Price Details To Products Array Hook # @author brian! use WHMCS\Database\Capsule; function add_price_details_to_products_array_hook($vars) { if ($vars['templatefile'] == "products") { $products = $vars['products']; foreach ($products as $key => $product) { $pricedetails = Capsule::table('tblproducts')->where('id',$product['pid'])->value('priceDetails'); $products[$key]['priceDetails'] = $pricedetails; } return array("products" => $products); } } add_hook("ClientAreaPageCart", 1, "add_price_details_to_products_array_hook"); if it works (it will work with another field, but I haven't got a pricedetails field in my tblproducts table!), then you should a) see the {product.priceDetails} output on the page and b) it should also be present in the $products array when looking at the popup window. 🙂 0 Quote Link to comment Share on other sites More sharing options...
trenttdogg Posted April 23, 2019 Author Share Posted April 23, 2019 Thanks Brian, I did the {debug} and nothing returned, so I guess that's good... Regarding the code that you so kindly wrote: On 4/21/2019 at 1:58 AM, brian! said: <?php # Add Price Details To Products Array Hook # @author brian! use WHMCS\Database\Capsule; function add_price_details_to_products_array_hook($vars) { if ($vars['templatefile'] == "products") { $products = $vars['products']; foreach ($products as $key => $product) { $pricedetails = Capsule::table('tblproducts')->where('id',$product['pid'])->value('priceDetails'); $products[$key]['priceDetails'] = $pricedetails; } return array("products" => $products); } } add_hook("ClientAreaPageCart", 1, "add_price_details_to_products_array_hook"); Which file(s) would I include this? Thanks, for your help. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 24, 2019 Share Posted April 24, 2019 On 23/04/2019 at 03:21, trenttdogg said: Which file(s) would I include this? sorry I should probably have mentioned that bit! 🙄 generally with hooks, you create a .php file in /includes/hooks, give it a memorable filename, copy&paste the code into it, save and the next time you refresh the page in the browser, you should have access to those new variables. i've attached the hook to this post, so just upload it to /includes/hooks and you should be good to go. 🙂 productnewfield.php 0 Quote Link to comment Share on other sites More sharing options...
trenttdogg Posted April 24, 2019 Author Share Posted April 24, 2019 Hi Brian, I got the dreaded "Oops! Something went wrong and we couldn't process your request." error when I refreshed after installing that file in the hooks directory. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Nathan Posted April 24, 2019 WHMCS Developer Share Posted April 24, 2019 If you're encountering an "Oops!" page, then that indicates that a PHP error has occurred. You'll want to enable the Display Errors option in the Setup > General Settings > Other section of your Admin Area, and then reproduce the issue. You should then see a PHP error displayed which you can use to determine what the issue with the hook-file is. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 25, 2019 Share Posted April 25, 2019 21 hours ago, trenttdogg said: I got the dreaded "Oops! Something went wrong and we couldn't process your request." error when I refreshed after installing that file in the hooks directory. What @WHMCS Nathan suggests is the way to go with this... the most likely error is the one below where it can't find the database column you're trying to add... Quote Column not found: 1054 Unknown column 'priceDetails' in 'field list' if that's what you're seeing, then that new column can't be called priceDetails... the rest of the hook looks ok to me, that new database field is the only unknown that i'm working with... let me know what the error is. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.