VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: ex3mist on August 01, 2015, 08:27:02 AM

Title: DIV ID with the name of the shopper group
Post by: ex3mist on August 01, 2015, 08:27:02 AM
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!
Title: Re: DIV ID with the name of the shopper group
Post by: ex3mist on August 02, 2015, 13:39:16 PM
Hello, anyone? I thought it is a simple question for a programist that knows VM...
Title: Re: DIV ID with the name of the shopper group
Post by: PRO on August 02, 2015, 19:10:03 PM
<?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 ;?>
Title: Re: DIV ID with the name of the shopper group
Post by: ex3mist on August 03, 2015, 09:16:51 AM
Works great for the category and product details page! Thank you!
Title: Re: DIV ID with the name of the shopper group
Post by: 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?
Title: Re: DIV ID with the name of the shopper group
Post by: 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?
Title: Re: DIV ID with the name of the shopper group
Post by: ex3mist on August 22, 2015, 14:34:59 PM
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! :)
Title: Re: DIV ID with the name of the shopper group
Post by: PRO on August 22, 2015, 16:33:46 PM

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 ;?>">
Title: Re: DIV ID with the name of the shopper group
Post by: ex3mist on August 24, 2015, 09:35:59 AM
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
$userJFactory::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!