Magento 1.7 - Remove fields from registration in /customer/account/create/ - magento

I want to remove fields from Registration (/customer/account/create/). How can I do this?
is there some way without get into files of the store (e.g. hiding these fields)?

You should update some fields in the DB.
For example. I need to remove last name from registration form. It's a requried field.
So I created own module with sql update file to change field parameters:
upgrade-1.0.0.1-1.0.0.2.php
/* #var $installer Mage_Customer_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();
// SELECT attribute_id, entity_type_id FROM eav_attribute where attribute_code = 'lastname'
// SELECT * FROM customer_eav_attribute where attribute_id in (SELECT attribute_id FROM eav_attribute where attribute_code = 'lastname')
$options = unserialize('a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}');
if (isset($options['min_text_length'])) unset($options['min_text_length']);
$installer->addAttribute('customer', 'lastname', array(
'validate_rules' => serialize($options),
'required' => false
));
$installer->addAttribute('customer_address', 'lastname', array(
'validate_rules' => serialize($options),
'required' => false
));
$installer->endSetup();
After that you should hide this field using html+css or js
UPDATE:
Edit file /app/design/frontend/default/YOURTHEME/template/customer/widget/name.phtml to change your registration form. In my case I commented out html block there:
<?php /*if ($this->showMiddlename()): ?>
<?php $isMiddlenameRequired = $this->isMiddlenameRequired(); ?>
<div class="field name-middlename">
<label for="<?php echo $this->getFieldId('middlename')?>"<?php echo $isMiddlenameRequired ? ' class="required"' : '' ?>><?php echo $isMiddlenameRequired ? '<em>*</em>' : '' ?><?php echo $this->getStoreLabel('middlename') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('middlename')?>" name="<?php echo $this->getFieldName('middlename')?>" value="<?php echo $this->escapeHtml($this->getObject()->getMiddlename()) ?>" title="<?php echo $this->getStoreLabel('middlename') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('middlename') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
<?php endif; */?>
<!--<div class="field name-lastname">
<label for="<?php echo $this->getFieldId('lastname')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('lastname') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo $this->getStoreLabel('lastname') ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>-->
Also you could add some class to <div class="field name-middlename"> and <div class="field name-lastname">. This class should has css property "display:none;".

Somehow I got it to work. This is want I did and I request you to try it and check if it solves the issue.
Open Magento DB and go to the table core_config_data.
Search for the path - customer/address/middlename_show.
Edit Value field for customer/address/middlename_show and change it to 1 . Generally, this will be 0 (zero) by default.
Save the table.
Clear Cache. Preferably delete the folder Cache and Session present in var folder.
Login to Magento admin and go to the following location:
System --> Configuration --> CUSTOMERS --> Customer Configuration
Under "Name and Address Options" tab, now the option for "Show Middle Name (initial)" will be shown as "Yes".
Change it to "No".
Save Config and clear Cache.

Related

Magento Save Value in Custom Attribute of Customer from one page checkout (billing.phtml)

I have made one attribute for customer registration. It is working fine on registration. I am getting problem on one page checkout. Like normal registration, i am also taking value from customer during one step checkout registration but problem is that it doesn't store the value in attribute. thank you in advance
code of billing.phtml which display textbox for attribute to take value from user
<li class="fields">
<div class="field">
<label for="<?php echo $attribute->getAttributeCode(); ?>" <?php if($attribute->getIsRequired()):?>class="required"><em>*</em> <?php else :?>><?php endif;?><?php echo $this->__($frontEndLabel) ?></label>
<div class="input-box">
<?php if($attribute->getFrontendInput()== 'text'):?>
<input type="text" name="billing[test]" id="billing:<?php echo $attribute->getAttributeCode(); ?>" title="<?php echo $this->__($frontEndLabel); ?>" class="input-text <?php echo $fieldRequiredClass; ?> <?php echo $fieldFrontendClass ;?>" />
<?php endif ?>
</div>
</div>
<?php endif ?>
<?php endforeach ?>
</li>
Just Update following code in your config.xml and check it
<fieldsets>
<checkout_onepage_quote>
<attributename>
<to_customer>*</to_customer>
</attributename>
</checkout_onepage_quote>
</fieldsets>

How To show product quantity in dropdown Magento

