how can I show the add to cart button for registered users only
version 2.0.6
joomla 2.5
I am looking for a solution to this myself.
Set up a menu for the VM shopping cart module and set the permission to be 'Registered', not 'Public' so those who are registered will only see the cart.
...and you can also set the permission to be "Registered" for "VirtueMart Shopping Cart" module
Setting the permission to registered for the shopping cart module hides the shopping cart, but not the Add to Cart button an individual product. :(
Not sure if hiding the 'Add to Cart' button on an unregistered user is possible, but not sure, maybe a hack is in order and maybe someone on here who is a PHP guru can help you out.
Figured it out. Modified the add to cart code in the template, using a tip from another Joomla thread to check the user status. Seems to work.
<?php
// check if user is logged in/registered.
$user =& JFactory::getUser(); if( $user->id ){
// Add To Cart Button
if (!VmConfig::get('use_as_catalog', 0)) {
echo $this->loadTemplate('addtocart');
} // Add To Cart Button END
}
?>
/components/com_virtuemart/views/productdetails/tmpl IN default_addtocart.php? Where exactly? THANKS!
Quote from: tophatco on May 21, 2012, 17:19:37 PM
Figured it out. Modified the add to cart code in the template, using a tip from another Joomla thread to check the user status. Seems to work.
<?php
// check if user is logged in/registered.
$user =& JFactory::getUser(); if( $user->id ){
// Add To Cart Button
if (!VmConfig::get('use_as_catalog', 0)) {
echo $this->loadTemplate('addtocart');
} // Add To Cart Button END
}
?>
in /components/com_virtuemart/views/productdetails/tmpl/default.php around line 200
I just added the code to the php file and the button is still there. So what exactly do you modify?
here is my code from line 184 to 200 before modification...
<?php
// Add the button
$button_lbl = JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls = 'addtocart-button cart-click2'; //$button_cls = 'addtocart_button';
$button_name = 'addtocart'; //$button_cls = 'addtocart_button';
// Display the add to cart button
$stockhandle = VmConfig::get('stockhandle', 'none');
if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock - $this->product->product_ordered) < 1) {
$button_lbl = JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls = 'addtocart-button';
$button_name = 'notifycustomer';
}
//vmdebug('$stockhandle '.$stockhandle.' and stock '.$this->product->product_in_stock.' ordered '.$this->product->product_ordered);
?>
<div class="wrapper">
<div class="fright">
I don't know which PHP file your are quoting from?
You should adjust in /components/com_virtuemart/views/productdetails/tmpl/default.php around line 200
before modification fromline 200:
<?php
// Add To Cart Button
// if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
echo $this->loadTemplate('addtocart');
} // Add To Cart Button END
?>
after modification from line 200:
<?php
// check if user is logged in/registered.
// $user =& JFactory::getUser(); if( $user->id ){
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1){
echo "Log in om de prijzen te zien.";
}
else
{
// Add To Cart Button
if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
echo $this->loadTemplate('addtocart');
} // Add To Cart Button END
}
?>
the text "Log in om de prijzen te zien." will be shown when user is not logged in.
Please read the path to right PHP file carefully.
Always make valid backup before you alter PHP files!!!