Magento Coding Solutions

change cart price Programmatically in magento

 foreach($this->getQuote()->getAllItems() as $item) {

 $productId = $item->getProductId();
 $product = Mage::getModel('catalog/product')->load($productId);
 //if($product->getAttributeText('is_dummy') == 'Yes') {
$price = 2;
$item->setCustomPrice($price);
// we need this since Magento 1.4
$item->setOriginalCustomPrice($price);

// }
}
$this->getQuote()->save();


or

$cartObj= Mage::getModel('checkout/cart')->getQuote();
foreach($cartObj->getAllItems() as $item) {
//echo "CART ID:".$item->getId();
// echo $productId = $item->getProductId();
 $product = Mage::getModel('catalog/product')->load($productId);
 //  if($item->getId()== 2) {
$price = 20;
$item->setCustomPrice($price);
// we need this since Magento 1.4
$item->setOriginalCustomPrice($price);

     // }
}
$cartObj->save();

No comments:

Post a Comment