Wednesday 19 June 2013

How to remove last name validation when create account in magento


1.Remove last name from:  app\design\frontend\default\default\template\persistent\checkout\onepage

\billing.phtml

2.now Comment validation from /mage/customer/model/customer.php
find function function validate() and comment below code
if (!Zend_Validate::is($this->getTelephone(), \\\’NotEmpty\\\’)) {
          $errors[] = Mage::helper(\\\’customer\\\’)->__(\\\’Please enter the telephone number.\\\’);
       }

same as above in file /mage/customer/model/Address/abstract.php file

3.now for Display only frst name in grid we have to modify mage/adminhtml/Block/customer/grid.php file find
$this->addColumn('name', array(
            'header'    => Mage::helper('customer')->__('Name'),
            'index'     => 'name'
        ));
 & replace it with below code
$this->addColumn('name', array(
            'header'    => Mage::helper('customer')->__('Name'),
            'index'     => 'firstname'
        ));

Tuesday 18 June 2013

view all product link in pager in category listing page in magento

add “View All” link in Magento’s pagination.in product list page you have two follw two steps only:

1. in page/html/pager.phtml file add
<a href="<?php echo $this->getLimitUrl('all')?>" title="<?php echo $this->__('View All Products') ?>">
<?php echo $this->__('View All') ?>
</a>

2 step app/code/local/mage/catalog/block/product/list/toolbar.php file

modify function _construct()

add below code after $this->setTemplate('catalog/product/list/toolbar.phtml'); line

$defaultLimit = $this->getDefaultPerPageValue();
Mage::getSingleton('catalog/session')->setData("limit_page",$defaultLimit);


enjoy Code.

Friday 14 June 2013

Add subcategory thumbnail image in topmenu in magento

link :http://source.9nit.com/magento/how-to-retrieve-the-parent-category-images-in-topmenu-in-magento-42154.html

step 1:
modified mage/catalog/model/observer.php file  modify  _addCategoriesToMenu function in modify
$categoryData = array( 
like
 $categoryData = array(
                'name' => $category->getName(),
            'id' => $nodeId,
            'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
            'is_active' => $this->_isActiveMenuCategory($category),
            'links' => $category->getData('links'),
            'image' => $category->getImageUrl('image'),
            'thumbnail' =>Mage::getModel('catalog/category')->load($cat)->getThumbnail(),
            'getLevel' => $category->getLevel()
            );


also add $cat = $category->getId();  after $nodeId



step2:
modify Mage/page/block/html/topmenu.php  modified _getHtml function
add below code after $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
                . $this->escapeHtml($child->getName()) . '</span></a>';

// new code starts here 

$parentLevels = $child->getLevel();
            if($parentLevels != 0)
              {
                //echo $child->getData('thumbnail');

                   $urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
                if(!file_exists("./media/catalog/category/resized"))    
                mkdir("./media/catalog/category/resized",0777);
                $imageName = substr(strrchr($urls,"/"),1);
                $imageResized = Mage::getBaseDir

('media').DS."catalog".DS."category".DS."resized".DS.$imageName;
                $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($urls,'/media'));
                if (!file_exists($imageResized)&&file_exists($dirImg)) :
                     $imageObj = new Varien_Image($dirImg);
                      $imageObj->constrainOnly(TRUE);
                      $imageObj->keepAspectRatio(FALSE);
                     $imageObj->keepFrame(TRUE);
                     $imageObj->resize(28,28);
                     $imageObj->save($imageResized);
               endif;

              $newImageUrl = Mage::getBaseUrl('media')."catalog/category/resized/".$imageName;

                     if($child->getData('thumbnail') !="")
                    {
                            $html .= '<img src="'.$newImageUrl.'"   />';
                     }
                }



Wednesday 5 June 2013

Import tier price through csv in magento

1. Create tierprice.csv in which there are Colums like  sku,price_General_2 (here genereal is customergroup
& 2 is qty),price_General_5,price_Wholesale_2  having value 
1112,200.99,425.99,150   

2.Create a custom module for import tierprice csv
create file in app/etc /modules     /Plumtree_Tierprice.xml  in it:
<?xml version="1.0"?>
<config>
    <modules>
        <Plumtree_Tierprice>
            <active>true</active>
            <codePool>local</codePool>
        </Plumtree_Tierprice>
    </modules>
</config>

