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();

Database server does not support the InnoDB storage engine when i install magento


location : app\code\core\Mage\Install\Model\Installer\Db\Mysql4.php

Replace below code
 public function supportEngine()
    {
        $variables  = $this->_getConnection()
            ->fetchPairs('SHOW VARIABLES');
        return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true;
    }

 To  this code
public function supportEngine()
{
$variables  = $this->_getConnection()
->fetchPairs('SHOW ENGINES');
return (isset($variables['InnoDB']) && $variables['InnoDB'] != 'NO');
}

add custom options programmatic

 $proAdd=Mage::getModel('catalog/product')->load($productId);
 $options = array(
array(
'is_delete' => 0,
'title' => 'First Line',
'type' => 'text',
'is_require' => 0,
'sort_order' => 1,
'pric' => 0.00,
'price_type' => 'fixed',
'sku' => '',

),

);

$proAdd = Mage::getModel('catalog/product')->load($productId);
$optionInstance = $proAdd->getOptionInstance();

foreach($options as $option){

$proAdd->setHasOptions(1);

if (isset($option['is_require']) && ($option['is_require'] == 1)) {
$proAdd->setRequiredOptions(1);
}

$optionInstance->addOption($option);
$optionInstance->setProduct($proAdd);
$proAdd->save();
}

custom magento massage


$urld='your custom url';
 Mage::getSingleton('core/session')->addSuccess("Your request for product was Deactivate");
Mage::app()->getFrontController()->getResponse()->setRedirect($urld);