Tuesday, February 7, 2012

Add product list on MouseOver on My cart in top link Magento

if you want to display a dropdown list of products in  my cart on MouseOver on 'My Cart' in top menu then follow these easy step:

1.copy the following line of code and save this in file cartlist.phtml  at path
app\design\frontend\base\default\template\catalog\product\

code:
////////////
<?php if(Mage::helper('checkout/cart')->getSummaryCount()>0) { ?>
<div style="display:none;position: relative;left: 650px;width: 200px;top: -70px;" id="vinod">
<div class="block block-cart">
 
    <div class="block-title">
        <strong><span><?php echo $this->__('My Cart') ?></span></strong>
    </div>
    <div class="block-content">
        <?php
        $cartid= Mage::getModel('checkout/cart')->getProductIds();
   
      
            foreach($cartid as $pid)
            {
               $pname= Mage::getModel('catalog/product')->load($pid)->getName();
              ?>
               <p><b><?=$pid?>=<?=$pname?></b></p>
            <?php
               }
 
        ?>
           </div>  
</div>
</div>
<? }?>


//////////////

2. add this xml code in catalog.xml in default scope
app\design\frontend\base\default\layout\
////////////
<reference name="content">
             
          <block type="catalog/product" name="catalog.product.cartlist" template="catalog/product/cartlist.phtml"/>
          </reference>


///////////////////

3. find the following line of code in
app\code\core\Mage\Checkout\Block\ Links.php

//////////////

 public function addCartLink()
    {
      
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Cart (%s item)', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Cart (%s items)', $count);
            } else {
                $text = $this->__('My Cart');
            }
           
          
            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
        }
        return $this;
    }

/////////////



and replace with 
///////////
 public function addCartLink()
    {
     
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Cart (%s item)', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Cart (%s items)', $count);
            } else {
                $text = $this->__('My Cart');
            }
           
          
            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart" onMouseOver="$(\'vinod\').toggle();"');
        }
        return $this;
    }
 
/////////


that's it.


Enjoy!!!.....




Monday, February 6, 2012

how to add custom field in customer registration form in front end and admin end magento 1.6.X

let you want to add occupation for customer registration
1. Add the following code in the form tag in register.phtml and edit.phtml
app/design/frontend/default/yourstore/template/customer/form/register.html 

////////////////
 <div class="input-box">

                    <label for="occupation"><?php echo $this->__('Occupation') ?></label><br/>

                    <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

                </div> 

/////////////////

2. replace the following block of code in
app/code/core/Mage/Customer/Model/Resource/Setup.php

//////////
 'group_id'           => array(
                        'type'               => 'static',
                        'label'              => 'Group',
                        'input'              => 'select',
                        'source'             => 'customer/customer_attribute_source_group',
                        'sort_order'         => 25,
                        'position'           => 25,
                        'adminhtml_only'     => 1,
                        'admin_checkout'     => 1,
                    ),     
///////////

with this
////////////

 'group_id'           => array(
                        'type'               => 'static',
                        'label'              => 'Group',
                        'input'              => 'select',
                        'source'             => 'customer/customer_attribute_source_group',
                        'sort_order'         => 25,
                        'position'           => 25,
                        'adminhtml_only'     => 1,
                        'admin_checkout'     => 1,
                    ),                   
                    'occupation'          => array(
                        'type'               => 'varchar',
                        'label'              => 'Occupation',
                        'input'              => 'text',
                        'sort_order'         => 7,
                        'validate_rules'     => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}',
                        'position'           => 120,
                    ),
///////////

3. find the following line of code around line 280  in
app/code/core/Mage/Customer/controllers/AccountController.php

///////
 $customerData = $customerForm->extractData($this->getRequest());
//////

and replace with
////////////
 $customerData = $customerForm->extractData($this->getRequest());
           //new code added to save occupation in database start here
            if($this->getRequest()->getParam('occupation'))
             {
                 $customer->setOccupation($this->getRequest()->getParam('occupation'));
                
             } 
              //new code added to save occupation in database end here
           

///////////

4. add the following code in
app/code/core/Mage/Customer/etc/config.xml
your
under the customer_account

