VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: m.davide82 on May 22, 2012, 14:34:55 PM

Title: Hide add to cart for non registered users
Post by: m.davide82 on May 22, 2012, 14:34:55 PM
Hello,

anyone as an idea on how to see the "add to cart" only for registered users?


Thanks in advance,

David
Title: Re: Hide add to cart for non registered users
Post by: Leonard Michael on May 29, 2012, 06:21:34 AM
I'd like to know this too!

Respectfully,
LMW1
Title: Re: Hide add to cart for non registered users
Post by: stuart.prevos on May 29, 2012, 08:23:10 AM
I guess you could write a code like this in ->views->productdetails->tmpl->default_addtocart.php
=========================================================
<?php
if(!JFactory::getUser()->guest) //********************this will test if the user is logged and if they are do the following*****************//
{
?>
<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); ?>"><?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">
      <input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO') ?>" title="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO') ?>" />
      </span>
<?php } ?>

       <div class="clear"></div>
   </div>
<?php
} //*********************end of login test*********************//
?>
===============================================================

But do it by using an HTML override in your template folder.
Title: Re: Hide add to cart for non registered users
Post by: bumburum on August 19, 2012, 07:09:12 AM
NO CHANGES. replace the entire default_addtocart.php
Quote from: stuart.prevos on May 29, 2012, 08:23:10 AM
I guess you could write a code like this in ->views->productdetails->tmpl->default_addtocart.php
=========================================================
<?php
if(!JFactory::getUser()->guest) //********************this will test if the user is logged and if they are do the following*****************//
{
?>
<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); ?>"><?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">
      <input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO') ?>" title="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO') ?>" />
      </span>
<?php } ?>

       <div class="clear"></div>
   </div>
<?php
} //*********************end of login test*********************//
?>
===============================================================

But do it by using an HTML override in your template folder.