doujia7779 2012-08-03 10:19
浏览 34
已采纳

检查OpenCart中是否为空

Is there a global way to check in any .tpl file without making modifications to the controllers and views to see if the basket is empty. This does not always work:

$cartItems = $this->cart->countProducts();
if ($cartItems < 0) {
    print "Your cart is empty"
}

It appears that it works when logged in and sometimes as a guest?

  • 写回答

2条回答 默认 最新

  • douyiavxxh02727 2013-03-28 12:02
    关注

    Much better sollution is just to call

    if ( ! $this->cart->hasProducts()) {
        print "Your cart is empty";
    }
    

    It is much quicker and refers directly to a product count within a cart.

    The method $this->cart->countProducts() does not count the products within a cart, but calculates the total product pieces count within a cart. So it loads all the products in a cart and in a loop adds each product's quantity. Therefore it is slower - not much, You might even not register the difference - but yet it is a little slower (the more products in a cart the more slower it is because of the loop).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题