11/11/2011

Delete all product from cart

I have add a function in the app\code\core\Mage\Checkout\controllers\CartController.php


if you call this it will delete all item in the cart.


the url should be http://www.yoursite.com/index.php/checkout/cart/deleteall/


public function deleteallAction()
    
{
        $cartHelper 
Mage::helper('checkout/cart');
        
$items $cartHelper->getCart()->getItems();       
        foreach (
$items as $item)
        
{
                $itemId 
$item->getItemId();
                
$cartHelper->getCart()->removeItem($itemId)->save();
        
}
        $this
->_redirectReferer(Mage::getUrl('*/*'));
    
}

11/09/2011

Get all product name

foreach(Mage::getModel(‘catalog/product’)->getCollection()->getData() as $product)
{
echo Mage::getModel(‘catalog/product’)->load($product['entity_id'])->getName();
}

10/29/2011

Magento order id Increment

I had a problem that when i insert old order in to my new magento site it showing in the admin but when new order come then order id make some problem. like i had 185 order which order id was 100000421 and when new order comes then order id become 100000024.
That was a problem to me. then i go to the database find the table "eav_entity_store" and change increment_last_id in to 100000422. after doing that new order come with order id 100000422.

10/25/2011

If you’re working with Magento Commerce you’ll most likely want to remove index.php from the URL when you go live

go to :
1) System
2) Configuration
3) Web:
secure:
Use secure URL Frontend: YES

4) edit:
http://mysite.com/.htaccess

############################################
## you can put here your magento root folder
## path relative to web root

RewriteBase /

9/28/2011

How to get product image in magento

If you have the product collection object like
$collection = Mage::getModel('catalog/product')->getCollection();

Now you can get product sku using $_product->getSku()
if you can't get image path with
echo $this->helper('catalog/image')->init($_product,'small_image')->resize(135);
or $_product->getImageUrl()

then you can add a little code
$model = Mage::getModel('catalog/product');
$prod = $model->loadByAttribute('sku', $_product->getSku());
Now you can get product url with this
$prod->getImageUrl();

9/13/2011

Send mail from magento

$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format
$mail->send();
?>

also you can use

$emailTemplate  = Mage::getModel('core/email_template')->load(1);   //1 is Transactional Emails id
$emailTemplate->setSenderEmail('sapnandu@gmail.com');
$emailTemplate->setSenderName('Sapnandu');
$emailTemplate->send('sourav.m@gsl.in','John', '');

look on
http://stackoverflow.com/questions/5595202/sending-e-mail-programmatically-in-magento-is-failing

9/12/2011

How to add Product review in product page

$storeId = Mage::app()->getStore()->getId();

$summaryData = Mage::getModel('review/review')->getCollection()->addStoreFilter($storeId)->addStatusFilter('approved')->addEntityFilter('product', $_product->getId())->setDateOrder();
foreach ($summaryData as $_review){
echo $_review->getTitle(). ' Review by '.$_review->getNickname().'
'.$_review->getDetail();
}

?>