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>


Thursday 19 September 2013

Creating extra fields in registration form in magento

Link:- http://www.webtechnologycodes.com/creating-extra-fields-in-registration-form-in-magento/


Code:- Step1.
Open your register.phtml file in magento.
if you want to add such as office address fields in your form
then insert this line


<div class="field">
                    <label for="offaddress" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Office Address') ?></label>
                    <div class="input-box">
                        <input name="offaddress" id="offaddress" title="<?php echo Mage::helper('contacts')->__('Office Address') ?>" value="<?php echo $this->escapeHtml($this->getFormData()->getOffaddress()) ?>" class="input-text required-entry" type="text" />
     </div>
            </div>



Step2.

Now to retrieve this field in my account page 

<li>
            <label for="offaddress" class="required"><em>*</em><?php echo $this->__('Office Address') ?></label>
            <div class="input-box">
               <input type="text" name="offaddress" id="offaddress" value="<?php echo $this->htmlEscape($this->getCustomer()->getOffaddress()) ?>" title="<?php echo $this->__('Office Address') ?>" class="input-text required-entry validate-email" />
            </div>
        </li>


Step 3. Now the final step is to create that type of attribute in database

for this run this script once in your register.phtml file and you are all done.


<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'offaddress', array(
 'label'  => 'Office Address',
 'type'  => 'varchar',
 'input'  => 'text',
 'visible' => true,
 'required' => false,
 'position' => 1,
 ));
$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('customer', 'offaddress');
$attribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit'));  //enable all action
//$attribute->setData('used_in_forms', array('adminhtml_customer'));  //to make the attribute can be created in backend only
//$attribute->setData('used_in_forms', array('customer_account_create')); //to make the attribute can be created in registration only
//$attribute->setData('used_in_forms', array('customer_account_edit')); // to make the attribute can be edited in the frontend only

$attribute->save();
?>

Wednesday 18 September 2013

How to cuntry code respect to set currency

LINK:- http://rosskendall.com/blog/web/using-geoip-with-magento-and-multiple-sites


code:- //GeoIP Track
define("GEOIP_DAT_FILE", "geoip/GeoIP.dat");
define("GEOIP_INC_FILE", "geoip/geoip.inc");

include(GEOIP_INC_FILE);

$_geoip = geoip_open(GEOIP_DAT_FILE ,GEOIP_STANDARD);
$_country_code = geoip_country_code_by_addr($_geoip, $_SERVER['REMOTE_ADDR']);

geoip_close($_geoip);

switch ($_country_code) {
  case "GB": // United Kingdom
    $_SERVER["MAGE_RUN_CODE"] = "uk";
    break;
  case "AU": // Australia
    $_SERVER["MAGE_RUN_CODE"] = "au";
    break;
  case "NZ": // New Zealand
    $_SERVER["MAGE_RUN_CODE"] = "nz";
    break;
  default:
    $_SERVER["MAGE_RUN_CODE"] = "";
}