Next Edge Posted December 17, 2020 Share Posted December 17, 2020 Hi All, I'm having an issue with a plugin i created (loaded in a /includes/hooks file) that solves an issue i identified in regards to the correct representation of a monthly price on a multi qty item in the client portal. The issue is based in the fact the qty field is not even available in the smarty template nor a calculated amount based on the reoccuring * qty. The WHMCS development team have addressed in the current RC1 (CORE-15550). That is not the purpose of this post but outlines how i came to the purpose of this post. I have created a custom server module to handle some M2M 4G simcards and communicate with a Cisco Jasper API to display information about them. The way i am approching the client service page for this has me loading the service information inside the /module/server/ client area template file for the sevrer module i am making. The price hack (which is in the attachments to this post, is called by the code {getprice serviceid={$serviceid} explain=true} in the smarty template, however when i place this plugin call inside the server module client area template the page fails to render. From what i can work out (even from a basic level of echo'ing out a value in the PriceQtyHack() function) the hook is firing and loading the plugin, but that plugin seems to not work for the server module template. I have a feeling its because the server module template is basically a sub template that is printed into clientareaproductdetails.tpl by the variable {$moduleclientarea}, I have not been able to find any specfic documentation about what is and isnt supported in regards to plugins in a sub template. Does anyone have any insight or suggestion as to what i may be facing here? Or a link to a doc that explains how to achieve the plugin being called from the sub template? Hack Code.txt 0 Quote Link to comment Share on other sites More sharing options...
Next Edge Posted December 17, 2020 Author Share Posted December 17, 2020 Note: we are not developing commercial modules, they are modules to expand the functionality of our own installation. So anything we do is not intended to be scalable to other instances so little hacks to fix things until WHMCS do/don't address the root cause are not a major concern to me. 🙂 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 19, 2020 Share Posted December 19, 2020 So are you only concerned with the client area -> product details page for showing this info or like within the cart? I am not sure doing this via smarty plugins will work but have not looked in to that. For just the product details page, you could use ClientAreaPageProductDetails hook and return the recurring amount you want to show or any other template variable you want to override. Just note you need to format it as it wont be formatted when you overwrite it. <?php use WHMCS\Service\Service; add_hook('ClientAreaPageProductDetails', 1, function($vars) { $service = Service::find($vars['serviceid']); if ($service) return array('recurringamount'=>$service->qty * $service->amount); }); Using internal classes like WHMCS\Service\Service above is, IMO at least, far better then querying the database directly. Check out the internal classes docs for the service class: https://classdocs.whmcs.com/8.0/WHMCS/Service/Service.html . It effectively does the same but is much cleaner. 0 Quote Link to comment Share on other sites More sharing options...
Next Edge Posted December 19, 2020 Author Share Posted December 19, 2020 So is that effectively overwriting the recurringamount value in the smartytemplate? 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 23, 2020 Share Posted December 23, 2020 Correct. If you look at the clientareaproductdetails.tpl file, it should be able to replace any smarty template variable within that template file at the least. 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.