Magento edit custom attribute from user edit screen on front end - magento

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');

Related

Modifying a model property of textarea in a View in ASP.NET Core

I have a View in ASP.NET Core application where I have a form:
<div class="form-group">
<label asp-for="#Model.Property" class="col-md-2 control-label">Description</label>
<div class="col-md-10">
<textarea asp-for="#Model.Property" class="form-control" rows="10" data-val-maxlength-max="1000"></textarea>
<span asp-validation-for="#Model.Property" class="text-danger" />
</div>
</div>
I want to make textarea empty and Not to have the value from Model. I don't see any value property on this textarea.
Is it possible to have textarea mapped to #Model.Property but Not display it?
I'll be using this textarea for POST only and I don't want to display anything for GET. But I want to have other properties fetched so that's why I need the model in GET.
I also tried to change the Model property in controller before sending, but this model is a part of a DBSet and if I modify in controller then the DBSet gets affected.
Javascript is another option but I want to avoid that.
I had a look at How to overwrite one model property in ASP.Net core but this is not convincing.
Thank you.

Adding additional field to registration form in Magento 1.9

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)

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.

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.

How to pre populate my custom form in magento

I've created a custom form, similar to a customer registration form, in Magento.
i want to prepopulate this form when an error messages arises.
Does anyone know how I can prepopulate a custom form in Magento?
Without seeing you code it is hard to say which method will method will work, but one of these method should work.
Using JavaScript Validation - client side validate, only post if all require info is correct
<form name="my-form" id="my-form" method="post">
<label for="username">
< ?php echo $this->__("User name") ?> <span>*</span></label><br />
<input type="text" id="username" name="username" class="input-text required-entry"/>
.....
</form>
<script type=”text/javascript”>
//< ![CDATA[
var customForm = new VarienForm('my-form');
//]]>
</script>
See a list of all the validation class name
Repopulate field
To get a list of all the post variable information that the customer fill out
Mage::app()->getRequest()->getPost();
To get a form field (eg. <input type='text' name='firstname' ... />)
Mage::app()->getRequest()->getPost('firstname');
So in you .phtml try (this will not work if you doing a redirect on error)
<input type='text' name='firstname' value="<?php echo Mage::app()->getRequest()->getPost('firstname');?>" />
If the above doesnt work then you need the save the post info into a session.
In your controller if validation fail save the information to customer session
Mage::getSingleton( 'customer/session' )->setData( 'yourFormName', Mage::app()->getRequest()->getPost() );
In your phtml template, print the data if 'yourFormName' variable session exist.

Resources