VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: clabis71 on December 28, 2011, 21:39:45 PM

Title: Remove button Add to Cart for only some groups of users
Post by: clabis71 on December 28, 2011, 21:39:45 PM
Hi,

use joomla 1.7.3 and VM2

I need not to bring up the add to cart button for a specific group of users, but I can not do it, I managed to hide only the prices but it remains button shopping cart and then appears the words if you want to continue or view the shopping cart. Clicking it displays prices again even if that group of users is not enabled, how can I fix this?
In the version of Joomla 1.1.9 was displayed the words that had not been allowed to add to cart.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Milbo on December 28, 2011, 22:22:10 PM
This feature is at the moment missing, but it is relativly easy to add, we just need to extend the catalogue mode per shoppergroups.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clabis71 on January 01, 2012, 10:30:29 AM
deadlines?
Title: Re: Remove button Add to Cart for only some groups of users
Post by: IllusionStudio on January 12, 2012, 09:46:01 AM
This feature is absolutely essential for my shop, too. Is there any publishing date planned?
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Lindhardsen on January 18, 2012, 20:55:42 PM
I add myself to the list of users who need this.

Are there any plans to implement this, and if so, is there any planned release date?

On the other hand, if we need to implement this ourselves, does anyone have some code to share?

Thanks in advance!
/Jan
Title: Re: Remove button Add to Cart for only some groups of users
Post by: tambay1001 on February 03, 2012, 02:17:37 AM
yes. this is the one i've been looking for! Disabling "Add to Cart button" and "Ask a question about this product". I just want to display available products and its details. this would be a good feature.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clementstigma on February 03, 2012, 07:48:35 AM
Yeap, I definitely need this for one of the development I'm doing right now too! :)
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Milbo on February 03, 2012, 13:09:04 PM
2.0.1c is a step in that direction.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Lindhardsen on February 06, 2012, 20:49:40 PM
Quote from: Milbo on February 03, 2012, 13:09:04 PM
2.0.1c is a step in that direction.

Milbo, can you please explain a little more regarding what is coming in 2.0.1?

I actually ended up doing my own hack for this:
Now, prices are controlled by the standard functionality, so you can show them to all users if you want, or not.
What I have added, is a check to determine if the user is logged in or not. If the user is logged in, everything looks like normal.
If the user is not logged in, the "Add to Cart" is not shown. Also, you can choose whether or not to display the "Ask a question" button.
There is no "gui" to control this, if you implement my changes, this is what you get, you cannot turn it on/off from within VM control panel.

Should anyone be interested in this solution, I can probably share it with you ;)
But again, it should be interesting to hear what is included in the next release.

Title: Re: Remove button Add to Cart for only some groups of users
Post by: clabis71 on February 08, 2012, 12:55:39 PM
Quote from: Milbo on February 03, 2012, 13:09:04 PM
2.0.1c is a step in that direction.

I installed the 2.0.1e release, but I see no solution to the problem, add to cart button still work even if you are not registered
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clementstigma on February 14, 2012, 03:24:40 AM
Quote from: Lindhardsen on February 06, 2012, 20:49:40 PM
Quote from: Milbo on February 03, 2012, 13:09:04 PM
2.0.1c is a step in that direction.

Milbo, can you please explain a little more regarding what is coming in 2.0.1?

I actually ended up doing my own hack for this:
Now, prices are controlled by the standard functionality, so you can show them to all users if you want, or not.
What I have added, is a check to determine if the user is logged in or not. If the user is logged in, everything looks like normal.
If the user is not logged in, the "Add to Cart" is not shown. Also, you can choose whether or not to display the "Ask a question" button.
There is no "gui" to control this, if you implement my changes, this is what you get, you cannot turn it on/off from within VM control panel.

Should anyone be interested in this solution, I can probably share it with you ;)
But again, it should be interesting to hear what is included in the next release.

Heya, I'm in serious need of this hack, could you kindly share the solution which you used please? :)
I've been trying to figure it out on my own but it's just been insane!
Title: Re: Remove button Add to Cart for only some groups of users
Post by: cyberx on February 14, 2012, 16:21:15 PM
yes, yes, yes need this feature in my shop!
please tell me when come on this?
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Lindhardsen on February 15, 2012, 23:29:16 PM
OK, here we go :D

In order to remove the Add to cart, follow these steps:

