简体   繁体   English

Magento如何检查购物车是否为空?

[英]Magento How to check if the shopping cart is empty or not?

I am trying to check if the shopping cart is empty or not. 我正在尝试检查购物车是否为空。 I am trying to do this from a static block and from a phtml file. 我试图从静态块和phtml文件中执行此操作。

Anyone know how to do this? 有人知道怎么做吗?

Thanks in advance 提前致谢

I was able to find the total count of items in the shopping cart using the following code: 我可以使用以下代码找到购物车中的商品总数:

$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount();

If it does not work, let me know. 如果它不起作用,请告诉我。

You can try this. 你可以试试这个。

$cart_qty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

if($cart_qty) {
    // Not empty.
} else {
    // Empty.
}

I think this could help: 我认为这可能会有所帮助:

http://blog.decryptweb.com/empty-cart-magento/ http://blog.decryptweb.com/empty-cart-magento/

You can try something like this: 你可以尝试这样的事情:

$checkout_cart = Mage::getSingleton('checkout/cart');
$items = $checkout_cart->getItems();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM