How to render custom html in tabs block

Standard

Remove _prepareForm() function from your Tab block and add constructor as shown below

class Company_Module_Block_Adminhtml_CustomSettings_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form
{

    public function __construct()
    {
        $this->setTemplate('MODULE_NAME/customsettings/view.phtml');
    }

}

Create a view.phtml file at design/adminhtml/default/default/template/MODULE_NAME/customsettings

Get custom attribute value in Magento

Standard

Simplest way:

echo $_product->getAttributeText('custom_attribute_code');

Problem:

You will get a fetal error if the attribute is not already registered.

Fatal error: Call to a member function getSource() on a non-object in D:\..\app\code\core\Mage\Catalog\Model\Product.php on line 1389

Solution:

$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute)
{
	echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}

This code will first check if the attribute code exists and gets its value if its there.

Authorize.net integration with Magento

Standard

1- Create a test account on Authorize.net (https://developer.authorize.net/testaccount/)

2- On successful signup you will see following info, save them at safe place.

  1. API Login ID
  2. Transaction Key

3- Login to your Magento Admin panel and navigate to

  1. System -> Configuration -> Payment Methods
  2. Expand Authorize.net
  3. Insert “API Login ID” and “Transaction Key” into this form and make other settings as shown below

authorize.net

6. Save Configuration and you are DONE!

Magento Admin: 404 Error Page not found.

Standard

mag-admin-404Let’s suppose you are logged in to Magento admin panel and you are installing a new extension that adds some new sections to Magento Configurations.
You activate your new extension and it adds some new tabs/sections but when you click on newly added tab you see a 404 error, don’t worry!

Solution :

Just logout from admin panel and login again. Cheers!!!

Get Magento root category id

Standard
public function getRootCategoryId()
{
    $categories = Mage::getModel('catalog/category')->getCollection();
    $categ_ids = $categories->getAllIds();
    asort($categ_ids);
    foreach ($categ_ids as $k => $cat_id)
    {
        $category = Mage::getModel('catalog/category')->load($cat_id);
        if ($category->name)
        {
            return $cat_id;
        }
    }
}

Set Magento website template, skin and layout programmatically

Standard
$groups['theme']['fields']['template']['value'] = 'template_name';
$groups['theme']['fields']['skin']['value'] = 'skin_name';
$groups['theme']['fields']['layout']['value'] = 'layout_name';
$groups['theme']['fields']['default']['value'] = 'template_name';
Mage::getModel('adminhtml/config_data')  
      ->setSection('design')  
      ->setWebsite('your_website')  
      ->setGroups($groups)  
      ->save(); 

Alternate method:

$installer->setConfigData('design/theme/template', 'facebook', 'stores', $store->getId());
$installer->setConfigData('design/theme/skin', 'facebook', 'stores', $store->getId());
$installer->setConfigData('design/theme/layout', 'facebook', 'stores', $store->getId());
$installer->setConfigData('design/theme/default', 'facebook', 'stores', $store->getId());