VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Janman on April 24, 2012, 15:36:52 PM

Title: Show add to cart for registered users only
Post by: Janman on April 24, 2012, 15:36:52 PM
how can I show the  add to cart button for registered users only
version 2.0.6
joomla 2.5
Title: Re: Show add to cart for registered users only
Post by: tophatco on May 16, 2012, 20:44:12 PM
I am looking for a solution to this myself.
Title: Re: Show add to cart for registered users only
Post by: antonitus on May 16, 2012, 23:07:55 PM
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.
Title: Re: Show add to cart for registered users only
Post by: JoomTut on May 17, 2012, 06:37:50 AM
...and you can also set the permission to be "Registered" for "VirtueMart Shopping Cart" module
Title: Re: Show add to cart for registered users only
Post by: tophatco on May 18, 2012, 20:53:28 PM
Setting the permission to registered for the shopping cart module hides the shopping cart, but not the Add to Cart button an individual product. :(
Title: Re: Show add to cart for registered users only
Post by: antonitus on May 19, 2012, 12:15:40 PM
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.
Title: Re: Show add to cart for registered users only
Post by: 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
}
?>

Title: Re: Show add to cart for registered users only
Post by: bumburum on August 19, 2012, 07:01:49 AM
/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
}
?>


Title: Re: Show add to cart for registered users only
Post by: Anne M on August 24, 2012, 00:25:32 AM
in /components/com_virtuemart/views/productdetails/tmpl/default.php around line 200

Title: Re: Show add to cart for registered users only
Post by: carezza on October 18, 2012, 04:21:50 AM
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">
               
Title: Re: Show add to cart for registered users only
Post by: Anne M on October 18, 2012, 14:06:28 PM
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!!!