Adding additional field to registration form in Magento 1.9 - magento

i was using this tutorial to add additional field in Magento 1.9 in Registration form: http://www.fontis.com.au/blog/magento/know-more-about-your-customers-adding-custom-signup-attributes
But unfortunately it not works. I am new in Magento and need some help. I would appreciate step by step instruction on how to create new module in order to be able to add this additional field in current registration form Magento 1.9.

Ok, I just did it, here is how.
Go to http://www.silksoftware.com/magento-module-creator/ and using its Module Creator to create a new module called "YourCustomerAttribute".
Set "Add Customer Attribute" to YES
Make proper inputs and selections as you needed.
Make sure to select the forms you needed the new attributes to be used.
Generate the module.
Upload the module to your Magento folder.
Modify located at app/design/frontend/base/default/template/persistent/customer/form/register.phtml and add:
<div class="input-box">
<label for="YourAttributeName"><?php echo $this->__('YourAttributeName') ?><span class="required">*</span></label><br />
<input type="text" name="YourAttributeName" id="YourAttributeID" value="<?php echo $this->htmlEscape($this->getFormData()->getYourAttributeName()) ?>" title="<?php echo $this->__('YourAttributeName') ?>" class="required-entry input-text" />
</div>
If you want customer to be able to modify the attribute in customer panel, then modify app/design/frontend/base/default/template/customer/form/edit.phtm and add:
<li>
<label for="YourAttributeName" class="required"><em>*</em><?php echo $this->__('YourAttributeName') ?></label>
<div class="input-box">
<input type="text" name="YourAttributeName" id="YourAttributeID" value="<?php echo $this->escapeHtml($this->getCustomer()->getYourAttributeName()) ?>" title="<?php echo $this->__('YourAttributeName') ?>" class="input-text required-entry" />
</div>
</li>
Refresh all caches.

If you want to do it manually, directly via SQL because you only need a quick fix, here is how the values are stored in the DB for Magento 1.9 (might work for M2).
This is not good practice as it is a direct DB manipulation that won't work if you move your theme to another server without using the same DB. There are some use cases in which this might be warranted though ;)
Add a new entry into the 'eav_attribute' table, in this case, to have a checkbox, use
INSERT INTO `eav_attribute`
(`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`)
VALUES
( 1, 'gdpr_accept', NULL, NULL, 'int', NULL, NULL, 'select', 'GDPR', NULL, 'eav/entity_attribute_source_boolean', 1, 1, '0', 0, NULL);
This will add a checkbox entry with the name 'gdpr_accept' (to be used in the form html later) and the title 'GDPR' (will be used when referring to it).
Add a new entry to 'customer_eav_attribute', using the attribute_id of the entry you created in 1.
INSERT INTO `customer_eav_attribute`
(`attribute_id`, `is_visible`, `input_filter`, `multiline_count`, `validate_rules`, `is_system`, `sort_order`, `data_model`)
VALUES
(ATTRIBUTE_ID_FROM_1, 1, NULL, 0, NULL, 0, 100, NULL);
This will add the necessary setting to the new value.
Add a new entry to the 'customer_form_attribute' table, again with the attribute_id from 1.
INSERT INTO `customer_form_attribute`
(`form_code`, `attribute_id`)
VALUES
('customer_account_create', ATTRIBUTE_ID_FROM_1);
This will tell Magento to check for the new checkbox value when validating the registration form.
This step is the same as with the accepted answer, you can now add the checkbox to the form and it will be validated automagically by Magento:
<li class="field gdpraccept">
<div class="input-box">
<input type="checkbox" id="gdpr_accept" name="gdpr_accept" value="1"
title="<?php echo $this->__('Accept the privacy policy') ?>" class="checkbox required-entry">
</div>
<label for="is_subscribed">
<?php echo $this->__('Registering you confirm that you accept our ') ?>
<a href="<?php echo Mage::helper('cms/page')->getPageUrl( 25 ) ?>">
<?php echo $this->__('privacy policy'); ?>
</a>.
</label>
</li>
Note that in this case the id of the page with the privacy policy is 25, it will probably
be different in your case.
This was a simple checkbox case, if you want a different field, with custom validation, have a look at the 'eav_attribute' table, there you can find examples of other fields that have been added.
Or, even better, walk the recommended way and use a module like the http://www.silksoftware.com/magento-module-creator/ is creating (you can do the same thing they do in your own custom module)

Related

How to disable the validation of some fields in Joomla 3 registration

