VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: Mongrel on August 28, 2012, 12:45:35 PM

Title: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 28, 2012, 12:45:35 PM
Hello,

I have searched for this all afternoon and can't find an answer?

I have my site setup so that unless you login, you don't see the prices, which is good, but you can still add products to the cart which is bad!!

I don't want unregistered users to be able to see the Add to Cart buttons - why would they, they can't buy anyway.

Can any one assist please?

Cheers
John
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: jenkinhill on August 28, 2012, 16:41:24 PM
http://forum.virtuemart.net/index.php?topic=106642.msg356716#msg356716
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 02:02:59 AM
Hi,

Thanks for the reply but I have done that - And yes - The prices are gone - But the Add To Cart buttons are still there!!  Why?
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 05:16:48 AM
Hi Mongrel,

Perhaps this will help.

http://forum.virtuemart.net/index.php?topic=106484.msg356669#msg356669 (http://forum.virtuemart.net/index.php?topic=106484.msg356669#msg356669)

God luck  ;D
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 05:24:46 AM
Yes - But that would mean MUCH code change.  :(

I just can't understand why you would want to show the Add Cart if there are no prices?  What the???
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 05:30:47 AM
Hi Mongrel,

It's only 3 lines of code.

QuoteI just can't understand why you would want to show the Add Cart if there are no prices?  What the???
-- I don't know.
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 05:32:55 AM
really! Ok.. I am not good at all on PHP.

Can you please explain?
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 05:37:30 AM
/component/com_virtuemart/views/productdetails/tmpl/default_addtocart.php



<?php
/**
 *
 * Show the product details page
 *
 * @package VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen
 * @todo handle child products
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_addtocart.php 6260 2012-07-12 07:42:04Z Milbo $
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
if ( ! 
$user->get('guest')) {
?>

<div class="addtocart-area">

    <form method="post" class="product js-recalculate" action="index.php" >
<?php // Product custom_fields
if (!empty($this->product->customfieldsCart)) { ?>

    <div class="product-fields">
<?php foreach ($this->product->customfieldsCart as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title?></strong></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php
}
?>

    </div>
<?php
}
/* Product custom Childs
 * to display a simple link use $field->virtuemart_product_id as link to child product_id
 * custom_value is relation value to child
 */

if (!empty($this->product->customsChilds)) {
    ?>

    <div class="product-fields">
    <?php foreach ($this->product->customsChilds as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->field->custom_title?></strong></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

    </div><br />
<?php ?>
    </div>
<?php ?>

<div class="addtocart-bar">

<?php // Display the quantity box

    
$stockhandle VmConfig::get('stockhandle''none');
    if ((
$stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
 
?>

<a href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>" class="notify"><?php echo JText::_('COM_VIRTUEMART_CART_NOTIFY'?></a>

<?php } else { ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
    <span class="quantity-box">
<input type="text" class="quantity-input js-recalculate" name="quantity[]" value="<?php if (isset($this->product->min_order_level) && (int) $this->product->min_order_level 0) {
    echo 
$this->product->min_order_level;
} else {
    echo 
'1';
?>
" />
    </span>
    <span class="quantity-controls js-recalculate">
<input type="button" class="quantity-controls quantity-plus" />
<input type="button" class="quantity-controls quantity-minus" />
    </span>
    <?php // Display the quantity box END ?>

    <?php
    
// Display the add to cart button
    ?>

<span class="addtocart-button">
<?php echo shopFunctionsF::getAddToCartButton($this->product->orderable); ?>
</span>
<?php ?>

    <div class="clear"></div>
</div>

<?php // Display the add to cart button END  ?>
<input type="hidden" class="pname" value="<?php echo $this->product->product_name ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>" />
    </form>

    <div class="clear"></div>
</div>
<?php 
}

Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 05:55:42 AM
No :(  This didn't work.  :(
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 05:56:18 AM
You can see here...   http://www.garryflemingpublishing.com/
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 06:00:31 AM
I forgot your had this installed. Find the same file in your templates override folder and apply it there.

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core (http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core)
http://docs.joomla.org/Understanding_Output_Overrides (http://docs.joomla.org/Understanding_Output_Overrides)
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 06:05:37 AM
Ahh Ok.  I see that in the templates.  However, If I just replace the one in the template I will lose all the styles I think.  :(
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 06:23:50 AM


<?php
/**
 *
 * Show the product details page
 *
 * @package VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen
 * @todo handle child products
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_addtocart.php 6260 2012-07-12 07:42:04Z Milbo $
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
if ( ! 
$user->get('guest')) {
?>


YOUR EXISTING CODE GOES HERE...

<?php 
}



And if you get lost here... might be a good idea to provide your code.
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 06:28:05 AM
Yeah I tried that and it didn't work - maybe I am missing something.

Here is my entire code..

<?php
/**

* @Enterprise: Yagendoo Media GmbH
* @author: Yagendoo Team
* @url: http://www.yagendoo.com
* @copyright: Copyright (C) Yagendoo Media GmbH
* @license: Commercial, see LICENSE.php
* @product: Virtuemart Theme
*
*/
?>

<?php if(!VmConfig::get('use_as_catalog'0)): ?>
<div class="yagVmFlyAtc">
<form method="post" class="product yagVmFlyAtcForm js-recalculate" action="index.php" >
<?php //::> Custom fields cart ?>
<?php if(!empty($this->product->customfieldsCart)):  ?>
<div class="product-fields yagVmFlyProdFields">
<?php foreach($this->product->customfieldsCart as $field): ?>
<div class="yagVmFlyProdField yagVmFlyProdFieldType-<?php echo $field->field_type ?>">
<span class="yagVmFlyProdFieldTitle">
<?php echo  JText::_($field->custom_title?>
<?php if($field->custom_tip): ?>
<?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
<?php endif; ?>
</span>

<div class="yagVmFlyProdFieldRight">
<span class="yagVmFlyProdFieldDisplay"><?php echo $field->display ?></span>
<span class="yagVmFlyProdFieldDesc"><?php echo $field->custom_field_desc ?></span>
</div>

<div class="yagVmClear">&nbsp;</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>

<?php //::> Custom childs ?>
<?php if(!empty($this->product->customsChilds)):  ?>
<div class="yagVmFlyProdFields">
<?php foreach($this->product->customsChilds as $field):  ?>
<div class="yagVmFlyProdField yagVmFlyProdFieldType-<?php echo $field->field->field_type ?>">
<span class="yagVmFlyProdFieldTitle">
<?php echo JText::_($field->field->custom_title?>
</span>

<div class="yagVmFlyProdFieldRight">
<span class="yagVmFlyProdFieldDesc"><?php echo JText::_($field->field->custom_value?></span>
<span class="yagVmFlyProdFieldDisplay"><?php echo $field->display ?></span>
</div>

<div class="yagVmClear">&nbsp;</div>
</div>
<br />
<?php endforeach; ?>
</div>
<?php endif; ?>

<?php //::> Add to cart bar ?>
<div class="addtocart-bar yagVmFlyAtcBar">
<?php $stockhandle VmConfig::get('stockhandle''none'); ?>

<?php if( ($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock $this->product->product_ordered ) < ) : ?>
<a class="yagVmFlyNotifyBtn" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>">
<?php echo JText::_('COM_VIRTUEMART_CART_NOTIFY'?>
</a>
<?php else : ?>
<span class="yagVmFlyAtcBarQtyBox">
<input type="text" class="quantity-input yagVmFlyAtcBarQtyInpt js-recalculate" name="quantity[]" value="<?php if (isset($this->product->min_order_level) && (int) $this->product->min_order_level 0) { echo $this->product->min_order_level;} else { echo '1'; } ?>" />
</span>

<span class="quantity-controls yagVmFlyAtcBarQtyCtrl js-recalculate">
<input type="button" class="quantity-controls yagVmFlyAtcVarQtyPlus quantity-plus" />
<input type="button" class="quantity-controls yagVmFlyAtcVarQtyMinus quantity-minus" />
</span>

<div class="yagVmClear">&nbsp;</div>

<span class="addtocart-button yagVmFlyAtcBtn">
<input type="submit" name="addtocart"  class="yagVmFlyAtcBtn addtocart-button" value="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'?>" title="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'?>" />
</span>

<div class="yagVmClear">&nbsp;</div>
<?php endif; ?>
</div>

<input type="hidden" class="pname" value="<?php echo $this->product->product_name ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>" />
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $this->product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $this->product->virtuemart_category_id ?>" />
</form>

<div class="yagVmClear">&nbsp;</div>
</div>
<?php endif; ?>
Title: Re: Hide Add to Cart Buttons for non registered users
Post by: ivus on August 29, 2012, 06:37:59 AM


<?php
/**

* @Enterprise: Yagendoo Media GmbH
* @author: Yagendoo Team
* @url: http://www.yagendoo.com
* @copyright: Copyright (C) Yagendoo Media GmbH
* @license: Commercial, see LICENSE.php
* @product: Virtuemart Theme
*
*/
?>

<?php if(!VmConfig::get('use_as_catalog'0)): ?>

<?php
$user =& JFactory::getUser();
if ( ! $user->get('guest')):
?>


<div class="yagVmFlyAtc">
<form method="post" class="product yagVmFlyAtcForm js-recalculate" action="index.php" >
<?php //::> Custom fields cart ?>
<?php if(!empty($this->product->customfieldsCart)):  ?>
<div class="product-fields yagVmFlyProdFields">
<?php foreach($this->product->customfieldsCart as $field): ?>
<div class="yagVmFlyProdField yagVmFlyProdFieldType-<?php echo $field->field_type ?>">
<span class="yagVmFlyProdFieldTitle">
<?php echo  JText::_($field->custom_title?>
<?php if($field->custom_tip): ?>
<?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
<?php endif; ?>
</span>

<div class="yagVmFlyProdFieldRight">
<span class="yagVmFlyProdFieldDisplay"><?php echo $field->display ?></span>
<span class="yagVmFlyProdFieldDesc"><?php echo $field->custom_field_desc ?></span>
</div>

<div class="yagVmClear">&nbsp;</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>

<?php //::> Custom childs ?>
<?php if(!empty($this->product->customsChilds)):  ?>
<div class="yagVmFlyProdFields">
<?php foreach($this->product->customsChilds as $field):  ?>
<div class="yagVmFlyProdField yagVmFlyProdFieldType-<?php echo $field->field->field_type ?>">
<span class="yagVmFlyProdFieldTitle">
<?php echo JText::_($field->field->custom_title?>
</span>

<div class="yagVmFlyProdFieldRight">
<span class="yagVmFlyProdFieldDesc"><?php echo JText::_($field->field->custom_value?></span>
<span class="yagVmFlyProdFieldDisplay"><?php echo $field->display ?></span>
</div>

<div class="yagVmClear">&nbsp;</div>
</div>
<br />
<?php endforeach; ?>
</div>
<?php endif; ?>

<?php //::> Add to cart bar ?>
<div class="addtocart-bar yagVmFlyAtcBar">
<?php $stockhandle VmConfig::get('stockhandle''none'); ?>

<?php if( ($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock $this->product->product_ordered ) < ) : ?>
<a class="yagVmFlyNotifyBtn" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id='.$this->product->virtuemart_product_id); ?>">
<?php echo JText::_('COM_VIRTUEMART_CART_NOTIFY'?>
</a>
<?php else : ?>
<span class="yagVmFlyAtcBarQtyBox">
<input type="text" class="quantity-input yagVmFlyAtcBarQtyInpt js-recalculate" name="quantity[]" value="<?php if (isset($this->product->min_order_level) && (int) $this->product->min_order_level 0) { echo $this->product->min_order_level;} else { echo '1'; } ?>" />
</span>

<span class="quantity-controls yagVmFlyAtcBarQtyCtrl js-recalculate">
<input type="button" class="quantity-controls yagVmFlyAtcVarQtyPlus quantity-plus" />
<input type="button" class="quantity-controls yagVmFlyAtcVarQtyMinus quantity-minus" />
</span>

<div class="yagVmClear">&nbsp;</div>

<span class="addtocart-button yagVmFlyAtcBtn">
<input type="submit" name="addtocart"  class="yagVmFlyAtcBtn addtocart-button" value="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'?>" title="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'?>" />
</span>

<div class="yagVmClear">&nbsp;</div>
<?php endif; ?>
</div>

<input type="hidden" class="pname" value="<?php echo $this->product->product_name ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>" />
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $this->product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $this->product->virtuemart_category_id ?>" />
</form>

<div class="yagVmClear">&nbsp;</div>
</div>
   
<?php endif; ?>   
   
<?php endif; ?>

Title: Re: Hide Add to Cart Buttons for non registered users
Post by: Mongrel on August 29, 2012, 06:42:03 AM
THANK YOU THANK YOU THANK YOU!!!

Fantastic!!   It works now!!  PHEW!!!

No all I need to get working is the Notify Me button and I can launch the site.  :)