Jump to content

Smarty Template Plugin inside Server Module


Next Edge

Recommended Posts

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

Link to comment
Share on other sites

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. 🙂

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated