projectmyst Posted December 21, 2019 Share Posted December 21, 2019 Hi Everyone I'm trying to add active domains badge via hooks, but I'm not having much luck. Does anyone how I can achieve this? This is my current code: // Domains if ($primaryNavbar) { $primaryNavbar->addChild('Domains') ->setLabel('Domains') ->setOrder(97); if ($primaryNavbar && !is_null($primaryNavbar->getChild('Domains'))) { if (!is_null($client)) { $primaryNavbar->getChild('Domains')->addChild('My Domains') ->setUri('clientarea.php?action=domains') ->setLabel('My Domains') ->setBadge(($badges['activedomains'])) ->setOrder(1); $primaryNavbar->getChild('Domains')->addChild('Divider-My Domains') ->setUri('#') ->setLabel('-----') ->setClass('nav-divider') ->setOrder(2); } $primaryNavbar->getChild('Domains')->addChild('Register a New Domain') ->setUri('cart.php?a=add&domain=register') ->setLabel('Register a New Domain') ->setIcon('fas fa-envelope-open') ->setOrder(3); $primaryNavbar->getChild('Domains')->addChild('Transfer a Domain to Us') ->setUri('cart.php?a=add&domain=transfer') ->setLabel('Transfer Domains to Us') ->setIcon('fas fa-envelope-open') ->setOrder(4); if (!is_null($client)) { $primaryNavbar->getChild('Domains')->addChild('Divider-Renew Domains') ->setUri('#') ->setLabel('-----') ->setClass('nav-divider') ->setOrder(5); $primaryNavbar->getChild('Domains')->addChild('Renew Domains') ->setUri('cart.php?gid=renewals') ->setLabel('Renew Domains') ->setOrder(6); } } } 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 21, 2019 Share Posted December 21, 2019 2 hours ago, projectmyst said: I'm trying to add active domains badge via hooks, but I'm not having much luck. Does anyone how I can achieve this? in your code, how were you defining $badges ? I think that will have been your issue... try the following hook, it should work... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $client = Menu::context('client'); $primaryNavbar->addChild('Domains')->setLabel(Lang::trans('navdomains'))->setOrder(97); if (!is_null($client)) { $domaincount = $client->domains->count(); $primaryNavbar->getChild('Domains')->addChild('My Domains')->setUri('clientarea.php?action=domains')->setLabel(Lang::trans('clientareanavdomains'))->setBadge($domaincount)->setOrder(1); $primaryNavbar->getChild('Domains')->addChild('Divider-My Domains')->setUri('#')->setLabel('-----')->setClass('nav-divider')->setOrder(2); $primaryNavbar->getChild('Domains')->addChild('Divider-Renew Domains')->setUri('#')->setLabel('-----')->setClass('nav-divider')->setOrder(5); $primaryNavbar->getChild('Domains')->addChild('Renew Domains')->setUri('cart.php?gid=renewals')->setLabel(Lang::trans('navrenewdomains'))->setOrder(6); } $primaryNavbar->getChild('Domains')->addChild('Register a New Domain')->setUri('cart.php?a=add&domain=register')->setLabel(Lang::trans('navregisterdomain'))->setIcon('fas fa-envelope-open')->setOrder(3); $primaryNavbar->getChild('Domains')->addChild('Transfer a Domain to Us')->setUri('cart.php?a=add&domain=transfer')->setLabel(Lang::trans('navtransferdomain'))->setIcon('fas fa-envelope-open')->setOrder(4); }); even the above code could be trimmed further, but it should be enough to get you on your way... 🙂 0 Quote Link to comment Share on other sites More sharing options...
projectmyst Posted December 22, 2019 Author Share Posted December 22, 2019 Hi brian Yeah that worked, thank you. I haded defined the badge correctly. 0 Quote Link to comment Share on other sites More sharing options...
projectmyst Posted December 22, 2019 Author Share Posted December 22, 2019 (edited) Hi brian How can I make it to just show the actives ones and not the totals. For example, only active domains and not total, active services and not total, due invoices and not total and so on. This is the code that I have so far. // Badge Count if (!is_null($client)) { $domainscount = $client->domains->count(); $servicescount = $client->services->count(); $invoicescount = $client->invoices->count(); $ticketscount = $client->tickets->count(); $quotescount = $client->quotes->count(); // Funds $currencydata = getCurrency($client->id); $creditcount = formatCurrency($client->credit, $currencydata); } // Cart Count Badge $itemsincart = (count($_SESSION['cart']['products']) + count($_SESSION['cart']['domains'])); Edited December 22, 2019 by projectmyst 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 22, 2019 Share Posted December 22, 2019 (edited) 3 hours ago, projectmyst said: How can I make it to just show the actives ones and not the totals. For example, only active domains and not total, active services and not total, due invoices and not total and so on. This is the code that I have so far. for domains... $domainscount = $client->domains()->where('status','Active')->count(); for services... $servicescount = $client->services()->where('domainstatus','Active')->count(); note that 'due' is a little more awkward because there isn't a "due" status, so they're effectively unpaid invoices where today is before/equal the due date... if today is after the due date, then they're overdue... if you just wanted an unpaid invoices count... $invoicescount = $client->invoices()->unpaid()->count(); or overdue invoices... $invoicescount = $client->invoices()->overdue()->count(); so to get a due value, you would either use the due date in the query and compare it to today... or you could take the overdue count value from the unpaid count value and that should give you a due count value. Edited December 22, 2019 by brian! 0 Quote Link to comment Share on other sites More sharing options...
projectmyst Posted December 22, 2019 Author Share Posted December 22, 2019 Thank you, that was a great help 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.