////////
<occupation>
                 <create>1</create>
                 <update>1</update>
              </occupation>
//////

5. put this script in your register.phtml 's header file and remove it after one run
 <?php
  
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
  
    $AttrCode = 'occupation';
  
      $settings = array (
  
          'position' => 1,
  
          'is_required'=> 0
  
      );
  
      $setup->addAttribute('1', $AttrCode, $settings);
  
      ?>



To show this field in admin end in customer tab field


1. find and replace this function of code in
app/code/core/Mage/AdminHtml/Block/Customers/Grid.php

/////////////////
 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
            ->addNameToSelect()
            ->addAttributeToSelect('email')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('group_id')
            ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
             ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
            ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
            ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
            ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }
/////////////////// 

and replace with

//////////////////
 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
            ->addNameToSelect()
            ->addAttributeToSelect('email')
            ->addAttributeToSelect('occupation')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('group_id')
            ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
             ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
            ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
            ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
            ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }
/////////////////// 



2. find and replace this function of code in
app/code/core/Mage/AdminHtml/Block/Customers/Grid.php


///////////
protected function _prepareColumns()
    {
        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('customer')->__('ID'),
            'width'     => '50px',
            'index'     => 'entity_id',
            'type'  => 'number',
        ));
        $this->addColumn('firstname', array(
            'header'    => Mage::helper('customer')->__('First Name'),
            'index'     => 'firstname'
        ));
        $this->addColumn('lastname', array(
            'header'    => Mage::helper('customer')->__('Last Name'),
            'index'     => 'lastname'
        ));
       /* $this->addColumn('name', array(
            'header'    => Mage::helper('customer')->__('Name'),
            'index'     => 'name'
        ));*/
        $this->addColumn('email', array(
            'header'    => Mage::helper('customer')->__('Email'),
            'width'     => '150',
            'index'     => 'email'
        ));
        $this->addColumn('occupation', array(
            'header'    => Mage::helper('customer')->__('Occupation'),
            'width'     => '150',
            'index'     => 'occupation'
        ));

        $groups = Mage::getResourceModel('customer/group_collection')
            ->addFieldToFilter('customer_group_id', array('gt'=> 0))
            ->load()
            ->toOptionHash();

        $this->addColumn('group', array(
            'header'    =>  Mage::helper('customer')->__('Group'),
            'width'     =>  '100',
            'index'     =>  'group_id',
            'type'      =>  'options',
            'options'   =>  $groups,
        ));

        $this->addColumn('Telephone', array(
            'header'    => Mage::helper('customer')->__('Telephone'),
            'width'     => '100',
            'index'     => 'billing_telephone'
        ));

        $this->addColumn('billing_postcode', array(
            'header'    => Mage::helper('customer')->__('ZIP'),
            'width'     => '90',
            'index'     => 'billing_postcode',
        ));

        $this->addColumn('billing_country_id', array(
            'header'    => Mage::helper('customer')->__('Country'),
            'width'     => '100',
            'type'      => 'country',
            'index'     => 'billing_country_id',
        ));

        $this->addColumn('billing_region', array(
            'header'    => Mage::helper('customer')->__('State/Province'),
            'width'     => '100',
            'index'     => 'billing_region',
        ));

        $this->addColumn('customer_since', array(
            'header'    => Mage::helper('customer')->__('Customer Since'),
            'type'      => 'datetime',
            'align'     => 'center',
            'index'     => 'created_at',
            'gmtoffset' => true
        ));

        if (!Mage::app()->isSingleStoreMode()) {
            $this->addColumn('website_id', array(
                'header'    => Mage::helper('customer')->__('Website'),
                'align'     => 'center',
                'width'     => '80px',
                'type'      => 'options',
                'options'   => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
                'index'     => 'website_id',
            ));
        }

        $this->addColumn('action',
            array(
                'header'    =>  Mage::helper('customer')->__('Action'),
                'width'     => '100',
                'type'      => 'action',
                'getter'    => 'getId',
                'actions'   => array(
                    array(
                        'caption'   => Mage::helper('customer')->__('Edit'),
                        'url'       => array('base'=> '*/*/edit'),
                        'field'     => 'id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
        ));

        $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
        $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
        return parent::_prepareColumns();
    }
///////////////

3...find the following line of code in
app\code\core\Mage\Adminhtml\Block\Customer\Edit\Tab\Account.php

/////
$suffixElement = $form->getElement('suffix');
        if ($suffixElement) {
            $suffixOptions = $this->helper('customer')->getNameSuffixOptions($customerStoreId);
            if (!empty($suffixOptions)) {
                $fieldset->removeField($suffixElement->getId());
                $suffixField = $fieldset->addField($suffixElement->getId(),
                    'select',
                    $suffixElement->getData(),
                    $form->getElement('lastname')->getId()
                );
                $suffixField->setValues($suffixOptions);
                if ($customer->getId()) {
                    $suffixField->addElementValues($customer->getSuffix());
                }
            }
        }
      
//////

and replace with
//////////////////////////////
$suffixElement = $form->getElement('suffix');
        if ($suffixElement) {
            $suffixOptions = $this->helper('customer')->getNameSuffixOptions($customerStoreId);
            if (!empty($suffixOptions)) {
                $fieldset->removeField($suffixElement->getId());
                $suffixField = $fieldset->addField($suffixElement->getId(),
                    'select',
                    $suffixElement->getData(),
                    $form->getElement('lastname')->getId()
                );
                $suffixField->setValues($suffixOptions);
                if ($customer->getId()) {
                    $suffixField->addElementValues($customer->getSuffix());
                }
            }
        }
        ///new code start here
         $fieldset->addField('occupation', 'text', array(
            'name'      => 'occupation',
             'label'=>'Occupation'
            
            ));
        
         ///new field end here



/////////////////////////////

4.find the follwing line of code around line no. 280 in file
app\code\core\Mage\Adminhtml\controllers\CustomerController.php

///////////////

if (isset($data['subscription'])) {
                $customer->setIsSubscribed(true);
            } else {
                $customer->setIsSubscribed(false);
            }
 ////////////////

and replace with
///////////////

if (isset($data['subscription'])) {
                $customer->setIsSubscribed(true);
            } else {
                $customer->setIsSubscribed(false);
            }
           //new code added to save occupation in database start here
          
            if(isset($data['account']['occupation']))
             {
              
                 $customer->setData('occupation',$data['account']['occupation']);
                
             } 
             //new code added to save occupation in database end here
///////////////



Enjoy !!!!!!!!

Friday, January 20, 2012

How to remove blank new line space in dreamweaver using regular expression

  1. >> open file
2. press Ctl+F
3. Choose regular expression select box in footer of search & replace window.
4. put "[\r\n]{2,}" in Find field
5. put "\n" in replace field
6 . press replace or replace all button.


Enjoy!!!!!

Tuesday, January 10, 2012

How to show customer group selecter in registration form

Make a copy of config.xml from app > code > core > Mage > Customer > etc > config.xml and add the following line of code into the customer account fieldset and save it to app > code >local>config.xml and in this file add the following line of code into the customer account fieldset:



<fieldsets>
<customer_account>
............
<group_id><create>1</create><update>1</update></group_id>
...........
</customer_account>
</fieldsets>


add code to the frontend of the store, in the registration form. Open template/customer/form/register.phtml and add the following code somewhere in the form:


<div class="input-box">
<label for="group_id"><?php echo $this->__('Group') ?><span class="required">*</span></label><br/>
<select name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />
<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
<?php } ?>
</select>
</div>


