【问题标题】:add every product as a new item into cart instead of updating quantity将每个产品作为新商品添加到购物车中,而不是更新数量
【发布时间】:2015-10-03 09:48:01
【问题描述】:

我正在使用以下自定义代码为 magento 添加产品到购物车中

$qty=2;
for($i=1;$i<=$qty;$i++){
 $product=Mage::getModel('catalog/product')->load($_REQUEST['productid']);
 $cart = Mage::getModel('checkout/cart');
 $cart->init();
 $cart->addProduct($product,array('qty'=>'1','customvar'=>$_REQUEST['customval']));$cart->save();
 Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
}

我使用 ajax 调用了这段代码,这段代码在购物车中添加了一个数量为 2 的单引号,我想添加两个数量为 1 的引号。我该怎么做?

【问题讨论】:

  • 为什么要修改代码。您可以使用 ajax 购物车而不是编写自己的代码
  • 我需要在需要自定义代码的新页面上找到结果,因此我添加了此代码。上面的代码不可以吗?
  • 尝试 /get 产品 $product = Mage::getModel('catalog/product')->load($pid); //获取项目 $item = $quote->getItemByProduct($product); $quote->getCart()->updateItem(array($item->getId()=>array('qty'=>$qty))); $quote->getCart()->save();
  • $quote 的价值是多少?我使用了 Mage::getModel('sales/quote') 并给出错误“调用非对象上的成员函数 updateItem()”。
  • $quote = Mage::getSingleton('checkout/session')->getQuote();

标签: magento cart


【解决方案1】:

它在 app/code/core/Mage/Sales/model/Quote/Item.php 中扩展函数代表产品($product)后工作。 使用返回 false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    相关资源
    最近更新 更多