3.Create modules Config.xml .App/code/local/Plumtree/Tierprice/etc/config.xml in it:
<?xml version="1.0"?>
<config>
  <modules>
        <Plumtree_Tierprice>
            <version>0.1.0</version>
        </Plumtree_Tierprice>
    </modules>
     <global>
        <models>
            <catalog>
                <rewrite>
                   

<convert_adapter_product>Plumtree_Tierprice_Catalog_Model_Convert_Adapter_Product</convert_adapter_product>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

4. now create model file in app/code/local/Plumtree/Tierprice/Catalog/Model/Convert/Adapter/Product.php    in

it:
<?php
class Plumtree_Tierprice_Catalog_Model_Convert_Adapter_Product extends

Mage_Catalog_Model_Convert_Adapter_Product
{
   
        private $_group_list = null;
        private $_tier_price_fields = null;
       
        public function load() {
           // load the group list
           $this->_group_list = Mage::getResourceModel('customer/group_collection')-

>setRealGroupsFilter()->loadData()->toOptionArray();
          
            // call the parent load
            return parent::load();
        }
       
    public function saveRow(array $importData)
    {
        // doing normal import...
        parent::saveRow($importData);
       
        if (!is_array($this->_group_list)) {
            $this->_group_list = Mage::getResourceModel('customer/group_collection')-

>setRealGroupsFilter()->loadData()->toOptionArray();
        }
       
        // is there a tier price field? (check this only the first time)
       
        if (!is_array($this->_tier_price_fields)) {
           
            $this->_tier_price_fields = array();
           
            foreach ($importData as $k=>$v) {
                $matches = array();
                if (preg_match('/^price\_([^_]+)\_?([0-9]+)?$/', $k, $matches)) {
                    // found a valid field. Check the group name and quantity
                   
                    $foundvalid = false;
                    foreach ($this->_group_list as $group) {
                        if (strtolower($group['label']) == strtolower($matches[1])) {
                            $foundvalid = true;
                            if (isset($matches[2])) $q = (int)$matches[2]; else $q = 1;
                            $this->_tier_price_fields[$k] = array('id_group'=>$group

['value'], 'quantity'=>$q);
                            break;
                        }
                    }
                   
                    if (!$foundvalid) {
                        // group not found!
                        // can't call exceptions here?
                        //$message = Mage::helper('catalog')->__('Customer group "%s" for

tier price not found', $matches[1]);
                          //    Mage::throwException($message,

Varien_Convert_Exception::NOTICE);
                    }
                   
                } /* end if */
            }
           
        }
       
        if (!count($this->_tier_price_fields)) return true; // no tier prices found
       
       
      // fetch the store object
      if (empty($importData['store'])) {
                if (!is_null($this->getBatchParams('store'))) {
                  $store = $this->getStoreById($this->getBatchParams('store'));
                } else {
                    // can't call exceptions here?
                  //$message = Mage::helper('catalog')->__('Skip import row, required field

"%s" not defined', 'store');
                  //Mage::throwException($message);
                }
            }    else {
                $store = $this->getStoreByCode($importData['store']);
            }
           
            // create the product object
      $product = $this->getProductModel()->reset();
      $product->setStoreId($store->getId());
      $productId = $product->getIdBySku($importData['sku']);
      $storeId = $store->getId();
     
            if ($productId) {
              $product->load($productId);
               
                $tierPrices = $product->tier_price;
               
                foreach ($this->_tier_price_fields as $tier_key=>$imported_tier_price) {
                    // should i update an existing tier price?
                    foreach ($tierPrices as $ktp=>$tp) {
                        if ($tp['website_id'] != $storeId) continue;
                        if ($tp['cust_group'] != $imported_tier_price['id_group'])

continue;
                        if ($tp['all_groups'] != 0) continue;
                        if ($tp['price_qty'] != $imported_tier_price['quantity'])

continue;
                       
                        // it matches this existing tier price. I remove it
                        unset($tierPrices[$ktp]);
                    }
                   
                    // now i add the imported tier_price
                    if ($importData[$tier_key]) {
                        $tierPrices[] = array(
                            'website_id'  => $storeId,
                            'cust_group'  => $imported_tier_price['id_group'],
                  'all_groups'  => 0,
                            'price_qty'   => number_format

($imported_tier_price['quantity'], 4, '.', ''),
                            'price'       => number_format($importData

[$tier_key], 4, '.','')
                        );
                    }
                   
                   
                }
               
                $product->tier_price = $tierPrices;
               
                // Save you product with all tier prices
                $product->save();
            }
       
        return true;
    }
}
  that's it. now Import csv through data flow Advanced profile.