【问题标题】:show/hide magento cart in wordpress在 wordpress 中显示/隐藏 magento 购物车
【发布时间】:2014-09-10 13:44:53
【问题描述】:

我正在开发一个主要基于 wordpress 但使用 magento 处理其电子商务的网站(不是我的选择,这是网站的设置方式)。

选择产品后,它会链接到 magento 购物车。我们在站点的头部有一个站点范围的“查看购物车”链接,该链接链接到 magento 购物车。如果购物车为空,我想做的是隐藏此链接。

在magento中单独工作我可以用它来隐藏链接:

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

但它不适用于 wordpress...有没有办法将购物车计数从 magento 获取到 wp 中,然后使用类似...

<?php if (sizeof($cart) > 1)) : ?>
<a href="link">link to cart</a>
<?php endif ?>

【问题讨论】:

  • 您的代码是正确的。您是否在 wordpress 的代码中添加了 app/Mage.php 并以 Mage::app() 开头?
  • 我的 php 不是特别先进,法师也不是我以前遇到过的东西。我将如何实现它?

标签: php wordpress magento e-commerce


【解决方案1】:
<?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>';
}

【讨论】:

  • 太好了,谢谢。我遇到的一个问题是,当您将某些内容添加到购物篮时,网站不会加载? (可能是我做错了什么)
猜你喜欢
  • 2013-05-22
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多