How to differentiate orders by usergroups?

  • Posts: 58
  • Thank you received: 2
  • Hikashop Business
11 years 4 months ago #110130

I have a site setup with about 800 items which all have 2 price levels based on usergroups. Normal Registered users and Wholesale users. Is there a way to add the usergroup to the invoices so there's a way to tell which group the user belongs to on the orders?

Please Log in or Create an account to join the conversation.

  • Posts: 82758
  • Thank you received: 13346
  • MODERATOR
11 years 4 months ago #110153

There is a way. But it depends on the version of Joomla you're using.
On Joomla 1.5 and 2.5 there is a usertype field in the user table of Joomla that you can use to display the user group.
So like that:
<?php echo $this->order->customer->usertype; ?>

But that parameter is deprecated on 2.5 and completely removed on Joomla 3.x.
So now you need something like that:
<?php
jimport( 'joomla.user.helper' );
$groups = JUserHelper::getUserGroups( $this->order->customer->user_cms_id);
foreach($groups as $group) echo ' '.$group;
?>

Please Log in or Create an account to join the conversation.

  • Posts: 58
  • Thank you received: 2
  • Hikashop Business
11 years 4 months ago #110157

It's J3.1.

So where can I add that so it shows up on the list of orders?

Like maybe under the user info like:

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
11 years 4 months ago #110185

Hi there,

Just edit the view listing of order in the backend (Display>Views) and add the code here (before the last </td>):

<td class="hikashop_order_customer_value">
						<?php
						 if(!empty($row->username)){
						 	echo $row->name.' ( '.$row->username.' )</a><br/>';
						 }
						 $url = hikashop_completeLink('user&task=edit&cid[]='.$row->user_id);
						 $config =& hikashop_config();
						 if(hikashop_isAllowed($config->get('acl_user_manage','all'))) echo $row->user_email.'<a href="'.$url.$target.'"><img src="'.HIKASHOP_IMAGES.'edit2.png" alt="edit"/></a>';
						 ?>
					</td>

Last edit: 11 years 4 months ago by Eliot.

Please Log in or Create an account to join the conversation.

  • Posts: 58
  • Thank you received: 2
  • Hikashop Business
11 years 4 months ago #111206

Ok so this is what I've got in there now but it's not showing the groups

    <td class="hikashop_order_customer_value">
    <?php
    if(!empty($row->username)){
    echo $row->name.' ( '.$row->username.' )</a><br/>';
    }
    $url = hikashop_completeLink('user&task=edit&cid[]='.$row->user_id);
    $config =& hikashop_config();
    if(hikashop_isAllowed($config->get('acl_user_manage','all'))) echo $row->user_email.'<a href="'.$url.$target.'"><img src="'.HIKASHOP_IMAGES.'edit2.png" alt="edit"/></a>';
    ?>
    <br />
    <?php
    jimport( 'joomla.user.helper' );
    $groups = JUserHelper::getUserGroups( $this->order->customer->user_cms_id);
    foreach($groups as $group) echo ' '.$group;
    ?>
    </td>

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #111250

The code is:

						 <?php
						 	jimport( 'joomla.user.helper' );
						 	$groups = JUserHelper::getUserGroups( $row->user_cms_id);
						 	foreach($groups as $group) echo ' '.$group;
						 ?>

Please Log in or Create an account to join the conversation.

  • Posts: 58
  • Thank you received: 2
  • Hikashop Business
11 years 4 months ago #111285

Yay! That's a step closer. That returns the usergroup ID, how do I convert that to the group name?

Thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
11 years 4 months ago #111297

Just make a var_dump($groups); to see what is inside the object.
You should be able to find the group name. If it's not included, then you'll have to write a SQL query to get it.

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum