Jump to content

Client Area Product Details missing sidebar links?


tsiedsma

Recommended Posts

Found the issue, if a product is Free or one-time like a Free Trial, it doesn't show the cancellation option.  As for the upgrade option missing, the specific product I was viewing had no upgrades so that makes sense 😛

This was non-existent in 7.6.2 and now exists in 7.7.0 but I do not remember reading about this change or seeing an option to disable it.

Link to comment
Share on other sites

19 minutes ago, tsiedsma said:

This was non-existent in 7.6.2 and now exists in 7.7.0 but I do not remember reading about this change

it's listed in the v7.7 changelog...

Quote

CORE-12870 - Do not display cancellation option for One Time products in client area

i'm assuming that it's just removing the link in the sidebar and it would theoretically still be possible to cancel a trial product if you generated the link yourself.

19 minutes ago, tsiedsma said:

or seeing an option to disable it. 

this is v7.7... "option to disable"?... i'm not sure anyone at WHMCS Towers understands that concept! celestial5.gif

I daresay if you wanted to, you could add the cancellation link back in with a sidebar hook... e.g check if cancel link already exists, if not, optionally check that it's a trial product and add link child to sidebar... it's just a link to clientarea.php?action=cancel&id=x where x is the serviceID.

Link to comment
Share on other sites

3 minutes ago, brian! said:

it's listed in the v7.7 changelog...

i'm assuming that it's just removing the link in the sidebar and it would theoretically still be possible to cancel a trial product if you generated the link yourself.

this is v7.7... "option to disable"?... i'm not sure anyone at WHMCS Towers understands that concept! celestial5.gif

I daresay if you wanted to, you could add the cancellation link back in with a sidebar hook... e.g check if cancel link already exists, if not, optionally check that it's a trial product and add link child to sidebar... it's just a link to clientarea.php?action=cancel&id=x where x is the serviceID.

Yep, I totally over looked it.  I hate that I have to hack in so much stuff via hooks!  It gets frustrating.  Disabling something without the option to turn it back on is not a feature, it’s a bug!

Link to comment
Share on other sites

1 hour ago, tsiedsma said:

I hate that I have to hack in so much stuff via hooks!  It gets frustrating.

I was helping someone with a v5 installation yesterday and it's remarkable how simple it was to do some things back then.

fwiw - this quick hook should add the Request Cancellation button back if it doesn't already exist for all Active products...

<?php

# Add Cancel Sidebar Link If Missing For Active Products Hook
# Written by brian! 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
	GLOBAL $smarty;
	$ServiceActions = $primarySidebar->getChild('Service Details Actions');
	if (empty($ServiceActions)) {
		return;
	}	
	if (is_null($ServiceActions->getChild('Cancel'))) {
		$serviceID = $smarty->getTemplateVars('id');
		$servicestatus = $smarty->getTemplateVars('status');
		if ($servicestatus == "Active") {
			$ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id='.$serviceID)->setOrder(40);
		}
	}
});

... feel free to expand it to suit your needs.

Link to comment
Share on other sites

3 minutes ago, brian! said:

it was easier to spend a couple of minutes on it now while it was still fresh in my mind rather than returning to it in a few weeks time! 🙂

FYI, getVariable('var') is deprecated, you should use getTemplateVars('var')
https://www.smarty.net/docs/en/api.get.template.vars.tpl

Link to comment
Share on other sites

The hook doesn't work for me, both id and status are not in the list of smarty variables.  They must get added after the hook is called!
Either way, "Cancel" is not being added to the side bar, I can dump the variables in the hook so I know it's running.

Link to comment
Share on other sites

14 minutes ago, tsiedsma said:

The hook doesn't work for me, both id and status are not in the list of smarty variables.  They must get added after the hook is called!

dammit - it's failing on cPanel products (didn't have a trial cpanel product, only active ones - so didn't see this) but working on non-cpanel products... leave it with me.

Link to comment
Share on other sites

Got it!  It doesn't show up on the "Cancellation" page but that's fine.  The status variable is missing there and the serviceid is just id.
This works for my purposes and doesn't require "GLOBAL", I hate using globals.

add_hook('ClientAreaPageProductDetails', 1, function($vars) {
    $primarySidebar = Menu::primarySidebar();
    $ServiceActions = $primarySidebar->getChild('Service Details Actions');

    if (empty($ServiceActions)) {
        return;
    }
    if (is_null($ServiceActions->getChild('Cancel'))) {
        $serviceID = $vars['serviceid'];
        $servicestatus = $vars['status'];
        if ($servicestatus == "Active") {
            $ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id='.$serviceID)->setOrder(40);
        }
    }
});

 

