News:

Support the VirtueMart project and become a member

Main Menu

Weird behaviour from joomla and virtuemart regarding cart data

Started by aqr996, July 15, 2016, 23:17:42 PM

Previous topic - Next topic

aqr996

So I wrote up this code to display the cart total outside of joomla framework:

<?php
// Set flag that this is a parent file

define'_JEXEC');

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'); 
$mainframe->initialise();

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();
$total 0;
foreach (
$data->products as $product){
  
$total += $product[quantity];
}
echo 
$total;

?>

which works fine (by displaying the total items in cart) in a top level directory (/public_html/test.php)

but if I move it to a second-level directory, like (/public_html/includes/test.php), I get this error: first, the code (notice the /../store because we're in a second-level now):

    <?php
// Set flag that this is a parent file

define'_JEXEC');

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'); 
$mainframe->initialise();

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();
$total 0;
foreach (
$data->products as $product){
  
$total += $product[quantity];
}
echo 
$total;

?>

then the error:

Fatal error: Uncaught exception 'Exception' with message 'XML file did not load' in /home/me/public_html/store/libraries/joomla/form/form.php:2020 Stack trace: #0 /home/me/public_html/store/administrator/components/com_virtuemart/plugins/vmplugin.php(201): JForm::getInstance('weight_countrie...', '/home/me/publ...', Array, false, '//vmconfig | //...') #1 /home/me/public_html/store/administrator/components/com_virtuemart/plugins/vmpsplugin.php(45): vmPlugin::getVarsToPushByXML('/home/me/publ...', 'weight_countrie...') #2 /home/me/public_html/store/plugins/vmshipment/weight_countries/weight_countries.php(44): vmPSPlugin->getVarsToPush() #3 /home/me/public_html/store/libraries/joomla/plugin/helper.php(194): plgVmShipmentWeight_countries->__construct(Object(JDispatcher), Array) #4 /home/me/public_html/store/libraries/joomla/plugin/helper.php(125): JPluginHelper::_import(Object(stdClass), true, NULL) #5 /home/me/public_html/store/administrator/components/com_virtuemart/helpe in /home/me/public_html/store/libraries/joomla/form/form.php on line 2020

I have no clue why it works fine in the top level but then not in subdirectories. Any ideas?