Hi,
I've been struggling with this. I've got my joomla/virtuemart running in a directory called "store" and I wish to display the total number of products in the cart outside of the joomla framework. So I've come up with this code, which works fine with older versions of virtuemart ( < v3). However, when trying it with Virtuemart 3.0.16, I'm running into these problems:
The code (which is in a directory called "includes")
Quote<?php
// Set flag that this is a parent file
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(realpath(__FILE__)). '/../store' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');
$mainframe = JFactory::getApplication('site');
$array = unserialize($_SESSION['__vm']['vmcart']);
$total = 0;
foreach($array->products as $product){
$total += $product->amount;
}
echo "" . $total;
?>
And the error:
Quote
Warning: Invalid argument supplied for foreach() in /home/me/public_html/includes/header.php on line 20
0
where 0 represents the cart total, which should show 1, since at the time I had an item in cart
I'm not a php expert, but open googling that, it seems to me that my $array isn't an array which is causing the problems?
This is really confusing me since it's working fine in older version of virtuemart.
I think the changes are joomla3 and not VM
Add same code as the cart module :
<?php
// Set flag that this is a parent file
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(realpath(__FILE__)). '/../store' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');
// NEW CODE
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if(!class_exists('VirtueMartCart')) require(VMPATH_SITE.DS.'helpers'.DS.'cart.php');
$cart = VirtueMartCart::getCart(false);
$data = $cart->prepareAjaxData();
foreach ($data->products as $product){
// here what you need to display see \modules\mod_virtuemart_cart\tmpl\default.php
}
Thanks, I tried this but I got the following new errors:
Quoterequire() @ /home/me/public_html/includes/test.php:16
JFactory :: getApplication() @ /home/me/public_html/store/administrator/components/com_virtuemart/helpers/config.php:25
JError :: raiseError() @ /home/me/public_html/store/libraries/joomla/factory.php:99
JError :: raise() @ /home/me/public_html/store/libraries/joomla/error/error.php:251
JError :: throwError() @ /home/me/public_html/store/libraries/joomla/error/error.php:176
call_user_func_array() @ /home/me/public_html/store/libraries/joomla/error/error.php:214
JError :: handleCallback()
call_user_func() @ /home/me/public_html/store/libraries/joomla/error/error.php:765
JError :: customErrorPage()
JFactory :: getApplication() @ /home/me/public_html/store/libraries/joomla/error/error.php:784
JError :: raiseError() @ /home/me/public_html/store/libraries/joomla/factory.php:99
JError :: raise() @ /home/me/public_html/store/libraries/joomla/error/error.php:251
No clue what they mean.
require() @ /home/me/public_html/includes/test.php:16
error line 16?
Please copy your current code, i cannot know your line 16 content.
But i think you can remove this 2 lines:
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');
and try to load site if it not work using :
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();