Thursday, 30 January 2014

IP track location city


<?php
   $key='4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089';
   /*include('ip2locationlite.class.php');
   $ipLite = new ip2location_lite;
   $ipLite->setKey('4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089');
 
   echo "<br>RA : ".$_SERVER['REMOTE_ADDR'];
 
   $tags = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
   $errors = $ipLite->getError();
 
   echo "<pre>"; print_r($errors); echo "</pre>";*/
 
   //http://api.ipinfodb.com/v3/ip-country/?key=4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089&ip=122.163.43.151
 
   echo "<br>U : ".$url='http://api.ipinfodb.com/v3/ip-country/?key='.$key.'&ip='.$_SERVER['REMOTE_ADDR'];
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $data = curl_exec($ch);
   curl_close($ch);
 
   $dataArr=explode(";",$data);
 
   echo "<pre>"; print_r($dataArr); echo "</pre>";
?>


Link:- http://www.ipinfodb.com/ip_location_api.php

Thursday, 28 November 2013

Toggle Visibility - Show/Hide use in javascript


<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

==============================HTML============================
 <div class="test" onclick="toggle_visibility('testId');" >Click Me</div>
<div id="testId">
Demo text
</div>

Tuesday, 26 November 2013

Product collection filter by attribute value

$productCollection = Mage::getModel('catalog/product')->getCollection();

 $productCollection->addAttributeToFilter('color', 4);

For example   attribute code  ="color"
                           Red (value id) ="4"

Thursday, 10 October 2013

Passing array of checkbox values to php through jQuery (example)


<!DOCTYPE html>
<html>
<head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
                function doit() {
                        var p=[];
                        $('input.cb').each( function() {
                                if($(this).attr('checked')) {
                                        p.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'/process.php',
                                type:'POST',
                                data: {list:p},
                                success: function(res) {
                                        alert(res);
                                }
                        });
                }
        </script>
</head>
<body>
        <input type="checkbox" class="cb" rel="1"></input>This is 1<br />
        <input type="checkbox" class="cb" rel="abc"></input>This is abc<br />
        <input type="checkbox" class="cb" rel="999"></input>This is 999<br />
        <a href="javascript:void(0)" onclick="doit()">Click</a>
</body>
</html>

print_r(@$_POST['list']);

Friday, 20 September 2013

Magento Add ‘Customer Group’ to Registration Form

Step -1
customer/form/register.phtml Add


<div>
<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>

Step-2

Mage\Customer\controllers\AccountController.php
line no 287 add
$customer->setGroupId($this->getRequest()->getPost(‘group_id’));

Step-3

Mage\Customer\etc\config.xml
Add customer_account node
<group_id><create>1</create><update>1</update></group_id>