Magento4u_CustomerAttribute - Version 1.0.0

Version Notes

First review release

Download this release

Release Info

Developer Suman Kar
Extension Magento4u_CustomerAttribute
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Magento4u/Customer/controllers/AccountController.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
4
+
5
+ class Magento4u_Customer_AccountController extends Mage_Customer_AccountController {
6
+
7
+ public function editPostAction() {
8
+
9
+ if (!$this->_validateFormKey()) {
10
+ return $this->_redirect('*/*/edit');
11
+ }
12
+
13
+ if ($this->getRequest()->isPost()) {
14
+ /** @var $customer Mage_Customer_Model_Customer */
15
+ $customer = $this->_getSession()->getCustomer();
16
+
17
+ /** @var $customerForm Mage_Customer_Model_Form */
18
+ $customerForm = Mage::getModel('customer/form');
19
+ $customerForm->setFormCode('customer_account_edit')
20
+ ->setEntity($customer);
21
+
22
+ $customerData = $customerForm->extractData($this->getRequest());
23
+
24
+ $errors = array();
25
+ $customerErrors = $customerForm->validateData($customerData);
26
+ if ($customerErrors !== true) {
27
+ $errors = array_merge($customerErrors, $errors);
28
+ } else {
29
+ $customerForm->compactData($customerData);
30
+ $errors = array();
31
+
32
+ // If password change was requested then add it to common validation scheme
33
+ if ($this->getRequest()->getParam('change_password')) {
34
+ $currPass = $this->getRequest()->getPost('current_password');
35
+ $newPass = $this->getRequest()->getPost('password');
36
+ $confPass = $this->getRequest()->getPost('confirmation');
37
+
38
+ $oldPass = $this->_getSession()->getCustomer()->getPasswordHash();
39
+ if (Mage::helper('core/string')->strpos($oldPass, ':')) {
40
+ list($_salt, $salt) = explode(':', $oldPass);
41
+ } else {
42
+ $salt = false;
43
+ }
44
+
45
+ if ($customer->hashPassword($currPass, $salt) == $oldPass) {
46
+ if (strlen($newPass)) {
47
+ /**
48
+ * Set entered password and its confirmation - they
49
+ * will be validated later to match each other and be of right length
50
+ */
51
+ $customer->setPassword($newPass);
52
+ $customer->setConfirmation($confPass);
53
+ } else {
54
+ $errors[] = $this->__('New password field cannot be empty.');
55
+ }
56
+ } else {
57
+ $errors[] = $this->__('Invalid current password');
58
+ }
59
+ }
60
+
61
+ // Validate account and compose list of errors if any
62
+ $customerErrors = $customer->validate();
63
+ if (is_array($customerErrors)) {
64
+ $errors = array_merge($errors, $customerErrors);
65
+ }
66
+ }
67
+
68
+ if (!empty($errors)) {
69
+ $this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
70
+ foreach ($errors as $message) {
71
+ $this->_getSession()->addError($message);
72
+ }
73
+ $this->_redirect('*/*/edit');
74
+ return $this;
75
+ }
76
+
77
+ try {
78
+ $customer->setConfirmation(null);
79
+ $customer->setProfession($this->getRequest()->getPost('profession')) // Added for updating Profession
80
+ ->save();
81
+ $this->_getSession()->setCustomer($customer)
82
+ ->addSuccess($this->__('The account information has been saved.'));
83
+
84
+ $this->_redirect('customer/account');
85
+ return;
86
+ } catch (Mage_Core_Exception $e) {
87
+ $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
88
+ ->addError($e->getMessage());
89
+ } catch (Exception $e) {
90
+ $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
91
+ ->addException($e, $this->__('Cannot save the customer.'));
92
+ }
93
+ }
94
+
95
+ $this->_redirect('*/*/edit');
96
+ }
97
+
98
+ }
99
+
100
+ ?>
app/code/community/Magento4u/Customer/etc/config.xml ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magento4u_Customer>
5
+ <version>1.0.0</version>
6
+ </Magento4u_Customer>
7
+ </modules>
8
+ <global>
9
+ <resources>
10
+ <magento4u_customer_setup>
11
+ <setup>
12
+ <module>Magento4u_Customer</module>
13
+ <class>Mage_Customer_Model_Entity_Setup</class>
14
+ </setup>
15
+ <connection>
16
+ <use>core_setup</use>
17
+ </connection>
18
+ </magento4u_customer_setup>
19
+ </resources>
20
+ </global>
21
+ <frontend>
22
+ <!--Procedure 1 to overwrite controller -->
23
+ <routers>
24
+ <customer>
25
+ <use>standard</use>
26
+ <args>
27
+ <modules>
28
+ <Magento4u_Customer before="Mage_Customer">Magento4u_Customer</Magento4u_Customer>
29
+ </modules>
30
+ </args>
31
+ </customer>
32
+ </routers>
33
+ <!--Procedure 1 to overwrite controller -->
34
+ <layout>
35
+ <updates>
36
+ <magento4u_customer>
37
+ <file>magento4u_customer.xml</file>
38
+ </magento4u_customer>
39
+ </updates>
40
+ </layout>
41
+ </frontend>
42
+ </config>
43
+
44
+ <!--Procedure 2 to overwrite controller -->
45
+ <!--
46
+ <frontend>
47
+ <routers>
48
+ <my_customer>
49
+ <use>standard</use>
50
+ <args>
51
+ <module>My_Customer</module>
52
+ <frontName>customer</frontName>
53
+ </args>
54
+ </my_customer>
55
+ </routers>
56
+ </frontend>
57
+
58
+ <global>
59
+ <rewrite>
60
+ <my_customer_account>
61
+ <from><![CDATA[#^/account/#]]>
62
+ </from>
63
+ <to>/customer/account/</to>
64
+ </my_customer_account>
65
+
66
+ <my_customer_address>
67
+ <from><![CDATA[#^/address/#]]>
68
+ </from>
69
+ <to>/customer/address/</to>
70
+ </my_customer_address>
71
+ </rewrite>
72
+ </global> -->
73
+ <!--Procedure 2 to overwrite controller -->
app/code/community/Magento4u/Customer/sql/magento4u_customer_setup/install-1.0.0.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //Procedure 1
4
+ $installer = $this;
5
+ /* @var $installer Mage_Customer_Model_Entity_Setup */
6
+
7
+ $installer->startSetup();
8
+
9
+ $installer->addAttribute(
10
+ 'customer', 'profession', array(
11
+ 'group' => 'Default',
12
+ 'type' => 'varchar',
13
+ 'label' => 'Profession',
14
+ 'input' => 'text',
15
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
16
+ 'required' => 0,
17
+ 'visible_on_front' => 1,
18
+ 'used_for_price_rules' => 0,
19
+ 'adminhtml_only' => 1,
20
+ )
21
+ );
22
+
23
+ //Mage::getSingleton('eav/config')->getAttribute('customer', 'profession')
24
+ // ->setData('used_in_forms', array('adminhtml_customer'))->save();
25
+
26
+
27
+ $installer->endSetup();
28
+
29
+ ////Procedure 2
30
+ //$installer = $this;
31
+ //$installer->startSetup();
32
+ //
33
+ //
34
+ //$installer->addAttribute("customer", "profession", array(
35
+ // "type" => "varchar",
36
+ // "backend" => "",
37
+ // "label" => "Profession",
38
+ // "input" => "text",
39
+ // "visible" => true,
40
+ // "required" => false,
41
+ // "default" => "",
42
+ // "frontend" => "",
43
+ // "unique" => false,
44
+ // "note" => ""
45
+ //));
46
+ //
47
+ //$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "profession");
48
+ //
49
+ //$used_in_forms = array();
50
+ //
51
+ //$used_in_forms[] = "adminhtml_customer";
52
+ //$attribute->setData("used_in_forms", $used_in_forms)
53
+ // ->setData("is_used_for_customer_segment", true)
54
+ // ->setData("is_system", 0)
55
+ // ->setData("is_user_defined", 1)
56
+ // ->setData("is_visible", 0)
57
+ // ->setData("sort_order", 100);
58
+ //
59
+ //$attribute->save();
60
+ //
61
+ //$installer->endSetup();
app/design/frontend/default/default/layout/magento4u_customer.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <customer_account_edit translate="label">
4
+ <reference name="my.account.wrapper">
5
+ <block type="customer/form_edit" name="customer_edit" template="magento4u/customer/form/edit.phtml"/>
6
+ </reference>
7
+ </customer_account_edit>
8
+ </layout>
app/design/frontend/default/default/template/magento4u/customer/form/edit.phtml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="page-title">
28
+ <h1><?php echo $this->__('Edit Account Information') ?></h1>
29
+ </div>
30
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
31
+ <form action="<?php echo $this->getUrl('customer/account/editPost') ?>" method="post" id="form-validate">
32
+ <div class="fieldset">
33
+ <?php echo $this->getBlockHtml('formkey') ?>
34
+ <h2 class="legend"><?php echo $this->__('Account Information') ?></h2>
35
+ <ul class="form-list">
36
+ <li class="fields">
37
+ <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
38
+ </li>
39
+ <li>
40
+ <label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
41
+ <div class="input-box">
42
+ <input type="text" name="email" id="email" value="<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text required-entry validate-email" />
43
+ </div>
44
+ </li>
45
+ <li>
46
+ <label for="profession"><?php echo $this->__('Profession') ?></label>
47
+ <div class="input-box">
48
+ <input type="text" name="profession" id="profession" value="<?php echo $this->htmlEscape($this->getCustomer()->getProfession()) ?>" title="<?php echo $this->__('Profession') ?>" class="input-text" />
49
+ </div>
50
+ </li>
51
+ <?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
52
+ <?php if ($_dob->isEnabled()): ?>
53
+ <li><?php echo $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?></li>
54
+ <?php endif ?>
55
+ <?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
56
+ <?php if ($_taxvat->isEnabled()): ?>
57
+ <li><?php echo $_taxvat->setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?></li>
58
+ <?php endif ?>
59
+ <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
60
+ <?php if ($_gender->isEnabled()): ?>
61
+ <li><?php echo $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?></li>
62
+ <?php endif ?>
63
+ <li class="control">
64
+ <input type="checkbox" name="change_password" id="change_password" value="1" onclick="setPasswordForm(this.checked)" title="<?php echo $this->__('Change Password') ?>"<?php if ($this->getCustomer()->getChangePassword() == 1): ?> checked="checked"<?php endif; ?> class="checkbox" /><label for="change_password"><?php echo $this->__('Change Password') ?></label>
65
+ </li>
66
+ </ul>
67
+ </div>
68
+ <div class="fieldset" style="display:none;">
69
+ <h2 class="legend"><?php echo $this->__('Change Password') ?></h2>
70
+ <ul class="form-list">
71
+ <li>
72
+ <label for="current_password" class="required"><em>*</em><?php echo $this->__('Current Password') ?></label>
73
+ <div class="input-box">
74
+ <input type="password" title="<?php echo $this->__('Current Password') ?>" class="input-text" name="current_password" id="current_password" />
75
+ </div>
76
+ </li>
77
+ <li class="fields">
78
+ <div class="field">
79
+ <label for="password" class="required"><em>*</em><?php echo $this->__('New Password') ?></label>
80
+ <div class="input-box">
81
+ <input type="password" title="<?php echo $this->__('New Password') ?>" class="input-text validate-password" name="password" id="password" />
82
+ </div>
83
+ </div>
84
+ <div class="field">
85
+ <label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm New Password') ?></label>
86
+ <div class="input-box">
87
+ <input type="password" title="<?php echo $this->__('Confirm New Password') ?>" class="input-text validate-cpassword" name="confirmation" id="confirmation" />
88
+ </div>
89
+ </div>
90
+ </li>
91
+ </ul>
92
+ </div>
93
+ <div class="buttons-set">
94
+ <p class="required"><?php echo $this->__('* Required Fields') ?></p>
95
+ <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
96
+ <button type="submit" title="<?php echo $this->__('Save') ?>" class="button"><span><span><?php echo $this->__('Save') ?></span></span></button>
97
+ </div>
98
+ </form>
99
+ <script type="text/javascript">
100
+ //<![CDATA[
101
+ var dataForm = new VarienForm('form-validate', true);
102
+ function setPasswordForm(arg){
103
+ if(arg){
104
+ $('current_password').up(3).show();
105
+ $('current_password').addClassName('required-entry');
106
+ $('password').addClassName('required-entry');
107
+ $('confirmation').addClassName('required-entry');
108
+
109
+ }else{
110
+ $('current_password').up(3).hide();
111
+ $('current_password').removeClassName('required-entry');
112
+ $('password').removeClassName('required-entry');
113
+ $('confirmation').removeClassName('required-entry');
114
+ }
115
+ }
116
+ <?php if ($this->getCustomer()->getChangePassword()): ?>
117
+ setPasswordForm(true);
118
+ <?php endif; ?>
119
+ //]]>
120
+ </script>
app/etc/modules/Magento4u_Customer.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Magento4u_Customer>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ </Magento4u_Customer>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Magento4u_CustomerAttribute</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Add custom attribute to customer entity</summary>
10
+ <description>This extension add custom attribute "profession" to the customer entity. Edit operation is also available in Account Information screen.</description>
11
+ <notes>First review release</notes>
12
+ <authors><author><name>Suman Kar</name><user>magento4u</user><email>suman.jis@gmail.com</email></author></authors>
13
+ <date>2013-10-02</date>
14
+ <time>09:21:49</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Magento4u_Customer.xml" hash="392b13cc5084348110e4807fc5fb0782"/></dir></target><target name="magecommunity"><dir name="Magento4u"><dir name="Customer"><dir name="controllers"><file name="AccountController.php" hash="5dd597e0896f59869850a1e0b825552a"/></dir><dir name="etc"><file name="config.xml" hash="974481239739c47d683b1061a3cfc4aa"/></dir><dir name="sql"><dir name="magento4u_customer_setup"><file name="install-1.0.0.php" hash="61527f6c60674f79852070ce890f122e"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="magento4u_customer.xml" hash="6278668aa7a41bc75d7fbe9ae24df0eb"/></dir><dir name="template"><dir name="magento4u"><dir name="customer"><dir name="form"><file name="edit.phtml" hash="eb2a82ad1d0fea1058d368a244f244c6"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.1</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.8.0.0</max></package></required></dependencies>
18
+ </package>