-- HikaShop version -- : Business 4.4.1
-- Joomla version -- : Joomla! 3.9.23 Stable
Hello,
quick question with no hurry.
How to get user custom field value in the product page?
Tried this but without success:
<?php
$user = hikashop_loadUser(true);
echo $user->custom_field; (using the CF column name)
?>
var_dump($user) -> NULL
Going further and deeper.
I'd like understand how to show custom fields in the different views of Hikashop using php.
What I need to do is to create some variables, based on custom fields, to change what the view will show to the user.
Right now I have just 2 main groups of users: customers and resellers (+ guest)
Customers/Guests need to see just final price (vat included) and "per unit" text under it.
Resellers need to see the base price (no Vat) and "per box" text under it.
I've been able to use the joomla user groups to control this situation, using this code (I post it here, cause maybe it could help someone else)
$user = JFactory::getUser();
$groups = JAccess::getGroupsByUser($user->id);
$groups_list = '(' . implode(',', $groups) . ')';
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('title'))
->from('#__usergroups')
->where($db->qn('id') . ' IN ' . $groups_list);
$db->setQuery($query);
$rows = $db->loadObjectList();
$grossista = false;
$gruppo ='';
$ids = array_column($rows, 'title');
foreach ($ids as $id) {
switch($id) {
case 'Grossisti':
$grossista = true;
$gruppo = 'grossisti';
break;
case 'Privati':
$gruppo = 'privati';
break;
case 'Guest':
$gruppo = 'guest';
break;
}
}
(Maybe it could be better written, but I'm not a developer)
Now, this is not a neat solution: if something changes I need to remember all the occurrences where I've injected the code.
Moreover, we're planning to add a new group: "Dropshippers" that will have its own prices and maybe other features.
What I'm planning to achieve:
I already have a user custom field: user_type (dropdown) with 2 value: customer / reseller; controlled by admin panel.
Simply adding a new value in this dropdown could help a lot cause I could avoid using the Joomla Groups and I could control what to show in the different situation, if I'll be able to recall that value everywhere in Hikashop views.
I'll also need to add a Boolean (Vat/No Vat) to better control how the price will be shown and a mass action that control the boolean based on the user_type custom value. (already have one that changes the Joomla Group the user belong to as I modify the user_type value).
It seems to me, that, by this way, I'll be better organized for future changes and I could clean up a bit my override's codes.
Thanks!
Davide