also change some code in app\code\core\Mage\Customer\controllers\AccountController.php now
replace $customer->getGroupId();
with

 if($this->getRequest()->getPost('group_id'))
 { $customer->setGroupId($this->getRequest()->getPost('group_id'));
 } else {
$customer->getGroupId(); }


Enjoy!!!



Thursday, January 5, 2012

PHP: Random password with numbers and letters

function genRandomString() {
    $length = 10;
    $characters = ’0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
    $string = ;    

    for ($p = 0$p < $length$p++) {
        $string .= $characters[mt_rand(0strlen($characters))];
    }
    return $string;
}

Thursday, December 8, 2011

IE9 Issue with Magento Checkout-Disabled Credit Card Fields-Fix

In some builds of Magento (Community and Enterprise), there is an issue with IE9 and all of the credit card fields being disabled. This is on step 4 of the one page checkout, and users will not be able to enter any information, or even use the dropdown select box to choose which type of credit card they are going to be using.



The fix:
Browse to your /skin/frontend/..template folder (if you’ve got one, if not, browse to the /skin/frontend/default/default/js/ folder). Open up the opcheckout.js file Around lines 641 AND 647, (inside the switchMethod function), replace :
1
var elements = form.select('input', 'select', 'textarea');
with
1
var elements = form.select('input').concat(form.select('select'), form.select('textarea'));
These 2 lines should fix your IE9 issues, as well as be compatible and work with Chrome/Firefox, earlier builds of IE, and others.

