User Group after Purchase

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #88249

I am trying to ensure users are added to a specific user group after purchase. I have "User Group After Purchase" set to "custom" "athlete" group

but it does not seem to activate as seen here ("registered" but not "Athlete"):


Attachments:
Last edit: 11 years 9 months ago by cberry1971.

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

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 9 months ago #88275

Hi,

Did the order been validated (confirmed) ?

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: cberry1971

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #88316

No I understand. So that is the issue. We have users complete payment via authorize.net or paypal.

They are then directed back to our site to setup their profile and attend to other matters. This is only possible for them via a specific user group which (despite completing payment) has not been stored in their current session.

Is my only alternative to ask them to log out and log back in again in order to have that user groups' privileges?

Many thanks

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

  • Posts: 13201
  • Thank you received: 2322
11 years 9 months ago #88394

Hi,

They don't have to log out and then log in, when the order is confirmed, the group will automatically be added on their account.
Just refreshing the page should be ok.

You can too change the default order status in the checkout configuration.

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #88779

Ok testing now in 2.1.0

1. once the order is "confirmed" the user group is applied however
2. the modules which are to be visible are not seen by that user (newly confirmed) unless they log out / log in.

Is there a work around?

example:
1. go here:
184.154.228.9/~throwdow/live/index.php?o...ent&id=10&Itemid=118
2. click buy tickets and create a dummy account (real email address)
3. complete the free "transaction" you will be marked "confirmed" on our backend
4. click "your account" top right.. notice there are no modules displayed (they should be based on your new user group)
5. log out and log in and click "your account" and the modules are there.

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 9 months ago #88973

Hi,

I see what you mean.
Unfortunately, the process confirming the orders and thus adding the user group is a server to server process where the payment gateway directly contacts HikaShop to notify HikaShop of the payment. So the user session is not available in that process and the "user group after purchase" plugin which is triggered when the order is confirmed is not able to change the user session at that time.

The best we can add is to force the logout of the user by deleting the session information from the database if you're using the database as session handler (there is an option to select that in the configuration of joomla).

To do that, you can add the code:

else{
			//auto logout user on the frontend
			$conf = JFactory::getConfig();
			$handler = $conf->get('session_handler', 'none');
			if($handler=='database'){
				$db->setQuery('DELETE FROM '.hikashop_table('session',false).' WHERE client_id=0 AND userid = '.(int)$data->user_cms_id);
				$db->query();
			}
		}
after the code:
if($no_change){
			if($mainframe->isAdmin()){
				$mainframe->enqueueMessage('The customer of that order is already in the good user group','notice');
			}
			return true;
		}
in the file plugins/hikashop/group/group.php

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89146

Thank you. Looks good. The only snag I now run into is for free events like here:

wodrocket.com/index.php?option=com_hikas...emo-winter-throwdown

Despite being logged out, the user still looks to be logged in, which is confusing to the user because the confirm language now says "Thank you for your purchase. Please login above to update your athlete profile."

But "above" looks like they are already logged in. If they were to refresh the page, they would notice the login form.

Last edit: 11 years 9 months ago by cberry1971.

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 9 months ago #89208

Well, the problem is that the user group is added on the same page as the display of that page when you use the validate free orders plugin. So it is still logged in when displaying the login module.
That will require additional code after that code to remove the session data in the session if the current session is for the user of the order.

Add the code

if(!$mainframe->isAdmin()){
				$user = JFactory::getUser();
				if($user->id==$data->user_cms_id){
					$session = JFactory::getSession();
					$session->set('user', new JUser($data->user_cms_id));
				}
			}
after the code:
if($handler=='database'){
				$db->setQuery('DELETE FROM '.hikashop_table('session',false).' WHERE client_id=0 AND userid = '.(int)$data->user_cms_id);
				$db->query();
			}
in that same file and that should solve the issue.

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89236

Hmm.

After creating new account and completing purchase, it still shows user as logged in (even though they are not) as evidenced by refreshing screen.

I have attached the screenshot. Many thanks.

Attachments:

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89237

Almost like the code needs to simply say.. before displaying "thank you for your purchase...",
refresh screen.

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 9 months ago #89357

Mmm. I don't have any other idea. that code should work.

For the message, you can change it with a translation override:
www.hikashop.com/en/download/languages.html#modify

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89363

Ok. Let me try again. Was I supposed to add the code from #88973 or no?

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

  • Posts: 13201
  • Thank you received: 2322
11 years 9 months ago #89441

Hi,

Yes you was supposed to.

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89477

Ok. Included both snippets of code. Works for paid events where we leave the server / site and return. Still does not work for free events where user does not leave site.

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 9 months ago #89761

Ok, try with that code instead then:

if(!$mainframe->isAdmin()){
	$mainframe->logout( $data->user_cms_id );
}

Last edit: 11 years 8 months ago by Jerome.

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89852

sorry getting this error:

