Posts Tagged ‘Magento’


Custom Account/Registration Fields

Our goal was to add a few fields to the standard Magento Registration form (Magento 1.4x, using the default template structure), enabling us to capture information such as Occupation, and Education.

Magento provides a simple user account signup page. However, some online stores might want to collect relevant customer information for more targeted and personal interactions with their customers. Some examples of details that could be collected include occupation, education etc…

Adding your custom fields on the signup form is not difficult, but it is not trivial either, since one cannot use the Magento backend for the task. As an example of how it can be done, I will demonstrate the addition of a new custom field to the signup form asking new users to enter their occupation and education.
Okay, Let me follow step by step. Please do not miss any single step otherwise it won’t work…
Step 1 :

Open File :

app\design\frontend\base\default\template\customer\form\register.phtml

1. Find below code

<div>
<label for="email_address"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br/>
<input type="text" name="email" id="email_address" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>

Replace Code

<div>
<label for="email_address"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br/>

<input type="text" name="email" id="email_address" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address')
?>" />

</div>

<div>

<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') ?>" />

</div>

<div>

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

<input type="text" name="education" id="education" value="<?php echo $this-
>htmlEscape($this->getFormData()->getEducation()) ?>" title="<?php echo $this->__('Education')
?>" />

</div>

step 2:

Open file :

app\design\frontend\base\default\template\customer\form\edit.phtml

1. Find Below Code

<li>
<div>
<label for="email"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br />
<input type="text" name="email" id="email" value="<?php echo $this-
>htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>
</li>

Replace Code

<li>
<div>
<label for="email"><?php echo $this->__('Email Address') ?> <span
class="required">*</span></label><br />
<input type="text" name="email" id="email" value="<?php echo $this-
>htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email
Address') ?>" />
</div>
</li>

<li>
<div>
<label for="occupation"><?php echo $this->__('Occupation') ?> </label><br/>
<input type="text" name="occupation" id="occupation" value="<?php echo
$this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this-
>__('Occupation') ?>" />
</div>
</li>

<li>
<div>
<label for="education"><?php echo $this->__('Education') ?> </label><br/>
<input type="text" name="education" id="education" value="<?php echo
$this->htmlEscape($this->getCustomer()->getEducation()) ?>" title="<?php echo $this-
>__('Education') ?>" />
</div>

</li>

Step 3:

Open file :

app\code\core\Mage\Customer\Model\Entity\Setup.php

1. Find below code inside getDefaultEntities() function

Replace Code :

'email' => array(
'type'
=> 'static',
'label'
=> 'Email',
'class'
=> 'validate-email',
'sort_order' => 6,
),
'occupation' => array(
'label'
=> 'Occupation',
'required' => false,
'sort_order' => 7,
),
'education' => array(
'label'
=> 'Education',
'required' => false,
'sort_order' => 8,
),

Note: (if you need field with validation then ‘requirted’ => true)

Hey do not feel tired or boring  you are going right way. You are now only Two steps to get it done.

Step 4 :

Open file :

app\code\core\Mage\Customer\etc\config.xml

1. Find below Code :

<global>
<fieldsets>
<customer_account>

Then In <customer_account>, you will find below line

<email><create>1</create><update>1</update></email>

After that line insert 2 more rows like below :

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

Step 5:

(Most important) Please follow below instruction :

1. Open file app\design\frontend\base\default\template\customer\form\register.phtml

2. Add Below code at top of the file,

<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = occupation;
$settings = array (
'position' => 1,
'is_required'=> 0
);
$setup->addAttribute('1', $AttrCode, $settings); ?>

Now Save file Clear Cache from admin panel Refresh create account page

