Add field to Edit Account form in Magento - 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?

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" />

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

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.

Move tags section out of the tabs in Magento?

On this page, I'm trying to move the tags (list of tags and tags form) out of the tabs to the open area immediately before the Reviews section.
I copied everything from the /template/tag/list.phtml to /template/catalog/product/view.phtml:
<div class="box-collateral box-tags">
<h2><?php echo $this->__('Product Tags') ?></h2>
<?php echo $this->getChildHtml('list_before')?>
<?php if( $this->getCount() ): ?>
<h3><?php echo $this->__('Other people marked this product with these tags:') ?></h3>
<ul id="<?php echo $this->getUniqueHtmlId('product-tags_'); ?>" class="product-tags">
<?php echo $this->renderTags('<li>%2$s (%3$s)</li>') ?>
</ul>
<script type="text/javascript">
decorateGeneric($("<?php echo $this->getUniqueHtmlId('product-tags_'); ?>").select('li'), ['first', 'last']);
</script>
<?php endif; ?>
<form id="addTagForm" action="<?php echo $this->getFormAction(); ?>" method="get">
<div class="form-add">
<label for="productTagName"><?php echo $this->__('Add Your Tags:') ?></label>
<div class="input-box">
<input type="text" class="input-text required-entry" name="productTagName" id="productTagName" />
</div>
<button type="button" title="<?php echo $this->__('Add Tags') ?>" class="button" onclick="submitTagForm()">
<span>
<span><?php echo $this->__('Add Tags') ?></span>
</span>
</button>
</div>
</form>
<p class="note"><?php echo $this->__("Use spaces to separate tags. Use single quotes (') for phrases.") ?></p>
<script type="text/javascript">
//<![CDATA[
var addTagFormJs = new VarienForm('addTagForm');
function submitTagForm(){
if(addTagFormJs.validator.validate()) {
addTagFormJs.form.submit();
}
}
//]]>
</script>
</div>
While the form is correctly showing, the tags are not.
I guess it's something to do with the "$this->getCount()". So how can I get $this for tags in view.phtml? Or how can I make this work?
Thanks a lot!
it cannot work if you copied code from template tag/list.phtml to catalog/product/view.phtml because behind of catalog/product/view.phtml is a block which doesnt support same set of methods as block behind tag/list.phtml.
I suggest to move tag_list block inside of product_view block in layout XML. And then in catalog/product/view.phtml you can use something like
<?php echo $this->getChildHtml('tag_list'); ?>
which would print content of tag/list.phtml.
Or if you dont want to move block in layout xmls then you can use something like
<?php echo $this->getLayout()->getBlock('tag_list')->toHtml(); ?>
but it's not so nice and clean :) I suggest to go with option one. Some resources how to work with layout is available in Magento Commerce site.

Resources