News:

Support the VirtueMart project and become a member

Main Menu

DIV ID with the name of the shopper group

Started by ex3mist, August 01, 2015, 08:27:02 AM

Previous topic - Next topic

ex3mist

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!

ex3mist

Hello, anyone? I thought it is a simple question for a programist that knows VM...

PRO

<?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 ;?>

ex3mist

Works great for the category and product details page! Thank you!

ex3mist

Another question for this - could the category and the product IDs be added in the same DIV?

PRO

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?

ex3mist

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! :)

PRO


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 ;?>">

ex3mist

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!