【问题标题】:How to get all products in cart in virtuemart?如何在德德玛特的购物车中获取所有产品?
【发布时间】:2012-12-05 10:59:44
【问题描述】:

我是 Joomla 和 Virtuemart 的新手。 我想获取/显示购物车中的所有产品(产品 ID、产品图片、产品数量),我在模板文件夹中的 index.php 中插入一些代码,如下所示:

foreach( $this->cart->products as $pkey =>$prow ) {
...                     
}

但是在线foreach出错了,任何人都可以帮助我 我使用 Joomla 2.5 和 Virtuemart 2

谢谢

【问题讨论】:

    标签: joomla virtuemart


    【解决方案1】:

    如果你试图将上面的代码直接包含在 index.php 中肯定会出错。 因为这里引用的 this 指针是 Cart 助手。这在 index.php 中是未知的。

    如果您想在 index.php 中插入一些购物车功能,最好的方法是使用该模块。 您可以在 public_html/modules/mod_cartinfo 中找到一些类似于 mod_cartinfo 的模块(此模块将返回购物车项目的详细信息。)

    您可以找到模块主文件加载了一些虚拟机购物车详细信息所需的 php 文件。

    if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'vmmodel.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);
    

    然后使用 $cart 代替 this->cart。

    不要试图在你的 index.php 中包含这个代码部分。它每次都会加载。 使用模块概念来实现这一点。try this

    希望对你有所帮助..

    【讨论】:

    • 谢谢,我会尝试,但是如何直接在 index.php 中查看购物车中的产品 ID,因为我在此修改了许多代码:(
    • 只需调用 $prow->virtuemart_product_id 。只需打印产品数组,如 echo "
      ";print_r($this->cart->products);您将获得与产品相关的所有信息
    • 糟糕,我的网站没有 mod_cartinfoasdf
    • 哦,非常感谢,我在我的网站上没有找到获取product_id的代码(我只找到了产品图片,产品数量......),我会试试你的代码。
    • 太棒了!我成功获得所有产品,非常感谢您的帮助
    猜你喜欢
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    相关资源
    最近更新 更多