【问题标题】:Accessing magento's checkout/cart using REST API使用 REST API 访问 magento 的结帐/购物车
【发布时间】:2012-10-07 11:15:30
【问题描述】:

我正在尝试为我的其他客户集成购物车同步解决方案。 目标应该是无论我从哪里访问我的商店,我都可以拥有相同的购物车。

所以我必须首先使用经过身份验证的 api-user 将现有项目交付给客户端。

但我一开始就卡住了:

protected function _retrieveCollection()
{
    $cart = Mage::getSingleton('checkout/cart')->getQuote();
    $cart->setCustomerId($this->getApiUser()->getUserId());
    $cart->setStoreId(4);
    $cart->load();

    return $cart->getAllItems();
}

即使我的购物车中有产品,也会返回一个空数组。

任何人有任何提示吗?有那种感觉我完全站在错误的一边......

【问题讨论】:

  • 是否可以使用 REST 结账?因为我问了一个关于 SO 上的 REST 的问题,我得到的答案是我们无法使用 REST 访问结帐和其他东西!
  • @vsvankhede 他正在开发其他未使用的 api。

标签: api rest checkout magento-1.7


【解决方案1】:

找到了解决办法。反之,得到客户的报价效果很好:

Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
    $items[] = array(
        'name'                  => $item->getName(),
        'entity_id'             => $item->getProductId(),
        'description'           => $item->getDescription(),
        'final_price_with_tax'  => $item->getBasePriceInclTax(),
        'qty'                   => $item->getQty()
    );

}

【讨论】:

  • axel 你的答案是正确的,而且工作起来很迷人,但是当我尝试在函数结束时返回 $items 时,它只显示每个项目的“数量”,但在 echo 的情况下它会显示所有。我想要这个的 json 响应,但由于返回而被卡在这里。
猜你喜欢
  • 2011-04-20
  • 2014-11-09
  • 1970-01-01
  • 2014-03-06
  • 2014-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多