Follow by Email

Wednesday, September 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();

Tuesday, September 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

Monday, September 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();
}

?>

How to add extra field in review form in magento

I have added 3 extra field in review form
just go to the frontend\base\default\template\review/form.phtml
add three field as other text field.
now go to app\code\core\Mage\Review\Model\Mysql4\Review.php
protected function _afterSave(Mage_Core_Model_Abstract $object)
{

$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), //this field add by sourav
'fname' => $object->getFname(), //this field add by sourav
'lname' => $object->getLname(), //this field add by sourav
);
now add email,fname,lname in the review_detail table in the database
also go to app\code\core\Mage\Adminhtml\Block\Review\Edit\Form.php also add

$fieldset->addField('fname', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));

$fieldset->addField('lname', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('Last Name'),
'required' => true,
'name' => 'lname'
));

$fieldset->addField('email', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));

before
$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));