Edited by tsiedsma
Link to comment
Share on other sites

30 minutes ago, tsiedsma said:

Got it!  

well done... though if you have access to $vars, there's no need for $smarty...

<?php

# Add Cancel Sidebar Link If Missing For Active Products Hook
# Written by brian! 

add_hook('ClientAreaPageProductDetails', 1, function($vars) {

    $primarySidebar = Menu::primarySidebar();
    $ServiceActions = $primarySidebar->getChild('Service Details Actions');
    if (empty($ServiceActions)) {
        return;
    }
    if (is_null($ServiceActions->getChild('Cancel'))) {
        if ($vars['status'] == "Active") {
            $ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id='.$vars['id'])->setOrder(100);
        }
    }
});
Link to comment
Share on other sites

Ok, for anyone else looking to add back the Request Cancellation functionality, this is my final product.  It works on the Service Details page, and when you click Cancel, it adds the menu item and makes it active.  This just completes the look.

<?php

add_hook('ClientAreaPage', 1, function ($vars) {
    $primarySidebar = Menu::primarySidebar();
    $ServiceActions = $primarySidebar->getChild('Service Details Actions');
    
    if (empty($ServiceActions)) {
        return;
    }
    if (is_null($ServiceActions->getChild('Cancel'))) {
        if ($vars['status'] === "Active") {
            $ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id=' . $vars['id'])->setOrder(40);
        }
        else if ($vars['clientareaaction'] === 'cancel') {
            $ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id=' . $vars['id'])->setOrder(40)->setClass('list-group-item active');
        }
    }
});

<

Link to comment
Share on other sites

8 minutes ago, tsiedsma said:

Ok, for anyone else looking to add back the Request Cancellation functionality, this is my final product.  It works on the Service Details page, and when you click Cancel, it adds the menu item and makes it active.  This just completes the look.

for me, it's already setting the active class when clicked upon... also, you wouldn't really want to use ClientAreaPage for this as that will run on every client area page, whereas you only need this to work on the product details page.

Link to comment
Share on other sites

1 minute ago, brian! said:

for me, it's already setting the active class when clicked upon... also, you wouldn't really want to use ClientAreaPage for this as that will run on every client area page, whereas you only need this to work on the product details page.

It wasn't setting the active class on the cancel page.  It has it's own page hook, so I guess if you notice a performance issue running this tiny bit of code on every page load, you could have two separate hooks for ClientAreaPageProductDetails and ClientAreaPageCancellation

Link to comment
Share on other sites

8 minutes ago, tsiedsma said:

It wasn't setting the active class on the cancel page.

it is for me - though i've got a dev using clean "Six" templates, and you may be using customised templates.

9 minutes ago, tsiedsma said:

It has it's own page hook, so I guess if you notice a performance issue running this tiny bit of code on every page load, you could have two separate hooks for ClientAreaPageProductDetails and ClientAreaPageCancellation

for a one-off hook, I wouldn't be concerned about page load... but WHMCS can require a lot of hooks, so I prefer them to only run when required.

Link to comment
Share on other sites

Just now, brian! said:

it is for me - though i've got a dev using clean "Six" templates, and you may be using customised templates.

for a one-off hook, I wouldn't be concerned about page load... but WHMCS can require a lot of hooks, so I prefer them to only run when required.

Considering the Cancellation link isn't present without the hook, there is no way it will be present and active on the cancellation page without adding it which your hook does not do.
WHMCS loads a ton of crap including hooks, so I am 100% in agreement that you don't want to run more than necessary.  I don't see this specific one running on every client area page load causing much of a problem based on what it actually does.

Link to comment
Share on other sites

<?php

# Add Cancel Sidebar Link If Missing For Active Products Hook
# Written by brian! 

add_hook('ClientAreaPage', 1, function ($vars) {
    $primarySidebar = Menu::primarySidebar();
    $ServiceActions = $primarySidebar->getChild('Service Details Actions');
    
    if (empty($ServiceActions)) {
        return;
    }
    if (is_null($ServiceActions->getChild('Cancel'))) {
        if ($vars['status'] === 'Active' || $vars['clientareaaction'] === 'cancel') {
            $ServiceActions->addChild('Cancel')->setLabel(Lang::trans('clientareacancelrequestbutton'))->setURI('clientarea.php?action=cancel&id='.$vars['id'])->setOrder(100)->setClass(( ! isset($_GET['modop']) ? 'active' : ''));
        }
    }
});

 

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