magento更新购物车产品数量
时间:2014-06-21 13:13来源:未知 作者:最模板zuimoban 点击:
次
1、向购物车中添加产品 [php] view plaincopy $params = array (); $product =Mage::getModel( catalog/product )-load( $productid ); $params [ qty ]=1; $cart =Mage::getSingleton( checkout/cart ); $cart -addProduct( $product , $params );
1、向购物车中添加产品
-
$params = array();
-
$product = Mage::getModel('catalog/product')->load($productid);
-
$params['qty'] = 1;
-
$cart = Mage::getSingleton('checkout/cart');
-
$cart->addProduct($product, $params);
-
$cart->save();
-
$success = 'DIY定制图片已经成功加入购物车!';
-
$cart->getCheckoutSession()->addNotice($success);
2、更新购物车中产品的数量和删除购物车中的产品
-
$cart = Mage::getSingleton('checkout/cart');
-
$items = $cart->getItems();
-
$data = $items->getData();
-
foreach($data as $key=>$v){
-
if($v['product_id'] == $productid){
-
$item_id = $v['item_id'];
-
$qty = $v['qty'];
-
}
-
}
-
$params['options'] = array();
-
$params['qty'] = $qty - 1;
-
if($params['qty']){
-
$cart->updateItem($item_id, new Varien_Object($params));
-
}else{
-
$cart->removeItem($item_id);
-
}
-
$cart->save();
-
(责任编辑:最模板) |
------分隔线----------------------------