Jump to content
sebsimappus

Sub categories of product in cart

Recommended Posts

Hello,

 

I come to see you to see if it is possible to modify the file sidebar-categories.tpl to get subcategories of services in the shopping basket.

 

thank you in advance for your help

 

cordially

Share this post


Link to post
Share on other sites
I come to see you to see if it is possible to modify the file sidebar-categories.tpl to get subcategories of services in the shopping basket.

hmm - you'd have to define what your subcategories are in the template and then which products are in each subcategory... that seems a lot of hassle to me. :roll:

 

the alternative would be to fake sub-categorisation - two examples are shown below of this, one for a narbar; the other for a sidebar.

 

https://forum.whmcs.com/showthread.php?114378-How-to-add-submenu-into-primary-navbar-main-menu&p=484390#post484390

https://forum.whmcs.com/showthread.php?95051-product-group-sub-groups&p=458799#post458799

 

depending on your categories, it's possible it would be simpler to create a new sidebar to replace the default categories sidebar rather than trying to adjust the existing one.

Share this post


Link to post
Share on other sites

I was hoping you weren't going to ask, because I was sure yesterday that i'd already posted the code previously but couldn't find the thread when I made the above reply... turns out that I probably didn't post the code in a thread anyway! :roll:

 

so in April 2016, to create the categories sidebar below (from the above thread)...

mDPmZjg.png

 

... I wrote the following action hook code...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Categories'))) {
            $secondarySidebar->getChild('Categories')
            ->addChild('SSL Certificates', array(
               'label' => '<b>SSL Certificates</b>',
               'order' => 20,
               ));
           $secondarySidebar->getChild('Categories')
            ->addChild('Comodo', array(
               'uri' => 'cart.php?a=add&pid=45',
               'label' => '   »» Comodo',
               'order' => 21,
               'icon' => 'fa-lock'    
               ));
           $secondarySidebar->getChild('Categories')
            ->addChild('Geotrust', array(
               'uri' => 'cart.php?a=add&pid=46',
               'label' => '   »» Geotrust',
               'order' => 22,
               'icon' => 'fa-lock'                
               ));                
           $secondarySidebar->getChild('Categories')
            ->addChild('RapidSSL', array(
               'uri' => 'cart.php?a=add&pid=47',
               'label' => '»» RapidSSL',
               'order' => 23,
               'icon' => 'fa-fw'                    
               ));
   }
});

for this quick example, I added a blank category (SSL Certs with no link), and added 3 products beneath it to the existing "Categories" sidebar - with the child positions being controlled by the order value in the hook...

 

now, if your subcategories were already product groups in their own right, then this becomes slightly easier in that you don't need to create new sidebar children, you just need to move and/or re-label the existing ones.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Categories'))) {
            $secondarySidebar->getChild('Categories')
                             ->addChild('SSL Certificates', array(
                             'label' => '<b>SSL Certificates</b>',
                             'order' => 20,
               ));
           $secondarySidebar->getChild('Categories')
                            ->getChild('Comodo')
                            ->setLabel('   »» Comodo')
                            ->setOrder(21);
   }
});

