VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: schregi on January 26, 2012, 09:27:05 AM

Title: Hide cart if empty
Post by: schregi on January 26, 2012, 09:27:05 AM
Hey,
is it possible to hide the cart module when there is no product in and show it as soon as the customer adds something to the cart?

I tried the Advanced Module Manager with a php session query but that doesn't work at all because i don't know the right variable.

Thanks for your help!
Title: Re: Hide cart if empty
Post by: Actlas on May 07, 2012, 10:17:27 AM
Same question...
Title: Re: Hide cart if empty
Post by: 36above on May 07, 2012, 15:25:58 PM
There are a few ways to tackle this, depending if you want to hide the module content or hide the whole module position and collapse it.

To hide the 'no products' message, open mod_virtuemart_cart.php around line 40 you will see else

else $data->totalProductTxt = JText::_('COM_VIRTUEMART_EMPTY_CART');
that displays the empty cart message, get rid of it or replace it as you see fit.


To collapse the whole module position, make a position only for the cart in your template, something like
<jdoc:include type="modules" name="vm_cart" /> (note, you will have to add this to your templates XML too

then load the VM functions, get the cart, prep the data and test the same way as in the module.


<?php
if (!class_exists'VmConfig' )) require(JPATH_ADMINISTRATOR DS 'components' DS 'com_virtuemart'.DS.'helpers'.DS.'config.php');
if(!
class_exists('VirtueMartCart')) require(JPATH_VM_SITE.DS.'helpers'.DS.'cart.php');
$cart VirtueMartCart::getCart(false);
$data $cart->prepareAjaxData();

if (
$data->totalProduct>1) echo "There is more than one, display the jdoc module include code here";
else if (
$data->totalProduct == 1) echo "There is only one, display the jdoc module include code for single here";
else echo 
"No products, don't display the include code";
?>



its a little hacky but works OK. Copy/paste it into the top of your template and check it out.