Magento add custom block to product page

Depend upon the position where we would like to insert your custom block you can insert your custom block.

Below is xml to insert custom block into product page

<catalog_product_view>
            <reference name="product.info.extrahint">
                <block type="tag/product_list" name="product_tag_list" before="-" template="tag/list.phtml"/>
            </reference>


            <reference name="product.info">
                <block type="catalog/product_list_related" before="-"  name="catalog.product.related" as="related_products" template="catalog/product/list/related.phtml" >
                        <action method="addToParentGroup"><group>detailed_info</group></action>
                </block>
                    </reference>
    </catalog_product_view>

Magento add attachment to email

Hello All,
I have found working code to send email with attachment.

$attachmentFilePath = Mage::getBaseDir('media'). DS.$filpath; //filepath is path of file inside media directory
$mailTemplate = Mage::getModel('core/email_template');
if(file_exists($attachmentFilePath)){ 
                    $fileContents = file_get_contents($attachmentFilePath);
                    $attachment   = $mailTemplate->getMail()->createAttachment($fileContents,Zend_Mime::TYPE_OCTETSTREAM,Zend_Mime::DISPOSITION_ATTACHMENT,Zend_Mime::ENCODING_BASE64,basename($attachmentFilePath));
              
                }

$postObject = new Varien_Object();
//Below code require you understandtsthe term used
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        $template_id,  //template id of email template
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
    );

Magento add translation file for custom module

In order to add custom translation we need to put translation file in location app\locale\en_US\Filename.csv

en_US is translation directory for english

For Admin
——————-
<adminhtml>

<translate>
<modules>
<modulename>
<files>
<default>Namespace_Module.csv</default>
</files>
</modulename>
</modules>
</translate>
</adminhtml>

For Frontend
<frontend>

<translate>
<modules>
<modulename>
<files>
<default>Namespace_Module.csv</default>
</files>
</modulename>
</modules>
</translate>
</frontend>

NB: You need to place this in config.xml

Thanks

Magento create admin user programmatically

Hello all,

Here is custom script to create admin user programmatically.

<?php
# Create New admin User programmatically.
require_once(‘./app/Mage.php’);
umask(0);
Mage::app();

try {
$user = Mage::getModel(‘admin/user’)
->setData(array(
‘username’  => ‘admin1’,
‘firstname’ => ‘Admin’,
‘lastname’    => ‘Admin’,
’email’     => ‘santosh@test.com’,
‘password’  =>’admin123′,
‘is_active’ => 1
))->save();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

//Assign Role Id
try {
$user->setRoleIds(array(1))  //Administrator role id is 1 ,Here you can assign other roles ids
->setRoleUserId($user->getUserId())
->saveRelations();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

echo “User created successfully”;

?>

Put the above content in a magento root folder in a file and  then browse the file.

You are done with creating new admin user.

Chears