- Posts: 45
- Thank you received: 6
Assigning User Group on order creation
2 years 9 months ago #357553
by NTV
Assigning User Group on order creation was created by NTV
-- HikaShop version -- : 5.0.2
-- Joomla version -- : 4.4.1
-- PHP version -- : 8
-- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)
Hi,
I want to assign a user group when a customer orders a certain product.
This is possible by setting "User group after purchase" for the product in question.
However, the user group is only assigned once the order is set to confirmed.
I am aware of the possible implications, but still want to assign user groups immediately after the order is created.
How would I go about doing this?
-- Joomla version -- : 4.4.1
-- PHP version -- : 8
-- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)
Hi,
I want to assign a user group when a customer orders a certain product.
This is possible by setting "User group after purchase" for the product in question.
However, the user group is only assigned once the order is set to confirmed.
I am aware of the possible implications, but still want to assign user groups immediately after the order is created.
How would I go about doing this?
Please Log in or Create an account to join the conversation.
2 years 9 months ago #357566
by nicolas
Replied by nicolas on topic Assigning User Group on order creation
Hi,
You would have to edit the file plugins/hikashop/group/group.php and change the line:
to:
That way, the group would be added when the order is created.
You would have to edit the file plugins/hikashop/group/group.php and change the line:
Code:
if($order->order_status != $confirmed){
Code:
if($order->order_status != 'created'){
The following user(s) said Thank You: NTV
Please Log in or Create an account to join the conversation.
2 years 9 months ago #357572
by NTV
Replied by NTV on topic Assigning User Group on order creation
Hi,
works fine, thanks a lot!
But this change will get overridden with the next update to group.php - correct?
If so, is there a way to make an override like with Views?
works fine, thanks a lot!
But this change will get overridden with the next update to group.php - correct?
If so, is there a way to make an override like with Views?
Please Log in or Create an account to join the conversation.
2 years 9 months ago #357574
by nicolas
Replied by nicolas on topic Assigning User Group on order creation
Hi,
That's correct.
You can make an override. Basically, you need to rename the plugin. Change its folder / files / class to new names based on the Joomla documentation on how to make plugins so that you basically have your own custom user group after purchase plugin.
This requires some development knowledge.
That's correct.
You can make an override. Basically, you need to rename the plugin. Change its folder / files / class to new names based on the Joomla documentation on how to make plugins so that you basically have your own custom user group after purchase plugin.
This requires some development knowledge.
Please Log in or Create an account to join the conversation.
2 years 9 months ago - 2 years 9 months ago #357682
by NTV
Replied by NTV on topic Assigning User Group on order creation
Hi,
I think that could be in the realm of my capabilities. Would I need to rename or copy the original Hika Plugin?
If I rename it, would the original not be added again with the new update?
And if I copy it, how would I stop the original from running as well?
I think that could be in the realm of my capabilities. Would I need to rename or copy the original Hika Plugin?
If I rename it, would the original not be added again with the new update?
And if I copy it, how would I stop the original from running as well?
Last edit: 2 years 9 months ago by NTV.
Please Log in or Create an account to join the conversation.
2 years 9 months ago #357690
by nicolas
Replied by nicolas on topic Assigning User Group on order creation
Hi,
You would need to copy the plugin. The original plugin will be updated / added back automatically after each update, so if you don't want to use it, you want to disable it in the Joomla plugins manager.
You would need to copy the plugin. The original plugin will be updated / added back automatically after each update, so if you don't want to use it, you want to disable it in the Joomla plugins manager.
The following user(s) said Thank You: NTV
Please Log in or Create an account to join the conversation.
1 year 4 months ago - 1 year 4 months ago #367110
by NTV
Replied by NTV on topic Assigning User Group on order creation
Hi,
digging this up again, because we tried to delegate the assigning of user groups to HikaSerial and discovered that HikaSerial is not an option for us (yet).
However, I had another idea:
Could I create an onAfterOrderCreate() function in a custom plugin, check if there are user groups associated with the product and then set it myself, leaving the original HikaShop code untouched?
Sound counter-intuitive, but for me it would be less overhead and also future proof (since we already have a custom plugin).
Something like this:
Tested it, seems to work.
Any problems this may cause that I'm not aware of?
digging this up again, because we tried to delegate the assigning of user groups to HikaSerial and discovered that HikaSerial is not an option for us (yet).
However, I had another idea:
Could I create an onAfterOrderCreate() function in a custom plugin, check if there are user groups associated with the product and then set it myself, leaving the original HikaShop code untouched?
Sound counter-intuitive, but for me it would be less overhead and also future proof (since we already have a custom plugin).
Something like this:
Code:
foreach ($order->cart->full_products as $product) {
$group = $product->product_group_after_purchase;
if ($group != '') {
$user = $userClass->get($order->order_user_id);
$email = $user->user_email;
// Find Joomla user via email
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
->where($db->quoteName('email') . ' = ' . $db->quote($email));
$db->setQuery($query);
if ($id = $db->loadResult()) $user = JFactory::getUser($id);
else return;
UserHelper::addUserToGroup($user->id, $group);
}
}
Any problems this may cause that I'm not aware of?
Last edit: 1 year 4 months ago by NTV.
Please Log in or Create an account to join the conversation.
1 year 4 months ago #367114
by nicolas
Replied by nicolas on topic Assigning User Group on order creation
Hi,
Well, that's basically similar to what I was suggesting in my previous message when I told you you could make a copy of the group plugin of HikaShop.
Whether you make a copy of the plugin, or you just copy / paste the onAfterOrderCreate function from the code of the plugin to your custom plugin and just apply the modification I proposed in my first message, either of these are fine.
Well, that's basically similar to what I was suggesting in my previous message when I told you you could make a copy of the group plugin of HikaShop.
Whether you make a copy of the plugin, or you just copy / paste the onAfterOrderCreate function from the code of the plugin to your custom plugin and just apply the modification I proposed in my first message, either of these are fine.
The following user(s) said Thank You: NTV
Please Log in or Create an account to join the conversation.
Time to create page: 0.224 seconds