Wednesday 17 August 2011

How to disable / remove Secret Key from Admin URL in Magento?


A new secret key is created every time you login to Magento Admin. So, there will be a unique key (32 chars long) for each session of your Magento admin login. This key is appended to the admin URL as http://your-admin-url/key/743c37b1…adf6588/


This is basically added for security reason. In their release note, Magento say that they added secret key to URL for CSRF (Cross-site request forgery) Attack Prevention.


Sometime you may want to access admin URL without the secret key. For this, you can disable the secret key from admin URL.

Here is how you do it:-

- Login to admin
- Go to System -> Configuration -> ADVANCED -> Admin -> Security -> Add Secret Key to URLs
- Select No
- Save Config

You are done. You will not see the secret key in admin URL nowonwards.

Hope this helps.

Magento: How to change Admin URL Path?

Here is a quick guide on how to change admin url path in Magento. This need to be done for security reason to be safe from hacking/cracking issue. Basically, this is done not to let any general user to access the admin page.

Generally, we do have ‘admin‘ as the administrator path for Magento. So, the admin URL will be http://www.example.com/admin/

This article will show you, how you can change the admin url. Let’s say from ‘admin‘ to ‘backend‘. So, the new admin URL will be http://www.example.com/backend/
Here is how we do it:-

- Open app/etc/local.xml
- Find the following:-

<admin>
 <routers>
  <adminhtml>
   <args>
     <frontName><![CDATA[admin]]></frontName>
   </args>
  </adminhtml>
 </routers>
</admin>

- Change

<frontName><![CDATA[admin]]></frontName>
to your desired name. Like below:-
<frontName><![CDATA[backend]]></frontName>

- Save the file
- Refresh the Cache from Magento Admin (System -> Cache Management)

Now, you should be able to access admin panel from http://www.example.com/backend/ instead of http://www.example.com/admin/

Magento: Disable Admin Notification Popup

Every time you login to Magento Admin panel, by default you will always encounter a notification popup message. If you not want to Pop-up when Login in Admin than simply do
 - Login to admin panel
- Go to System –> Configuration –> Advanced
- Disable Mage_AdminNotification module.
You are done :) 

Saturday 9 July 2011

how to get store information in magento?

Use below code for get store data :
Get store data
 
Mage::app()->getStore();
 
Store Id
 
Mage::app()->getStore()->getStoreId();
 
Store code
 
Mage::app()->getStore()->getCode();
 
Website Id
 
Mage::app()->getStore()->getWebsiteId();
 
Store Name
 
Mage::app()->getStore()->getName();
 
Is Active
 
Mage::app()->getStore()->getIsActive();
 
Store Home Url
 
Mage::app()->getStore()->getHomeUrl();

Friday 8 July 2011

How to export Categories with Ids in Magento?

Using the following given quick PHP script you can export categories with Ids in Magento.You just need to save te below given code in a PHP file “CatList.php” in the base Magento directory of your store, and visit the URL in your web browser.

<?php
 
 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 Mage::app();
 
 $category = Mage::getModel ( 'catalog/category' );
 $tree = $category->getTreeModel ();
 $tree->load ();
 
 $ids = $tree->getCollection ()->getAllIds ();
 
 if ($ids) {
  $file = "var/import/catlist.csv";
  file_put_contents($file,"catId, catName\n");
  foreach ( $ids as $id ) {
    $string = $id . ', ' .$category->load($id)->getName() . "\n";
   file_put_contents($file,$string,FILE_APPEND);
  }
 }
?>

You can run this script as http://www.domain.com/CatList.php. You can find the csv file in the var/import/ directory.

Monday 27 June 2011

Download link in product list page to download downloadable product in magento


Download link in list page to download downloadable product direct :

<?php
$_myprodlinks = Mage::getModel('downloadable/link');
$_myLinksCollection = $_myprodlinks->getCollection()->addProductToFilter($_product->getId());
if (sizeof($_myLinksCollection)>0):
foreach ($_myLinksCollection as $_link):
$mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$_linkpath = $mediaUrl."downloadable/files/links".$_link->getLinkFile();
?>
    <a href="<?php echo $_linkpath ?>" target="_blank"><?php echo $this->__('Download') ?></a>
<?php
 endforeach;
endif;
?>
put this code in list.phtm (app/design/frontend/yourtheme/yourtheme/template/catalog/product) page where you want to 'Download' link.
Please make sure that your media dir have 777 permision

Confirm Email Address in onepage checkout in magento


Add one tax box in billing.phtml (app/design/frontend/ yourtheme/ yourtheme/template/checkout/onepage/billing.phl)
Ex : After email address Texbox add this :

<label for="billing:confirm_email" class="required"><em>*</em><?php echo $this->__('Re-Type Email Address') ?></label>
            <div class="input-box">
<input type="text" name="billing[confirm_email]" id="billing:confirm_email" value="<?php  $conf=$this->htmlEscape($this->getAddress()->getEmail()); echo $conf; ?>" onchange="abc(this.value)" title="<?php echo $this->__('Re-Type Email Address') ?>" class="input-text validate-email required-entry"  />
             </div>
  Then go to the onepage.php(code/core/Mage/Checkout/Model/Type)
In onepage.php do the following  change in function:


protected function _processValidateCustomer(Mage_Sales_Model_Quote_Address $address)
foreach (array( 
                         'firstname'    => 'firstname',
                         'lastname'     => 'lastname',

                        'email'        => 'email',
                        'confirm_email' => 'confirm_email',
                        'password'     => 'customer_password',
                        'confirmation' => 'confirm_password',
                        'taxvat'       => 'taxvat',
                        'gender'       => 'gender', )

 In elseif(self::METHOD_GUEST == $this->getQuote()->getCheckoutMethod())

  $email = $address->getData('email');
  $c_email=$address->getData('confirm_email');
           
  if($c_email != $email)
  {
        return array(
                              'error'   => -1,
                              'message' => $this->_helper->__('Not match email address "%s"', $c_email)
                           );
   }
                       
   if (!Zend_Validate::is($email, 'EmailAddress'))
  {
       return array(
                            'error'   => -1,
                            'message' => $this->_helper->__('Invalid email address "%s"', $email)
                          );
   }