VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Alexanderz on March 03, 2016, 10:30:15 AM

Title: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 03, 2016, 10:30:15 AM
Hi, use the latest version of VM 3.0.13.6 and wanted to know if there was a way like in V2 to hide the "add to cart" to those who were not registered, including by changing the module itself.

Thank you

P.S. I think, it is a function that should be integrated natively in VM3. It is very important for many sellers.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: GJC Web Design on March 03, 2016, 10:38:01 AM
std. user check snippet in the cart   display..  over ride components\com_virtuemart\sublayouts\addtocartbar.php

$user = JFactory::getUser();   
  $user_id = $user->get('id');   


if (!VmConfig::get('use_as_catalog', 0) && $userid != 0 ) { ?>
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: jenkinhill on March 03, 2016, 11:31:21 AM
Quote from: Alexanderz on March 03, 2016, 10:30:15 AM
It is very important for many sellers.

Almost every VirtueMart site I have worked on does not use customer registration at all, but as GJC says, it just takes a simple template override to provide this function.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 03, 2016, 15:57:10 PM
thanks for the answer, but it seems not work.
I created an override in mytemplates/html/com_virtuemart/sublayouts/addtocartbar.php

add :
$user = JFactory::getUser();
$user_id = $user->get('id');

and replace:


if (!VmConfig::get('use_as_catalog', 0)  ) { ?> in
if (!VmConfig::get('use_as_catalog', 0) && $userid != 0 ) { ?>

Here is the php source --> http://pastie.org/10746389

Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: GJC Web Design on March 03, 2016, 17:15:08 PM
if (!VmConfig::get('use_as_catalog', 0) && $user_id != 0 ) { ?>
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 03, 2016, 19:44:26 PM
still does not work.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: GJC Web Design on March 04, 2016, 00:38:38 AM
then debug it and find out why not.......
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Studio 42 on March 04, 2016, 00:52:18 AM
Hi Alexanderz,
Have you check if your template do not overide it?
Some do not use the sublayouts, so changing the code here do not remove the add to cart render.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 04, 2016, 12:39:02 PM
hi Studio 42
Yes, I also tried to change the component itself, without using overide, but does not work the same.

in homepage of my site under "Session" of debug, I see this:

index.php?option=com_virtuemart&view=virtuemart&productsublayout=0

⇒{"__default":{"session":{"counter":6,"timer":{"start":1457090728,"last":1457091067,"now":1457091177},"token":"40417277850c8601ad1d2cca089f2ce4"},"registry":{"separator":"."},"user":{"id":0,"name":null,"username":null,"email":null,"password":null,"password_clear":"","block":null,"sendEmail":0,"registerDate":null,"lastvisitDate":null,"activation":null,"params":null,"groups":["9"],"guest":1,"lastResetTime":null,"resetCount":null,"requireReset":null,"aid":0}},"__easycalccheck":{"redirect_url":null,"hidden_class":"es8tzs2re7l","spamcheck":"omfcimpwpd93","rot13":1,"spamcheckresult":"ZGp=","time":1457091068,"ip":"87.20.177.198"},"__vm":{"manage":0,"vmlastvisitedItemid":134,"vmcart":"{\"cartProductsData\":[{\"virtuemart_product_id\":10,\"quantity\":1,\"customProductData\":[]}],\"vendorId\":1,\"lastVisitedCategoryId\":0,\"virtuemart_shipmentmethod_id\":\"5\",\"virtuemart_paymentmethod_id\":0,\"automaticSelectedShipment\":true,\"automaticSelectedPayment\":false,\"order_number\":null,\"BT\":0,\"ST\":0,\"cartfields\":null,\"couponCode\":\"\",\"_triesValidateCoupon\":[],\"order_language\":\"it-IT\",\"pricesCurrency\":182,\"paymentCurrency\":null,\"_guest\":1,\"_inCheckOut\":false,\"_inConfirm\":false,\"_dataValidated\":false,\"_confirmDone\":false,\"STsameAsBT\":1,\"selected_shipto\":0,\"_fromCart\":false,\"layout\":\"default\",\"layoutPath\":\"\",\"virtuemart_cart_id\":0}","vmlastvisitedcategoryid":0,"vmlastvisitedmanuid":0}}
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Studio 42 on March 04, 2016, 13:03:33 PM
WHy you don't dump the use_id?
<php var_dump($user->get('id')) ?>
So you can check if you are in the good file and that the value change.
Another problem can be that you use page cache in Joomla ?
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 04, 2016, 13:17:08 PM
How can I dump the user_id?

I deleted the Joomla cache but still does not work.
thank you.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Jörgen on March 04, 2016, 14:03:56 PM
Quote from Patrick
WHy you don't dump the use_id?
<php var_dump($user->get('id')) ?>


regards

Jörgen @ Kreativ Fotografi
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Milbo on March 04, 2016, 14:42:44 PM
Quote from: Studio 42 on March 04, 2016, 13:03:33 PM
WHy you don't dump the use_id?
<php var_dump($user->get('id')) ?>

Please use vmdebug('my stuff',$user);
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 04, 2016, 15:49:58 PM
Excuse me , but I still do not understand .
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Studio 42 on March 04, 2016, 22:33:51 PM
Quote from: Milbo on March 04, 2016, 14:42:44 PM
Quote from: Studio 42 on March 04, 2016, 13:03:33 PM
WHy you don't dump the use_id?
<php var_dump($user->get('id')) ?>

Please use vmdebug('my stuff',$user);
Or echo, this is not the problem.

YOu said, you have change codes but don't know how to add a var_dump or echo, print_r ...?
So please read the PHP Doc to know some elementary function , else we cannot help you.
We can help you, but we don't work for you ;)
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 06, 2016, 13:47:10 PM
Could you give me a tip on how to do?
It is very important for me to implement this thing.

I need to create a php file and enter the code for the dump or do I add in addtocartbar.php?

The help you are giving me all of you is still appreciated.
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: GJC Web Design on March 06, 2016, 18:07:55 PM
after $user = JFactory::getUser();

add

print 'Debug Line '.__LINE__.' $user <pre>'; print_r ($user); print "</pre><br />\n";
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 06, 2016, 20:08:26 PM
adding, seems not to appear none debug message. When I enter inside the object, however, comes out the error message:

"Fatal error: Call to a member function get () on a non-object in /templates/mytemplates/html/com_virtuemart/sublayouts/addtocartbar.php on line 28"
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: GJC Web Design on March 06, 2016, 21:42:14 PM
then u have a mistake...  but it is unreasonable to ask someone to code by long distance via a forum for changes you want to make to your site...

we have no idea what you are coding..

Sorry, either you learn some php or employ someone to do this for you -- this is basic stuff.... 
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 07, 2016, 08:49:09 AM
Maybe it's because I'm using a purchased theme? So it may work differently?
Yet, I have always used a guide in this forum for VM2 and had no problems. ( http://forum.virtuemart.net/index.php?topic=101797.0 )

However i repeat, you have been kind to help me  :)
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Studio 42 on March 07, 2016, 09:13:19 AM
Quote from: GJC Web Design on March 06, 2016, 21:42:14 PM
then u have a mistake...  but it is unreasonable to ask someone to code by long distance via a forum for changes you want to make to your site...

we have no idea what you are coding..

Sorry, either you learn some php or employ someone to do this for you -- this is basic stuff.... 
I think it's the right answer. First learn PHP or find a developper.
THis is a basic problem, how you do the day your site is crashed, or your cart is not working anymore?
Title: Re: [VM3] Hide add to cart option to unregistered?
Post by: Alexanderz on March 07, 2016, 11:46:42 AM
I will follow your advice. Thank you for everything.