In the folder /components/com_virtuemart/views/productdetails/tmpl/ open the file called default.php (or <yourthemename>.php, if you are using a custom theme).
Approx. at the line number 145 (below the line that says: <?php // Add To Cart Button), add these lines:
                    $user =& JFactory::getUser();
                    if($user->id) {   

So that the start of the section now reads:
                    <?php // Add To Cart Button
                   
                    $user =& JFactory::getUser();
                    if($user->id) {               
                    if (!VmConfig::get('use_as_catalog',0)) { ?>
                    <div class="addtocart-area">

And then we need to close this up (this was actually what caused most headache to me personally... Kind of hard to grip the structure of the mixed html and php code in the same file):
At approx. line number 238, change to that it reads:
                    <?php }  // Add To Cart Button END
                    } ?>

Basically what this does, is to remove the Add to Cart button, unless you are a logged in user.

If you have comments on this, if you like it or not, please leave a comment! If you like it helped you as much as it did myself, feel free to leave a small token of appreciation on Paypal,  https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CU6U3PQ4FK5RW (https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CU6U3PQ4FK5RW) ;-) This is not much code, but I can promise I spend many hours figuring this out!
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Lindhardsen on February 15, 2012, 23:34:15 PM
Also, in my implementation, we have replaced the "Ask seller a question" button with a "Log in to see prices" hyperlink, if the user is not logged in. Let me know if anyone are interested in the little addition as well.

/Jan
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clementstigma on February 18, 2012, 14:02:46 PM
Hi Lind,

Thanks for the code!
I'm using a custom theme by Flexible Web Design or something so the code somehow didn't work for me.
Basically, I used the same codes but removed:
1. the { after if ($user->id)
2. didn't add any additional lines to Add to Cart Button END

I messed around with it and did the following:

1. After  <?php // Add To Cart Button, add:
                $user   = &JFactory::getUser();
                if ($user->id)

Final Code:
         <?php // Add To Cart Button
            
            $user   = &JFactory::getUser();
                                if ($user->id)
            if (!VmConfig::get('use_as_catalog',0)) { ?>
            <div class="addtocart-area">

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! :)
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Lindhardsen on February 18, 2012, 20:04:39 PM
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 ;)
Title: Pleaze help me to disable https protocole when checkout
Post by: jean2013 on February 20, 2012, 20:26:01 PM
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
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clabis71 on February 24, 2012, 22:50:49 PM
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
      ?>
Title: Re: Remove button Add to Cart for only some groups of users
Post by: clabis71 on February 28, 2012, 13:17:05 PM
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????
Title: Re: Remove button Add to Cart for only some groups of users
Post by: jlover on March 15, 2012, 02:52:11 AM
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.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Apewire on April 02, 2012, 18:19:23 PM
I'm also looking for a solution to this problem. Can we aspect this feature in a future version of Virtuemart ?
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Janman on April 24, 2012, 16:05:16 PM
solution pls
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Janman on April 24, 2012, 16:16:27 PM
      <?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
      ?>
Title: Re: Remove button Add to Cart for only some groups of users
Post by: jlover on May 04, 2012, 18:30:10 PM
now i can hide price for registered user  :D
Title: Re: Remove button Add to Cart for only some groups of users
Post by: JanZet on June 23, 2012, 05:01:12 AM
      
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
}
?>
Title: Re: Remove button Add to Cart for only some groups of users
Post by: andreasgr on June 28, 2012, 02:37:15 AM
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
Title: Re: Remove button Add to Cart for only some groups of users
Post by: 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
}
}
?>

Title: Re: Remove button Add to Cart for only some groups of users
Post by: bumburum on August 21, 2012, 06:53:33 AM
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
}
}
?>


Title: Re: Remove button Add to Cart for only some groups of users
Post by: Apewire on August 21, 2012, 12:26:43 PM
override the productdetails/tmpl/default.php  :)
Title: Re: Remove button Add to Cart for only some groups of users
Post by: ivus on August 21, 2012, 13:37:57 PM
@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.
Title: Re: Remove button Add to Cart for only some groups of users
Post by: dmic on June 28, 2013, 00:10:34 AM
Quote from: ivus on August 21, 2012, 13:37:57 PM
@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.

@ivus Do you know of a way to do this without outputting a db query?

Thanks

Dave
Title: Re: Remove button Add to Cart for only some groups of users
Post by: Rozie on January 26, 2018, 15:02:40 PM
If anyone is interested there is an updated (January 2018) solution to this topic here https://forum.virtuemart.net/index.php?topic=136494.0