magento pincode number digit validation

<input type="text" maxlength="6" placeholder="Zip/Postal Code*" class="input-text required-entry validate-length maximum-length-6 minimum-length-6 validate-digits" value="" id="billing:postcode" name="billing[postcode]" title="Pincode">

if you want to use any number of integer validation on input filed use this 2 syntax.
maxlength=”6″
class=”input-text required-entry validate-length maximum-length-6 minimum-length-6 validate-digits”

10 digit mobile number validation in magento

 <input type="text" maxlength="10" name="mobile" id="mobile" placeholder="Mobile"  title="<?php echo $this->__('Mobile') ?>" class="input-text required-entry validate-length maximum-length-10 minimum-length-10 validate-digits" />

if you want to use any number of integer validation on input filed use this 2 syntax.
maxlength=”10″
class=”input-text required-entry validate-length maximum-length-10 minimum-length-10 validate-digits”

how to check product is a simple product

We can check 2 ways if a product is a simple product and does not a child of any configurable product

Way-1:-

$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($productId);

if (!count($parentIds)) {
// Product is Simple product
}

It return the product parent Ids. if it does not return any parent product ids that means the product is Simple product.

Way-2:- Check by product Attribute set Id.

$sPro = Mage::getModel('catalog/product')->load($productId);

$attributeSetName = Mage::getModel("eav/entity_attribute_set")
->load($sPro->getAttributeSetId())
->getAttributeSetName();

if($attributeSetName=='Default' && $sPro->getTypeId()=='simple') {
      echo "simple product";
}

The Way-1 is fastest then Way-2.

magento display category image

<?php 
    $parentCategoryId = 204; // Category Id

    $cat = Mage::getModel('catalog/category')->load($parentCategoryId);
    $subcats = $cat->getChildren();

    foreach (explode(',', $subcats) as $subCatid) {
        $_category = Mage::getModel('catalog/category')->load($subCatid);

        if ($_category->getIsActive()) {         
        if($_category->getThumbnail()):
 ?>
    <a href="<?php echo $_category->getURL(); ?>" title="<?php echo $_category->getName(); ?>">
    <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'. $_category->getThumbnail(); ?>" alt=""  />
    </a>
<?php endif; ?> 

<?php } 
 } 
?>

Add extra field on customer address backend in magento

Step1: Create a file addCustomerColumn.php file in root directory
and put the below content in that file.


<?php

require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
 
$installer->addAttribute('customer_address', 'extra_field', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Extra Field',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'extra_field')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
$installer->endSetup();

?>

Note: Change Extra filed name to your desire custom name.

Step2: Now run this file on your browser.

Step3: Clear your project cache.