Hello,
I'd like to set a custom ID in a DIV in the category page which actually is the shopper group name of the current user. That would allow me to make some custom styling that is required based on the group. What I've tried is:
<div id="sg-<?php echo $product->shopper_group_name ?>">
Where "sg-" is just a prefix. But what is rendered in the HTML is only this:
<div id="sg-">
So, how can I do it? How can I call the current shopper group name and insert it in the div's ID? Thanks!
Hello, anyone? I thought it is a simple question for a programist that knows VM...
<?php
$user= JFactory::getUser();
if ($user->id==0){$div='<div id="shopper0">';}
if ($user->id !=0){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_vmuser_shoppergroups'));
$query->where($db->quoteName('virtuemart_user_id')." = ".$db->quote($user->id));
$db->setQuery($query);
$row = $db->loadAssoc();
$div='<div id="shopper'.$row['virtuemart_shoppergroup_id'].'">';
}
?>
<?php echo $div ;?>
Works great for the category and product details page! Thank you!
Another question for this - could the category and the product IDs be added in the same DIV?
Quote from: ex3mist on August 21, 2015, 09:18:33 AM
Another question for this - could the category and the product IDs be added in the same DIV?
yes
have you tried it?
Quote from: PRO on August 21, 2015, 14:45:29 PM
Quote from: ex3mist on August 21, 2015, 09:18:33 AM
Another question for this - could the category and the product IDs be added in the same DIV?
yes
have you tried it?
I'd like to, but I don't know PHP... Would be grateful if you show me how! :)
On product details page
<?php
$user= JFactory::getUser();
if ($user->id==0){$div='shopper0';}
if ($user->id !=0){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_vmuser_shoppergroups'));
$query->where($db->quoteName('virtuemart_user_id')." = ".$db->quote($user->id));
$db->setQuery($query);
$row = $db->loadAssoc();
$div='shopper'.$row['virtuemart_shoppergroup_id'].;
}
$div.=' c'.$this->product->virtuemart_category_id;
$div.=' p'.$this->product->virtuemart_product_id;
?>
<div class="<?php echo $div ;?>">
Hello,
It gave me an error on this line:
$div='shopper'.$row['virtuemart_shoppergroup_id'].;
but I copied and replaced it with the same line from the previous code you gave, and now it works perfect. It looks like this now:
<?php
$user= JFactory::getUser();
if ($user->id==0){$div='shopper0';}
if ($user->id !=0){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_vmuser_shoppergroups'));
$query->where($db->quoteName('virtuemart_user_id')." = ".$db->quote($user->id));
$db->setQuery($query);
$row = $db->loadAssoc();
$div='<div id="shopper'.$row['virtuemart_shoppergroup_id'].'">';
}
$div.=' CategoryID'.$this->product->virtuemart_category_id;
$div.=' ProductID'.$this->product->virtuemart_product_id;
?>
<div class="<?php echo $div ;?>">
Thanks a lot!