For Example, (http://websitename/ index.php/customer/account/create/)

Once Refreshed, then

Go to the customer_entity_varchar table in DB, your field is there…

Again Open file, app\design\frontend\base\default\template\customer\form\register.phtml

Now Replace Top code,

<?php
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$AttrCode = education;
$settings = array (
'position' => 1,
'is_required'=> 0
);
$setup->addAttribute('1', $AttrCode, $settings); ?>

Or Else put

$AttrCode = education;

Now Save file Clear Cache from admin panel Refresh create account page

For Example, (http://websitename/ index.php/customer/account/create/)

Once Refreshed then,

Again go to file, app\design\frontend\base\default\template\customer\form\register.phtml

And Comment Top Code or remove top code….

$AttrCode = education;

Now create your account and login with your information…

Check my account page and get smile….:)

That’s it…………….

Feel Free to ask if you are having any doubt in this.
credit goes to Magento developer : Vipul Prajapati

PHP Cookies: How to Set Cookies & Get Cookies

Cookies don’t have to be an essential part of a website but can provide some of the “little things” that can set your website apart from the rest. Cookies are small tidbits of information that you save on the client’s computer so that you can access them next time they visit the website. Session ID’s are also usually held in cookies.

So what are the most popular uses of cookies? They are:

  • To store username/password information so that the user doesn’t have to log in every time they visit the website (“remember me” sign ins).
  • To simply remember the user’s name.
  • To keep track of a user’s progress during a specified process.
  • To remember a user’s theme.

Setting the Cookie

Setting a cookie requires a key, a value, and the amount of time to allow the cookie to exist.

$first_name = 'David';
setcookie('first_name',$first_name,time() + (86400 * 7)); // 86400 = 1 day

Above, we set the user’s first name equal to ‘David’ (this data would actually come from a form or database but for the sake of the example we’ll use my name). Then, we set a cookie with the key of “first_name” with the value ‘David’, and program it to expire 7 days from now.

Getting the Cookie Values

Now that we’ve set our cookie, it’s time to get the value pretend they left your site and are coming back two days later).

echo 'Hello '.($_COOKIE['first_name']!='' ? $_COOKIE['first_name'] : 'Guest'); // Hello David!

Above, we check to see if the cookie with ‘first_name’ as the key still exists. If so, we use their name; if not, we call them “Guest”. Basic cookies are that easy!

PHP cookies can be set with more specific directives, including path, domain, secure, and httponly.

setcookie('first_name',$first_name,time() + (86400* 7),'/~sugar/','sudhirtiwari.com,true,true);

This cookie is the same as above, but we’re also telling the cookie to be applied towards the “~sugar” directory on the “davidwalsh.name” domain. It is for use only on an SSL connection and it may not be used by JavaScript.

Some other things to know about cookies:

  • Although you set an expiration on the cookie, a user can delete cookies at any time.
  • Cookies can only be accessed by the browser that set them (Firefox and IE don’t share them)
  • A user can turn cookies off in their browser.

Magento – Fix for admin login problem

Out of all CMS Magento installation is really big for everyone. Some time works and other time not works. Its all due to lake of common tips we missing while installation or After installation.

To make your mangeto admin panel working after installation follow below steps.

1] modify the core Magento code (keep in mind you may have to re-apply the fix if you update the code Magento code) – go to: app/code/core/Mage/Core/Model/Session/Abstract and open up varien.php, and comment out lines 73 (comment out the comma at the end of the line) through 76 so that it looks like the following:

// set session cookie params
session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath() //remove this after putting on server (leave the comma)   ,
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()
);

For Latest version of magneto you have to do something new :)

In the latest version of which i’m using is 1.4.0.1
in that the below mentioned code is not available

app\code\core\Mage\Core\Model\Session\Abstract\varien.php

$this->getCookie()->getDomain(),
$this->getCookie()->isSecure(),
$this->getCookie()->getHttponly()

Comment these lines line (may be at line 78…);

search for “// session cookie params” line in app\code\core\Mage\Core\Model\Session\Abstract\varien.php

change

$cookieParams = array(
‘lifetime’ => $cookie->getLifetime(),
‘path’ => $cookie->getPath(),
‘domain’ => $cookie->getConfigDomain(),
‘cookieParams’ => $cookie->isSecure(),
‘httponly’ => $cookie->getHttponly()
);

to

$cookieParams = array(
‘lifetime’ => $cookie->getLifetime(),
‘path’ => $cookie->getPath()
);

and comment the below mentioned code
line number 86,

/* if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}

if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}
*/

now login as admin, it will work
Hope to get lots of thanks here :)

Magento installation problem in localhost – [validate-url] – Please enter a valid URL. Protocol is required…

Comment line no. #501 in \magento-1.4.2.0\js\prototype\validation.js file by code below:
like below i did

['validate-url', 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)', function (v) {
//return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
return true;
}],

it will works :)

source:stackoverflow.com
Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories