简体   繁体   English

在wordpress中显示/隐藏magento购物车

[英]show/hide magento cart in wordpress

I'm working on a site which is primarily based on wordpress but uses magento to deal with its e-commerce (not my choice, it's how the site is setup). 我正在一个主要基于wordpress但使用magento处理其电子商务的网站上(不是我的选择,这是该网站的设置方式)。

When a product is selected, it links through to the magento shopping cart. 选择产品后,它会链接到magento购物车。 We have a site wide "View Cart" link in the head of the site which links to the magento cart. 我们在网站的顶部有一个站点范围的“查看购物车”链接,该链接链接到magento购物车。 What I'd like to do is to hide this link if the cart is empty. 我想做的就是在购物车为空时隐藏此链接。

Working soley in magento I could use this to hide the link: 在magento工作soley,我可以使用它来隐藏链接:

<?php $_cartQty = $this->getSummaryCount() ?>
<?php if ($_cartQty >0): ?>
<a href="link">link to cart</a>
<?php endif ?>

but it doesn't work for wordpress... Is there a way to get the cart count from magento into wp to then use something along the lines of... 但是它不适用于wordpress ...是否有办法将购物车数量从magento转换为wp,然后再沿...使用

<?php if (sizeof($cart) > 1)) : ?>
<a href="link">link to cart</a>
<?php endif ?>
<?php
require_once '../app/Mage.php'; //root to app/Mage.php of magento
Mage::app(); //run
Mage::getSingleton('core/session', array('name'=>'frontend')); //load session
$count = Mage::helper('checkout/cart')->getSummaryCount(); //read count itemes in cart
$total = Mage::helper('checkout/cart')->getQuote()->getGrandTotal(); //read total in cart
if($count==0){
    echo '<a href="'.Mage::getBaseUrl("web").'checkout/cart">Cart is empty</a>';
}
else {
    echo '<a href="'.Mage::getBaseUrl("web").'checkout/cart">'.$count.' item(s) with total '.Mage::helper('core')->formatPrice($total, false).'</a>';
}

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

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