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)
                          );
   }

Form field validation in magento


Magento uses Prototype as javascript library.  It provides a simple way to validate html form values.
Below is an example:
<form name=”my-form” id=”my-form” method=”post”>
<label for=”firstname”>
< ?php echo $this->__(‘First name’) ?> <span>*</span></label><br />
<input  id=”firstname” name=”firstname” class="input-text required-entry"/>

<label for=”lastname”>
< ?php echo $this->__(‘Last name’) ?> <span>*</span></label><br />
<input  id=”lastname” name=”lastname” class="input-text required-entry"/>

</form>
<script type=”text/javascript”>
//< ![CDATA[
var customForm = new VarienForm('my-form');
//]]>
</script>

In the form above you can see each input field has its own class name and these classes will be used to validate field’s value. There are many predefined classes like that in prototype lib. I’ll show you all of them at the end of this topic.
Most important thing besides assigning class names is that little piece of JavaScript below the form. Remember to pass form id into the new VarienForm object.
Basically, that’s it. Constructing the form this way, automatically makes your form reuse already existing validation code which is being used by the rest of the shop.
Below is a full list of validate class and its error message that I found in prototype lib.
  • validate-select
Please select an option.
  • required-entry
This is a required field.
  • validate-number
Please enter a valid number in this field.
  • validate-digits
Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.
  • validate-alpha
Please use letters only (a-z or A-Z) in this field.
  • validate-code
Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
  • validate-alphanum
Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.
  • validate-street
Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.
  • validate-phoneStrict
Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.
  • validate-phoneLax
Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.
  • validate-fax
Please enter a valid fax number. For example (123) 456-7890 or 123-456-7890.
  • validate-date
Please enter a valid date.
  • validate-email
Please enter a valid email address. For example johndoe@domain.com.
  • validate-emailSender
Please use only letters (a-z or A-Z), numbers (0-9) , underscore(_) or spaces in this field.
  • validate-password
Please enter 6 or more characters. Leading or trailing spaces will be ignored.
  • validate-admin-password
Please enter 7 or more characters. Password should contain both numeric and alphabetic characters.
  • validate-cpassword
lease make sure your passwords match.
  • validate-url
Please enter a valid URL. http:// is required
  • validate-clean-url
Please enter a valid URL. For example http://www.example.com or www.example.com
  • validate-identifier
Please enter a valid Identifier. For example example-page, example-page.html or anotherlevel/example-page
  • validate-xml-identifier
Please enter a valid XML-identifier. For example something_1, block5, id-4
  • validate-ssn
Please enter a valid social security number. For example 123-45-6789.
  • validate-zip
Please enter a valid zip code. For example 90602 or 90602-1234.
  • validate-date-au
Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.
  • validate-currency-dollar
Please enter a valid $ amount. For example $100.00.
  • validate-one-required
Please select one of the above options.
  • validate-one-required-by-name
Please select one of the options.
  • validate-not-negative-number
Please enter a valid number in this field.
  • validate-state
Please select State/Province.
  • validate-new-password
Please enter 6 or more characters. Leading or trailing spaces will be ignored.
  • validate-greater-than-zero
Please enter a number greater than 0 in this field.
  • validate-zero-or-greater
Please enter a number 0 or greater in this field.
  • validate-cc-number
Please enter a valid credit card number.
  • validate-cc-type
Credit card number doesn\’t match credit card type
  • validate-cc-type-select
Card type doesn\’t match credit card number
  • validate-cc-exp
Incorrect credit card expiration date
  • validate-cc-cvn
Please enter a valid credit card verification number.
  • validate-data
Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
  • validate-css-length
Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%
  • validate-length
Maximum length exceeded.

Get URL in magento

Current Page url :
$this->helper('core/url')->getCurrentUrl()

Skin url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Mage::getBaseUrl('skin');
//returned value: http://www.mymagento.com/skin/

Path to skin dir :
$this->getSkinUrl('images/mymage.jpg')


Media url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Mage::getBaseUrl('media');
//returned value: http://www.mymagento.com/media/

Js url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
Mage::getBaseUrl('js');
//returned value: http://www.mymagento.com/js/

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Mage::getBaseUrl('web');
//returned value: http://www.mymagento.com/

Current Page Title :
Mage::getSingleton('cms/page')->getTitle();

Tuesday 14 June 2011

Magento delete order Script

Php script for delete particular status order from admin in magento


require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
->setPageSize(5000)
->addFieldToFilter('status', 'closed')->load();

foreach ($collection as $col) {
Mage::log($col->getIncrementId() . ' order deleted ');
try {
$col->delete();
} catch (Exception $e) {
throw $e;
}
}

change the status for whatever order you want to delete.. eg. if you want to delete 'closed' order than in addFieldToFilter status write 'closed' for complete 'completed' so on..

First Blog

This is my First Blog....