Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Add customer in different group during registration in magento

If you want to add customer in different group during registration than follow this instruction.

You need to change in two files.
1) app\design\frontend\[your theme]\default\template\customer\form\register.phtml
add following code in the page

<div class="input-box">
   <label for="group_id"><?php echo $this->__('Group') ?><span class="required">*</span></label>
   <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>

2) 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();
}

This is good practise to override AccountController.php in your local directory

Print the contents of specific DIV using javascript

Using my following solution you can print the specific div content from your web page if you don't want to print your full page.

Demo

<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>  

<script type="text/javascript">
    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data)
    {
        var mywindow = window.open('', 'new div', 'height=400,width=600');
        mywindow.document.write('<html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.print();
        mywindow.close();
        return true;
    }
</script>
</head>
<body>

<div id="yourdiv">
    Div you want to print. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a quam at nibh adipiscing interdum. Nulla vitae accumsan ante. 
</div>

<div>
    This will not be printed.
</div>

<div id="anotherdiv">
    Nor will this.
</div>
<input type="button" value="Print" onclick="PrintElem('#yourdiv')" />

</body>
</html>



Magento age verification on create account page using javascript

Use following script in your create account page for age verification of new user before creating new account of user.

<script>
function check_dob()
{
    var month = document.getElementById('month').value;
    var day = document.getElementById('day').value;
    var year = document.getElementById('year').value;
    var dbDate = year+'-'+month+'-'+day;
    var today = new Date();
    var birthDate = new Date(dbDate);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
    age--;
    }

    if(age<=20)
    {
        alert("You are under "+age+" Year")
    }
}
</script>

 

Copyright @ 2017 HKBlog.