News:

Looking for documentation? Take a look on our wiki

Main Menu

Remove button Add to Cart for only some groups of users

Started by clabis71, December 28, 2011, 21:39:45 PM

Previous topic - Next topic

Lindhardsen

Quote from: clementstigma on February 18, 2012, 14:02:46 PM
Hi Lind,

Hope this helps anyone else using custom themes...thanks Lind again for sharing the code.
I'll make a PP payment once my project pays me at the end of the month! :)

Thanks Clement - Always fun, when other find my work useful ;)

jean2013

Quote from: jean2013 on February 16, 2012, 14:13:02 PM
Hello everybody :)
I would like to disable the SSL redirection when trying to checkout .
I tried to do this through :
       $mainframe = JFactory::getApplication();

       $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=editshipment',$this->useXHTML,$this->useSSL), $_retVal);

break;

    }

}



if ($cart->getInCheckOut()) {

    $mainframe = JFactory::getApplication();

    $mainframe->redirect('index.php?option=com_virtuemart&view=cart&task=checkout');

}

    }


But no, results. Please help me and thank's a lot

clabis71

New in version 2.0.2 have changed some things, I tried to make the changes you reported it does not work ...

This is the code written in vesion 2.0.2

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

clabis71

I did everything as you wrote, the button "add to cart" now if you are logged in so you do not see.
The problem is that if I do I access my endorsement from questaa button instead of "echo $ this-> loadTemplate ('addtocart');"

This is what I changed

      <?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 ) {
         $user =& JFactory::getUser();
                       if($user->id) {
      if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) { ?>
      <div class="addtocart-area">
          echo $this->loadTemplate('addtocart');
      <?php }  // Add To Cart Button END
      }
      ?>

Help me????

jlover

Dear All,

I am not programmer. please help modify to work if i add the code like below. it can remove add to card botton but registered user still can see it. i add the code from other post that i think it check shopper group  but it not work.

<?php
      // Add To Cart Button

   
           $user =&JFactory::getUser();
                    if($user->id) { 
                  
    $auth = $_SESSION['auth'];
    $shopper_group_id = $auth["shopper_group_id"];
      if($shopper_group_id >=3) {

//          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
               }                }?>


i see the shopper_group_id in VM database is 1&2 if they are anoumorous & default user. So i add this code.

Thanks in advance.

Apewire

I'm also looking for a solution to this problem. Can we aspect this feature in a future version of Virtuemart ?


Janman

      <?php
//          if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
         $user =& JFactory::getUser();
         if($user->id) if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
          echo $this->loadTemplate('addtocart');
      }  // Add To Cart Button END
      ?>

jlover


JanZet

      
On our website a user can login with username 'gast' and password 'gast'. This is a member of the virtuemart-group 'anonymous'. This user don't see any prices and the addtocart-button will not be displayed when I use these probably 'ugly' solution. Anyway for me it helped.
<?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 ) {
// Added Next 2 lines to disable addtocart-button for user with user_id = 5926, wich is member of virtuemart usergroup 'anonymous' (logged in guest)
$userid = JFactory::getUser()->id;
if ($userid <> '5926') {
if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices)) {
    echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
}
?>

andreasgr

#25
Hi

can you please tells us Milbo if you are going to include the option to hide add to cart when there are no prices ?
It useless to have add to cart button if you do not have prices and use vm2 as a catalogue. For me is a bug cuase there is no point to show the cart without prices.
Please fix it or tell us how to fix it properly until you fix it.

I use vm2.0.6

kind regards
Andreas

Apewire

So I finally have a fix that works for my webshop. The idea was that only certain groups can see the add to cart button. The following code shows the add to cart button to the group with ID 1 or the group with ID 6  ;D

       
<?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 ) {

$db JFactory::getDbo(); // Joomla database class
$user JFactory::getUser(); // get User ID

if($user->id) {  // Does the user have an ID ?
$userID $user->id;
  
// Retrieve Shopper ID group from database
$getShopperID ="
SELECT "
.$db->nameQuote('virtuemart_shoppergroup_id')."
FROM "
.$db->nameQuote('#__virtuemart_vmuser_shoppergroups')."
WHERE "
.$db->nameQuote('virtuemart_user_id')." = ".$db->quote($userID).";
"
;
$db->setQuery($getShopperID);
$shopperID $db->loadResult();

if($shopperID == || $shopperID == 6){ // shopper group ID as in the VM backoffice 
if (!VmConfig::get('use_as_catalog'0) and !empty($this->product->prices)) {
echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
}
}
?>


bumburum

where? in which file? thanks
Quote from: Apewire on August 14, 2012, 17:55:46 PM
So I finally have a fix that works for my webshop. The idea was that only certain groups can see the add to cart button. The following code shows the add to cart button to the group with ID 1 or the group with ID 6  ;D

       
<?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 ) {

$db JFactory::getDbo(); // Joomla database class
$user JFactory::getUser(); // get User ID

if($user->id) {  // Does the user have an ID ?
$userID $user->id;
  
// Retrieve Shopper ID group from database
$getShopperID ="
SELECT "
.$db->nameQuote('virtuemart_shoppergroup_id')."
FROM "
.$db->nameQuote('#__virtuemart_vmuser_shoppergroups')."
WHERE "
.$db->nameQuote('virtuemart_user_id')." = ".$db->quote($userID).";
"
;
$db->setQuery($getShopperID);
$shopperID $db->loadResult();

if($shopperID == || $shopperID == 6){ // shopper group ID as in the VM backoffice 
if (!VmConfig::get('use_as_catalog'0) and !empty($this->product->prices)) {
echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
}
}
?>



Apewire


ivus

@bumburum

just a quick note. You should never put database queries in your view output template. It potentially could expose your entire database for exploits. You should really adhere to strict MVC principles.