Showing posts with label add. Show all posts
Showing posts with label add. Show all posts

Tuesday, September 20, 2011

How to Add a custom State / Province / Region to a Country in magento?

If you need to add a custom State / Province / Region to a Country in Magento, you’ll need to modify the database manually as there currently isn’t a means to do this from within the Magento admin. Fortunately it’s pretty simple – there are 2 tables involved: directory_country_region and directory_country_region_name.

Adding a record to directory_country_region for a specified country_id will make that new entry show up in the State/Province drop box on the address forms. It will also make that a required field, so you need to make sure you add all the possible options.

You then need to add a corresponding record to directory_country_region_name, using the region_id generated when you inserted into directory_country_region. This entry will make the new region show up when a whole address is displayed on the screen or email, e.g. in an order summary.

Example: Add Tamil Nadu to India

So let’s say that like me, you live in India and want to add 2 regions: Tamil Nadu and Kerala. The country id for India is IN, the region code is a unique identifier so I’m going with Tamil Nadu and at the moment I’m only interested in the en_US locale.

First I will insert Tamil Nadu into directory_country_region as follows:
INSERT INTO `directory_country_region`
(`region_id`,`country_id`,`code`,`default_name`)
VALUES (NULL,'IN','TAMIL','Tamil Nadu');
Note the NULL entry for the region_id field which will auto_increment. I need to find out this new region_id for my next insert so I can either browse the table manually, or this query will do the trick:
SELECT * FROM `directory_country_region`
WHERE `country_id`='IN' AND`code`='TAMIL' AND `default_name`='Tamil Nadu';
In my case, the new region_id is 485, so with that I’ll now insert into directory_country_region_name as follows:
INSERT INTO `directory_country_region_name`
(`locale`,`region_id`,`name`)
VALUES ('en_US','485','Tamil Nadu');
Now I just repeat those steps for Kerala and I’m all set.

How to add CSS and JS files in magento header?

Open your page.xml file and add the below lines
skin_csscss/YOURCSSFILENAME.css
skin_jsjs/YOURJSFILENAME.js
Refresh your cache. Thats it. You are done.

Monday, September 19, 2011

How to add category and manufacturer dropdown to the magento default search?

Here is the code to add category and manufacturer / brand dropdown to the magento default search. Just replace your "template/catalogsearch/form.mini.phtml" with the below code.
<?php
$category = Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
    $current_category_path=Mage::registry('current_category')->getPathIds();
}else{
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
foreach($children as $c){
    $selected = (in_array($c, $current_category_path))?'SELECTED':'';
    $extra_options.= '<option $selected . value="' . $c . '" ' . '>' . htmlspecialchars($category->load($c)->getName()) . '</option>' . "\n";
}
?>

<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
   <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <div class="mini-search">
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
            <select name="cat">
            <option value="">Select Category</option>
            <?= $extra_options ?>
           </select>    
           <?php $product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);?>
 <select name="manufacturer" id="manufacturer" class="" title="Manufacturer" >
          <?php foreach ($manufacturers as $manufacturer): ?>
            <option value="<?php echo $manufacturer['value'] ?>"><?php echo $manufacturer['label'] ?></option>
   <?php endforeach; ?>
       </select>
           <input type="submit" value="Go" style="border: 1px solid #808080;" alt="<?php echo $this->__('Search') ?>" />
            <div id="search_autocomplete" class="search-autocomplete"></div>
           <script type="text/javascript">
            //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search Entire Site...') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
            //]]>
            </script>
        </div>
    </fieldset>
</form>  

Tuesday, September 13, 2011

How to Add CMS page link to top links or footer links in Magento?

Use "<prepare>true</prepare>" to get correct url path.
customer-serviceCustomer Servicetrue1000

Thursday, September 8, 2011

How to Add Confirmation email field in magento registration form using class validate-cemail?

The following method allows you to add confirmation email address field in your customer registration or newsletter page.
Create a javascript file called validation.js under "js/email/validation.js"
Validation.addAllThese([

    ['validate-cemail', 'Please make sure your emails match.', function(v) {
                var conf = $('confirmation') ? $('confirmation') : $$('.validate-cemail')[0];
                var pass = false;
  var confirm;
                if ($('email')) {
                    pass = $('email');
                }
  confirm =conf.value;
  if(!confirm && $('email2'))
  {
  confirm = $('email2').value;
  }
                return (pass.value == confirm);
            }],
]); 
Add the new js file into your customer.xml file

    
 
On the register form add a new field to contain the email confirmation field "template/customer/form/register.phtml".

Thats all. You are done.

Wednesday, September 7, 2011

How to add address field in magento customer registration form?

If you want to add address details in your form you are in luck. Those fields are already setup in the "template/customer/form/register.phtml" file, but they are disabled by an inactive if statement that so far has not actually been linked to anything else in Magento. Therefore to enable the address related fields you simply need to comment out or delete the following statements:

<?php if($this->getShowAddressFields()): ?>

and

<?php endif; ?>

Note that there are two occurrences of this if statement. One is around the area where the customer actually inputs their data  and the second statement is bottom of the file around some JavaScript code that sets up the State/Province select.