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:
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);
}
}
Tested it, seems to work.
Any problems this may cause that I'm not aware of?