Jump to content

ClientAreaPrimarySidebar Get Current Product ID


willk

Recommended Posts

Hi All,

For some reason the tabAddons nav option is not displaying on random products, even though there are addons definitely available for them.

To get around this I wanted to add a custom nav item using the ClientAreaPrimarySidebar hook.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)

{
    $client = Menu::context("client");
    $pid = (int) $client->id;
    if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
        $primarySidebar->getChild('Service Details Actions')
            ->addChild('Order Addons')
            ->setOrder(100)
            ->setUri('../clientarea.php?action=productdetails&id='.$pid.'#tabAddons');
    }
});

Although I can get the client ID using the Menu::context option I cannot work out how get the current productID. Any suggestions would be appreciated.


Thanks,
Will

Link to comment
Share on other sites

the hook below would work...

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)

{
	$service = Menu::context('service');    
	$pid = (int) $service->id;
	if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
		$primarySidebar->getChild('Service Details Actions')
			->addChild('Order Addons')
			->setOrder(100)
			->setUri('clientarea.php?action=productdetails&id='.$pid.'#tabAddons');
	}
});

though I might be more tempted to add it to the Overview sidebar (perhaps detecting if there was already an addons link there, and checking that the service is active).

Link to comment
Share on other sites

Hi Brian,

Fantastic, thanks for your reply. I took your advice and checked to see if the Addons was menu item was null or not before adding it again.

However, the Uri when it is added seems to reload the entire page and then lose the product ID. I have commented out the check for Addons in the template file so the class with ID 'tabAddons' definitely exists on the page. See: http://prntscr.com/n6n1v4

The menu item renders okay, see: http://prntscr.com/n6n207

However, it doesn't have the data-toggle="tab" field so it does a postback of the entire page and loses the productID etc. so if you click back on 'Information' it no longer shows anything.

I couldn't find any set commands when adding the child to fix this.


Thanks,

Will

Link to comment
Share on other sites

Hi Will,

15 hours ago, willk said:

However, it doesn't have the data-toggle="tab" field so it does a postback of the entire page and loses the productID etc. so if you click back on 'Information' it no longer shows anything.

I couldn't find any set commands when adding the child to fix this.

just add the code below to your hook...

->setAttribute('dataToggleTab','tab')
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