For other to solve the IE9 issue use the metatag in head of page

<meta http-equiv="X-UA-Compatible" content="IE=7" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />

Tuesday, December 6, 2011

Extarct Fedex Shipping Response


 $xmltxt = $client->__getLastResponse(); 
       $xmltxt = preg_replace('#(</?)ns[\d]:#','$1',$xmltxt);     
     //remove all the namespaces that appear in the soap response.
        $xmltxt = preg_replace('#(</?)v[\d]:#','$1',$xmltxt);
         $xmltxt = preg_replace('#(</?)soapenv:#','$1',$xmltxt);
         echo $xmltxt;  
     //debuggig to make sure the SOAP is proper XML and 
         namespaces removed
        $doc = new DOMDocument();  
        $doc->loadXML($xmltxt);        
       $trackingNumber = $doc->getElementsByTagName("TrackingNumber");
        print_r($trackingNumber); //debugging to make sure this exists.
        
        if($trackingNumber = $trackingNumber->item(0)) { 
       //retrieve the first trackingnumber in the elements list.  
                $trackingNumber = $trackingNumber->nodeValue; 
        }  
        
        echo "Tracking Number :::::: ".$trackingNumber;

Saturday, November 19, 2011

How to change Magento search from LIKE ‘keyword’ to LIKE ‘keyword%’ but not LIKE ’%keyword% ?


The Like search is the most basic routine available in a SQL database engine that can be called a search function. It has to be applied against the data_index field in catalogsearch_fulltext and due to the fact that it is searching the whole field, has to be a sliding window search, or simulated simple regex if you’re used to those terms.
Here’s the code snippet that creates it:

foreach ($words as $word{
                    $like[] 
'`s`.`data_index` LIKE :likew' $likeI;
                    
$bind[':likew' $likeI] '%' $word '%';
                    
$likeI ++;
                
}
The reason for using %$word%; for the match string is pretty obvious and simple. It has to match against the whole field and find something bounded by spaces (definition of a word) to get a return match.
So a search on relation will return a match on: 
relation
correlation
correlations
   relations
   relationship
ad nauseum

If you remove the % from the beginning of the match string, then it has to match everything up to $word in the data_index field in order to return a match, so no solution there.
The next step is to decide that your customer might be smart enough to start a word with the right spelling, but trail off on the right hand side to unfindability. If Magento’s like search is modified to look for words starting with a space, looking for relation should no longer also return correlation, correlations, etc.
Where this modification falls down on the job is that it will never match the beginning of the data_index field, starting words in a parenthesis block or words that have been separated that are really one word or hyphenated.
For example, searches for black and stone will no longer return blackstone.
Modification to experiment with this this can be done in app/code/local/Mage/CatalogSearch/Model/Mysql4/Fulltext.php as follows: 
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
                
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE{
                $words 
$stringHelper->splitWords($queryTexttrue$query->getMaxQueryWords());
                
$likeI 0;
                foreach (
$words as $word{
                    $like[] 
'`s`.`data_index` LIKE :likew' $likeI;
                    
$bind[':likew' $likeI] '% ' $word '%';
                    
$likeI ++;
                
}
                
if ($like{
                    $likeCond 
'(' join(' AND '$like) . ')';
                
}
            }

From
'%' $word '%'; to
'% ' $word '%';