I'm building the website based on Joomla 3. I need to disable the validation of the fields: name, username, password1 (the second, because the first is password2) and email2 and use email1 as username (I installed the plugin Email for user authorization).
I have tried to remove these fields in file components/com_users/models/forms/registration.xml but the validation is still remaining. If I don't remove them but only change the rows required="true" to false for these fields the registration doesn't work at all and any user stored in the DB. How can I disable these fields?
It's not an easy workaround, and you will need some basic knowledge of Joomla and PHP, but I'll try to explain it to you as simple as i can.
>>> Creating view template override
First of all you will need to create your Registration view template override (to keep it Joomla update proof). To do so, create folder /templates/YOUT_TEMPLATE/html/com_users/registration and copy /components/com_users/views/registration/tmpl/default.php file there.
From now on you can modify registration output in your template folder.
>>> Modifying registration form output
By default Joomla takes all fields from form file /components/com_users/models/forms/registration.xml, where they are defined, and outputs them in a view. But if we don't want to use ALL the fields, we need to output fields manually.
My example code only output E-mail and Password fields for registration. Here's a sample code to do so: (default.php file)
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
?>
<div class="grid_8" id="register_block">
<div class="content_block">
<h1>Registracija</h1>
<div class="login<?php echo $this->pageclass_sfx?>">
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration2.register'); ?>" method="post" enctype="multipart/form-data">
<div>
<div class="login-fields">
<label id="jform_email1-lbl" for="jform_email1">E-mail:</label>
<input type="text" name="jform[email1]" id="jform_email1" value="" size="30">
</div>
<div class="login-fields">
<label id="jform_password1-lbl" for="jform_password1">Password:</label>
<input type="password" name="jform[password1]" id="jform_password1" value="" autocomplete="off" size="30">
</div>
<button type="submit" class="button"><?php echo JText::_('JREGISTER');?></button>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration2.register" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
</div>
</div>
</div>
Please note, that I've also replaced task value from registration.register to registration2.register, I did this to bypass some of validation rules using my own controller.
>>> Creating controller override
Locate file /components/com_users/controllers/registration.php and create a copy of it called registration2.php in same folder.
Open file registration2.php and change It's class name from UsersControllerRegistration to UsersControllerRegistration2
From now on Joomla registration form will use this class to create a new user.
Find a method called register and find this line:
$requestData = JRequest::getVar('jform', array(), 'post', 'array');
This is where Joomla get's registration form data. Add the following lines:
$requestData['name'] = $requestData['email1'];
$requestData['username'] = $requestData['email1'];
$requestData['email2'] = $requestData['email1'];
$requestData['password2'] = $requestData['password1'];
It will add missing registration info, and help you pass validation.
NOTE: This is a sample code, to show the main logic. If anyone has a better solution, I'd be more than happy to hear it.
Following same idea, a simpler solution might be just including hidden inputs with values in com_users\views\registration\tmpl\default.php above
<button type="submit" class="btn btn-primary validate"><?php echo JText::_('JREGISTER');?></button>
add
<input type="hidden" id="jform[username]" name="jform[username]" value="username" />
<input type="hidden" id="jform_name" name="jform[name]" value="name" />
It would pass the validation and you would no longer need to override controllers etc.

Magento update product price

I am trying to customize the magento associated product dropdown menu in frontend.
So far it's working good, But i need somehow to be able to update the price when a user has clicked the radio button. I guess i need to use some jquery stuff? The price is stored in the radio value. Any suggestions? :)
The code i'm currently working with is:
<?php
if($_product->getTypeId() == "configurable"):
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($simple_collection as $simple_product){ ?>
<input type="radio" id="attribute135" name="attribute135" value="<?php echo strip_tags(Mage::helper('core')->currency($simple_product->getPrice())) ?>" /> <?php echo $simple_product->getName();
}
endif;
?>
I ended using:
$_product->setPrice(new price value here)

New added attribute value pass from product detail page to cart, checkout and order

I have added new attributes to the product with multiselect option in admin.
I get the values for the selected attributes from checkbox in view.phtml (product page).
Now, I want to pass these selected checkbox values to the cart page, checkout page and order page. But I am struggling to find an easy way to do so.
Any help is greatly appreciated.
here available_colors is my attribute name
<div class="available_color span10" style="margin:10px 0;">
<?php
$_product->getResource()->getAttribute('available_colors')->getFrontend()->getValue($_product);
$color = $_product->getAttributeText('available_colors');
//print_r ($color);
?>
<h2>Item Color</h2>
<?php foreach ($color as $value): ?>
<label class="span4" style="margin-left:0px;">
<input class="pro_color_<?php echo $value; ?>" name="<?php echo $value; ?>" value="<?php echo $value; ?>" type="checkbox">
<?php echo $value; ?>
</label>
<?php endforeach; ?>
</div>
it display in product page but problem is that
when I add to product add-to-cart attribute value not pass and display in cart, checkout page.
You could use Product Custom Options to acheive this.Select the product to which you want to add custom options .You can find a tab named Custom Options.You can add the options there.
If I understand what you want, you need to store your product attribute through the quote and finally to the order.
You'll need to :
create new attribute (column) on quote and order
fill these new attributes with the user selection when adding product to quote
display it on the checkout (quote attribute value) and on the order page (order attribute value)
For the attribute creation check this link : http://www.atwix.com/magento/custom-product-attribute-quote-order-item/ .
For the display of your attribute on your pages, you just have to adapt your code to check the quote_item or order_item values.

Magento edit custom attribute from user edit screen on front end

I'm using this magento extension http://www.magentocommerce.com/magento-connect/custom-attributes-4340.html to create customer attributes. I'm able to create the attribute and view it in the backend. But I'm unable to edit/update the values when a user logins in via the front end.
This is my code on the edit.phtml page.
<li><?php $attribute = Mage::getModel('eav/config')->getAttribute('customer','height'); ?>
<label for="height"><?=$this->__('Height') ?></label>
<div class="input-box">
<input type="text" name="height" id="height" />
</div>
</li>
I haven't added anything manually to my database or created any modules. Strictly using this extension. Any help would be much appreciated.
in order to save this input in to attribute what you can do is update attribute on form submit.
1) get the value of height on the page where you submit the form. e.g $height_val
2) Now $height_val has the value so you can try this code this will update the attribute's value without saving the whole product instead.
$customer->setHeight($height_val);
$customer->getResource()->saveAttribute($customer, 'height');

Joomla add param to extension

I fix /administrator/components/com_content/models/forms/article.xml
with
<field name="turbobit" type="text"
label="Turbobit" description="Turbobit"
class="inputbox" size="60" />
and /administrator/components/com_content/views/article/tmpl/edit.php
with
<li><?php echo $this->form->getLabel('turbobit'); ?>
<?php echo $this->form->getInput('turbobit'); ?></li>
but when I press save this field doesn't store in database
Where I must fix code more?
in short, you need to add a column named "turbobit" in jos_content table in the database
take a look at my other answer: Add new image field to Joomla 1.7 com_content , which might be helpfull

Resources