Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在joomla框架之外显示购物车总计_Php_Joomla - Fatal编程技术网

Php 在joomla框架之外显示购物车总计

Php 在joomla框架之外显示购物车总计,php,joomla,Php,Joomla,我一直在努力解决这个问题 我的joomla/virtuemart运行在一个名为“store”的目录中,我希望显示joomla框架之外的购物车中的产品总数。因此,我提出了这段代码,它适用于旧版本的virtuemart(products)>0){ 回声“; 打印(购物车); } 否则{ 回声“你的车是空的”; } 该数组包含所有购物车项目的详细信息,只需选择您想要的内容即可 希望有帮助。谢谢,我试过了,但它总是告诉我“你的车空了”。即使是回音sizeof($cart->products)也给出了0

我一直在努力解决这个问题

我的joomla/virtuemart运行在一个名为“store”的目录中,我希望显示joomla框架之外的购物车中的产品总数。因此,我提出了这段代码,它适用于旧版本的virtuemart( 代码(位于名为“includes”的目录中)


错误是:

警告:中为foreach()提供的参数无效 /第20行的home/me/public_html/includes/header.php

0

其中0表示购物车总数,应显示1,因为当时我在购物车中有一个项目

我不是一个php专家,但打开谷歌搜索,在我看来,我的$array不是一个导致问题的数组

这让我很困惑,因为它在旧版本的virtuemart中运行良好

--

根据下面的答案,我正在尝试运行以下程序:

<?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');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);

     if (!class_exists( 'VmConfig' ))
     require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');

     if(!class_exists('VirtueMartCart'))
     require(VMPATH_SITE.DS.'helpers'.DS.'cart.php');
echo sizeof($cart->products);
    ?>

……但没有成功。它不断地说0

试试这个

加载Joomla框架后,只需使用以下代码即可

     defined('DS') or define('DS', DIRECTORY_SEPARATOR);

     if (!class_exists( 'VmConfig' ))
     require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');

     if(!class_exists('VirtueMartCart'))
     require(VMPATH_SITE.DS.'helpers'.DS.'cart.php');

        $cart = VirtueMartCart::getCart();
        if(sizeof($cart->products) > 0){
          echo "<pre/>";
          print_r($cart);
        }
        else{
         echo 'Your cart is empty';
        }
defined('DS')或define('DS',目录分隔符);
如果(!class_存在('VmConfig'))
require(JPATH_ROOT.DS.administrator.DS.components.DS.com\u virtuemart.DS.helpers.DS.config.php));
如果(!class_存在('VirtueMartCart'))
require(VMPATH_SITE.DS.helpers.DS.cart.php');
$cart=VirtueMartCart::getCart();
如果(sizeof($cart->products)>0){
回声“;
打印(购物车);
}
否则{
回声“你的车是空的”;
}
该数组包含所有购物车项目的详细信息,只需选择您想要的内容即可

希望有帮助。

试试这个

加载Joomla框架后,只需使用以下代码即可

     defined('DS') or define('DS', DIRECTORY_SEPARATOR);

     if (!class_exists( 'VmConfig' ))
     require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');

     if(!class_exists('VirtueMartCart'))
     require(VMPATH_SITE.DS.'helpers'.DS.'cart.php');

        $cart = VirtueMartCart::getCart();
        if(sizeof($cart->products) > 0){
          echo "<pre/>";
          print_r($cart);
        }
        else{
         echo 'Your cart is empty';
        }
defined('DS')或define('DS',目录分隔符);
如果(!class_存在('VmConfig'))
require(JPATH_ROOT.DS.administrator.DS.components.DS.com\u virtuemart.DS.helpers.DS.config.php));
如果(!class_存在('VirtueMartCart'))
require(VMPATH_SITE.DS.helpers.DS.cart.php');
$cart=VirtueMartCart::getCart();
如果(sizeof($cart->products)>0){
回声“;
打印(购物车);
}
否则{
回声“你的车是空的”;
}
该数组包含所有购物车项目的详细信息,只需选择您想要的内容即可


希望有帮助。

谢谢,我试过了,但它总是告诉我“你的车空了”。即使是回音
sizeof($cart->products)
也给出了0(当购物车中有项目时。我已经在我的原始问题中提出了我现在尝试运行的内容。好的,检查名为virtuemart cart的模块,它完成了将购物车项目加载到虚拟机组件外部的技巧,您也可以在外部php中使用该代码。谢谢,我尝试过了,但它一直给我“您的购物车是空的”。甚至回显
sizeof。)($cart->products)
给出0(当购物车中有项目时)。我在我的原始问题中提出了我现在尝试运行的内容。确定检查名为virtuemart cart的模块,它完成了将购物车项目加载到虚拟机组件外的技巧。您也可以在外部php中使用该代码。