remember to take care when calling existing children because, in the above code, I lazily haven't included any validation to check the child exists before modifying them - e.g., if a product group called 'Comodo' doesn't exist (or you've renamed it), the hook will fail.

 

as I said previously, depending on the complexity of how to want to do your subcategories, an alternative might be to start a new sidebar from scratch... though you'd likely have to query the db to get the group names and then put them into an order before outputting the sidebar and it's children... it could be done. but I expect for most circumstances, you can more easily just modify the existing sidebar. :idea:

 

4zReMCP.png

Share this post


Link to post
Share on other sites

Hello

 

Thanks for your return, I currently use in the sidebar-categories file.

 

It would be possible to modify my file in order to obtain the same result.

 

thank you in advance

 

 

<div class="panel panel-default">

<div class="panel-heading">

<h3 class="panel-title"><span class="fa fa-shopping-cart"></span>   {$LANG.ordercategories}</h3>

</div>

<div class="list-group">

{foreach from=$productgroups item=productgroup}

<a href="cart.php?gid={$productgroup.gid}" class="list-group-item{if $productgroup.gid eq $gid} active{/if}">{$productgroup.name}</a>

{/foreach}

{if $loggedin}

<a href="cart.php?gid=addons" class="list-group-item{if $gid eq "addons"} active{/if}">{$LANG.cartproductaddons}</a>

{/if}

</div>

</div>

 

<div class="panel panel-default">

<div class="panel-heading">

<h3 class="panel-title"><span class="fa fa-plus"></span>   {$LANG.actions}</h3>

</div>

<div class="list-group">

{if $loggedin && $renewalsenabled}

<a href="cart.php?gid=renewals" class="list-group-item{if $gid eq "renewals"} active{/if}"><i class="fa fa-refresh fa-fw"></i> {$LANG.domainrenewals}</a>

{/if}

{if $registerdomainenabled}

<a href="cart.php?a=add&domain=register" class="list-group-item{if $domain eq "register"} active{/if}"><i class="fa fa-globe fa-fw"></i> {$LANG.navregisterdomain}</a>

{/if}

{if $transferdomainenabled}

<a href="cart.php?a=add&domain=transfer" class="list-group-item{if $domain eq "transfer"} active{/if}"><i class="fa fa-share fa-fw"></i> {$LANG.transferinadomain}</a>

{/if}

<a href="cart.php" class="list-group-item"><i class="fa fa-shopping-cart fa-fw"></i> {$LANG.viewcart}</a>

</div>

</div>

Share this post


Link to post
Share on other sites
Thanks for your return, I currently use in the sidebar-categories file.

It would be possible to modify my file in order to obtain the same result.

not really - the problem is that {foreach} loop that outputs the product group names.

 

without knowing exactly what you want to do, if you were going to do this in a template, it might be easier to just hard-code the product group links and names individually - that way you could determine their order and which were indented...

Share this post


Link to post
Share on other sites

Hello,

 

I come back to you because I would like to know if it would be possible to give an accordion style for the subcategories.

 

In addition I would like to use the languages for the setLabel.

 

thank you in advance

Share this post


Link to post
Share on other sites
I come back to you because I would like to know if it would be possible to give an accordion style for the subcategories.

by default you couldn't do it - but there'd be little to stop you adding additional code, in the template or as a hook, to create it... it would just be a case of getting the accordion code and putting your content (sub-cats) in the appropriate place.

 

In addition I would like to use the languages for the setLabel.

you can use the Lang::trans feature to access the language strings.

 

setLabel (Lang::trans('accountinfo'));

Share this post


Link to post
Share on other sites

Hey @brian!

I've tried reaching out to you to assist with debugging an error that Im receiving when attempting to implement this on my site and see that you dont allow PM's 🙂

Would you mind sending me a PM so that I can forward you the error thats being logged on my whmcs?

Share this post


Link to post
Share on other sites
5 hours ago, Jade D said:

I've tried reaching out to you to assist with debugging an error that Im receiving when attempting to implement this on my site and see that you don't allow PM's 🙂

I do, but the mailbox is currently 100% full - i'm a victim of my own popularity. 😎

5 hours ago, Jade D said:

Would you mind sending me a PM so that I can forward you the error thats being logged on my whmcs?

try again tomorrow - by that time, I should have deleted a few of the old PMs to create some space...

Share this post


Link to post
Share on other sites
40 minutes ago, brian! said:

I do, but the mailbox is currently 100% full - i'm a victim of my own popularity. 😎

try again tomorrow - by that time, I should have deleted a few of the old PMs to create some space...

Will do, thanks Brian

Share this post


Link to post
Share on other sites

Hello Brian

we also need this SUB-cat function!

is this still working for year 2021 for WHMCS 8.1 ?

Share this post


Link to post
Share on other sites
On 10/01/2021 at 00:56, hoya8 said:

is this still working for year 2021 for WHMCS 8.1 ?

yes - I can't imagine that there is anything in v8.1 that would break it... Six & 21 screenshots from v8.1 below...

PcL2Qob.pngE7HmquV.png

it's just a case of working out what you want to indent, whether to include icons and coding accordingly.

Share this post


Link to post
Share on other sites

Hi Brian

as our menu is really too long, is there any way that sub-categories are folded by default with a "+ "  and sub menu only pop up after click +?

Share this post


Link to post
Share on other sites
On 11/01/2021 at 22:34, hoya8 said:

as our menu is really too long, is there any way that sub-categories are folded by default with a "+ "  and sub menu only pop up after click +?

not a simple way. 🙂

you could minimise the whole Categories sidebar on page load if that helps (they will see the sidebar animated close) - it would be a variation of the hook I posted in the thread below...

<?php

# Minimise Cart Categories Sidebar Hook
# Written by brian! 

function minimise_cart_categories_sidebar_hook($vars) {

	if ($vars['inShoppingCart']) {
		return <<<HTML
<script>
	jQuery(function(){
		jQuery('div[menuItemName="Categories"]').find('i[class~="fa-chevron-up"]').click();
	});
</script>
HTML;
	}
}
add_hook("ClientAreaHeaderOutput", 1, "minimise_cart_categories_sidebar_hook");

GVMQKPK.png

as written, it should minimise the sidebar on all cart pages - if you need to be more selective when to minimise, then you should follow the original hook and define a list of templates where the minimising should be allowed.

Share this post


Link to post
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