Parse error: syntax error, unexpected '}' in /home/throwdow/public_html/live/plugins/hikashop/group/group.php on line 94

I have included the entire group.php file

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
11 years 9 months ago #89895

Try to replace the content with:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.1.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashopGroup extends JPlugin
{
	function plgHikashopGroup(&$subject, $config){
		parent::__construct($subject, $config);
	}

	function onProductDisplay(&$product,&$html){
		ob_start();
		?><fieldset class="adminform">
			<legend><?php echo JText::_('USER_GROUP_AFTER_PURCHASE'); ?></legend>
			<?php
				$subscriptiontype = hikashop_get('type.subscription');
				echo $subscriptiontype->display('product_group_after_purchase',@$product->product_group_after_purchase,'product');
			?>
		</fieldset><?php
		$html[]=ob_get_clean();
	}

	function onAfterOrderCreate( &$order,&$send_email){
		return $this->onAfterOrderUpdate( $order,$send_email);
	}

	function onAfterOrderUpdate(&$order,&$send_email){
		$config=&hikashop_config();
		$confirmed = $config->get('order_confirmed_status');
		if(!isset($order->order_status)) return true;

		$mainframe = JFactory::getApplication();
		$db = JFactory::getDBO();

		$class = hikashop_get('class.order');
		$dbOrder = $class->get($order->order_id);
		$class = hikashop_get('class.user');
		$data = $class->get($dbOrder->order_user_id);

		if(empty($data->user_cms_id)){
			if($mainframe->isAdmin()){
				$mainframe->enqueueMessage('The customer '.$dbOrder->order_user_id.'does not have a joomla user account so his group cannot be changed','notice');
			}
			return true;
		}

		$db->setQuery('SELECT b.*,a.* FROM `#__hikashop_order_product` as a LEFT JOIN `#__hikashop_product` as b ON a.product_id=b.product_id WHERE a.order_id = '.(int) $dbOrder->order_id.' AND b.product_group_after_purchase!=\'\'');
		$allProducts = $db->loadObjectList();

		if(empty($allProducts)){
			return true;
		}

		if($order->order_status!=$confirmed){
			return true;
		}


		$no_change=true;
		foreach($allProducts as $oneProduct){
			if(hikashop_isAllowed($oneProduct->product_group_after_purchase,$data->user_cms_id)){
				continue;
			}
			$no_change=false;
			$this->_updateGroup($data->user_cms_id,$oneProduct->product_group_after_purchase);
			if($mainframe->isAdmin()){
				$mainframe->enqueueMessage('The user '.$dbOrder->order_user_id.' is now in the group '.$oneProduct->product_group_after_purchase);
			}
		}

		if($no_change){
			if($mainframe->isAdmin()){
				$mainframe->enqueueMessage('The customer of that order is already in the good user group','notice');
			}
			return true;
		}
		else{
			//auto logout user on the frontend
			$conf = JFactory::getConfig();
			$handler = $conf->get('session_handler', 'none');
			if($handler=='database'){
				$db->setQuery('DELETE FROM '.hikashop_table('session',false).' WHERE client_id=0 AND userid = '.(int)$data->user_cms_id);
				$db->query();
			}
			if(!$mainframe->isAdmin()){
				$mainframe->logout( $data->user_cms_id )
			}
		}
	}

	function _updateGroup($user_id,$new_group_id,$remove_group_id=0){
		$user = clone(JFactory::getUser($user_id));
		if(version_compare(JVERSION,'1.6.0','<')){
			if($user->gid!=25){
				$user->set('gid',$new_group_id);
				$acl = JFactory::getACL();
				$user->set('usertype', $acl->get_group_name($new_group_id));
			}
		}else{
			jimport('joomla.access.access');
			$userGroups = JAccess::getGroupsByUser($user_id, true);
			$userGroups[] = $new_group_id;
			if(!empty($remove_group_id)){
				$key = array_search($remove_group_id, $userGroups);
				if(is_int($key)){
					unset($userGroups[$key]);
				}
			}
			$user->set('groups',$userGroups);
		}
		$user->save();
	}

}

Two "}" were missing.

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

  • Posts: 241
  • Thank you received: 5
11 years 9 months ago #89924

sorry still getting the following error when I try to access hikashop from the back-end:


Parse error: syntax error, unexpected '}' in /home/throwdow/public_html/live/plugins/hikashop/group/group.php on line 93

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

  • Posts: 13201
  • Thank you received: 2322
11 years 9 months ago #89987

Add a ";" at the end of the line 92.

Regards

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

  • Posts: 241
  • Thank you received: 5
11 years 8 months ago #90348

Ok. getting there.

Works on paid products. On free products we are getting the following error:

"No class of content is loaded! To avoid critical error, proccess aborted"

To create the issue go here:

184.154.228.9/~throwdow/live/index.php?o...ent&id=10&Itemid=118

complete registration and purchase (free). Again purchases which are not free work fine.

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

Time to create page: 0.104 seconds
Powered by Kunena Forum