I want to show Product quantity in dropdown like 10,20,30 for according to product in magento please help what are i do
please help
thanks
I would recommend you create a new numeric custom attribute for your products so you can define the packsize/order multiple for each product. Then go to this file;
app/design/frontend/YOURFOLDER/YOURTHEME/template/catalog/product/view/addtocart.phtml
In this file, find this code;
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="1<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php endif; ?>
And replace it with this;
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<?php
$qtymultiple = $_product->getData('your_attribute_code'); // Add your attribute_id here
if(($qtymultiple == 1) || (!$qtymultiple)) { // No need to anything ?>
<input type="text" name="qty" id="qty" maxlength="12" value="1<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php } else { //qty multiple requirement ?>
<select name="qty" id="qty" maxlength="12">
<?php
$countme = 1;
while ($countme < 101) { // Define how many multiples of the number to offer
echo '<option value="'.($qtymultiple*$countme).'">'.($qtymultiple*$countme).'</option>';
$countme++;
} ?>
</select>
<?php } ?>
<?php endif; ?>
This will show a select box with multiples instead of the free type qty box for products that have a value the custom attribute.

Email Validation in Checkout Page in Magento

I need to change the email validation of Magento's Checkout page (Checkout as a Guest).
The problem is the default style of input box contains character support only. When I tried to input email with numbers, it doesn't accept and display number.
So I need a proper validation with regard to its email. The email address input box should also accept characters with numbers.
Thanks,
I tried to check this Code:
File location: onepage/billing.phtml
<?php if(!$this->isCustomerLoggedIn()): ?>
<div class="field">
<label for="billing:email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<div class="input-box">
<input type="text" name="billing[email]" id="billing:email" value="<?php echo $this->escapeHtml($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
</div>
</div>
<?php endif; ?>
File location: validation.js
['validate-email', 'Please enter a valid email address. For example johndoe#domain.com.', function (v) {
//return Validation.get('IsEmpty').test(v) || /\w{1,}[#][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
//return Validation.get('IsEmpty').test(v) || /^[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9][\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9\.]{1,30}[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9]#([a-z0-9_-]{1,30}\.){1,5}[a-z]{2,4}$/i.test(v)
return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*#([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v)
}],
I found the solution.
File Location: template/webtexgiftregisrty/billing.phtml
On th field box of email address, insert the string data types inside the class validation.
Here's the code:
<input type="text" name="billing[email]" id="billing:email" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="string input-block-level input-text validate-email required-entry billing-email" />

Add field to Edit Account form in Magento

I'm adding a field to the template customer/form/edit.phtml. I used this code :
<li>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('customer','code_magique');
?>
<label for="code_magique" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('Code') ?></label>
<div class="input-box">
<input type="text" name="code_magique" id="code_magique" value="<?php echo $this->htmlEscape($this->getCustomer()->getData("code_magique")) ?>" title="<?php echo $this->__('Code') ?>" class="input-text" />
</div>
</li>
This display a field with my "code_magique" attribute inside but when i try to modify this attribute, it doesn't work, did I forget something?
I did a quick look at AccountController.php, and it seems there is some postprocessing of form data, not the simple $model->addData($post);
Try hooking to customer_save_before event and adding your data manually.
Hopefully you know how to create anobserver and add data to model object?

Change gender dropdown to radio button in magento

Today i started working in registration form in magento site. As you know by default it's having gender drop down. I need to change that to checkbox.
So far i went to register.phtml file, and tried to add <input type="radio" ...../> select files, but this didn't worked.
Did anyone know how to solve this !
please give me some suggestions to so this....
Do not forget the validation!
<div class="input-box">
<?php
$options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
$value = $this->getGender();
$_last = count($options);
$_index = 0;
?>
<?php foreach ($options as $option):?>
<?php if($option['value'] != ''): ?>
<input id="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>"
class="radio<?php if ($this->isRequired() && $_index == $_last - 1):?> validate-one-required<?php endif; ?>"
type="radio" title="<?php echo $option['label'] ?>"
value="<?php echo $option['value'] ?>" name="<?php echo $this->getFieldName('gender')?>"
<?php if ($option['value'] == $value) echo ' checked="checked"' ?>>
<label for="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>">
<?php echo $option['label'] ?>
</label>
<?php endif; ?>
<?php $_index++; ?>
<?php endforeach;?>
</div>
Magento uses widgets on registration form. In fact in template register.phtml you can see lines:
<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
<?php if ($_gender->isEnabled()): ?>
<li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
<?php endif ?>
This particular widget can be found in template/customer/widget directory. So in order to change select into radio buttons, copy it (template) to your theme and modify, e.g.:
<div class="input-box">
<label><?php echo $this->__('Gender'); ?></label>
<?php $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();?>
<?php $value = $this->getGender();?>
<?php foreach ($options as $option):?>
<input type="radio" name="<?php echo $this->getFieldName('gender')?>" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' selected="selected"' ?> /><?php echo $option['label'] ?>
<br />
<?php endforeach;?>
</div>
Hope didn't make any typo.

Resources