Friday 21 March 2014

Magento Disable Admin Notification Popup.

Every time you login to Magento Admin panel, by default you will always encounter a notification popup message.
Here is a quick and simple way to remove this notification popup message.


Go to System –> Configuration –> Advanced
 - Disable Mage_AdminNotification module.


Magento: How to Disable / Remove Secret Key from Admin URL?

A new secret key is created every time you login to Magento Admin. This is basically added for security reason.
To Disable secreat key Go :


System -> Configuration -> ADVANCED -> Admin -> Security -> Add Secret Key to URLs And select no.

Thursday 20 March 2014

Magento Add Country and State Dropdown in Magento admin Form.

When you have no states for pirticular country the it show a textbox in textbox you can add state name for country.

Open your form which is in Yournamespace/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php then add below fields

$country = $fieldset->addField('country', 'select', array(
    'name' => 'country',
    'label' => 'Country',
    'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
    'onchange' => 'getstate(this)',
    'class' => 'required-entry',
    'required' => true,
        ));

if (Mage::registry('modulename_data')->getData('state')) {
    $fieldset->addField('state', 'text', array(
        'name' => 'state',
        'label' => 'State',
        'class' => 'required-entry',
        'required' => false,
    ));
} else {
    $statevalues = '';
    if (Mage::registry('modulename_data')->getData('store_image')) {
        $regionModel = Mage::getModel('directory/region')->load(Mage::registry('modulename_data')->getData('store_image'));
        $region = $regionModel->getName();
        $statevalues = array(Mage::registry('modulename_data')->getData('store_image') => $region);
    }

    $fieldset->addField('state', 'select', array(
        'name' => 'state',
        'label' => 'State',
        'value' => Mage::registry('modulename_data')->getData('region_id'),
        'values' => $statevalues,
        'required' => false,
    ));
}

$country->setAfterElementHtml("<script type=\"text/javascript\">
            function getstate(selectElement){
                var reloadurl = '" . $this
                ->getUrl('modulename/adminhtml_modulename/state') . "country/' + selectElement.value;
                new Ajax.Request(reloadurl, {
                    method: 'get',
                    onLoading: function (stateform) {
                        $('state').update('Searching...');
                    },
                    onComplete: function(stateform) {
                        $('state').replace(stateform.responseText);
                    }
                });
            }
    </script>");

Now Create State Action in modulenamecontroller.php file which will be like this

public function stateAction() {
    $countrycode = $this->getRequest()->getParam('country');
    if ($countrycode != '') {
        $statearray = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($countrycode)->load();
        $state = "<select class='select' name='state' id='state' class='required-entry validate-select'><option value=''>Please Select</option>";
        foreach ($statearray as $_state) {
            $state .= "<option value='" . $_state->getDefaultName() . "'>" . $_state->getDefaultName() . "</option>";
            $yes = 1;
        }
        $state .= "</select>";
    }
}

Wednesday 19 March 2014

Magento Get From Post Data in Controller

Add following code in your controller action.

$PostData = Mage::app()->getRequest()->getPost();

Magento Get Logged In Customer’s Detail

Add this code any file.

if (Mage::getSingleton('customer/session')->isLoggedIn()) {

    $CustomerDetail = Mage::getSingleton('customer/session')->getCustomer();

    $FullName = $CustomerDetail->getName();

    $FirstName = $CustomerDetail->getFirstname();

    $LastName = $CustomerDetail->getLastname();

    $Email = $CustomerDetail->getEmail();

}

Tuesday 18 March 2014

Magento Change E-mail Subject For Order Confirmations in Locale.

To change these, go to the relevant e-mail template at:
app/locale//template/email/sales


and find the commented out @subject at the top of the e-mail and change this to whatever you want.