Magento - Disable customer of Changing / Reset email - email

For security reasons I need to disable the possibility in form the user to change his email. Once set it can't be change. How can I do this?

I have found :
http://www.magentocommerce.com/boards/viewthread/8622/
Maybe usefull for someone ...

Make the following changes:
In template/customer/account/dashboard/info.phtml
<div class="inner-head">
<h5><?php echo $this->__('Contact Information') ?></h5>
Edit
</div>
<p>
<?php echo $this->htmlEscape($this->getCustomer()->getFirstname()) ?>
<?php echo $this->htmlEscape($this->getCustomer()->getLastname()) ?><br />
<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?><br />
<?php echo $this->__('Change Password') ?>
</p>
and Replace with:
<div class="inner-head">
<h5><?php echo $this->__('Contact Information') ?></h5><br />
</div>
<p>
<?php echo $this->htmlEscape($this->getCustomer()->getFirstname()) ?>
<?php echo $this->htmlEscape($this->getCustomer()->getLastname()) ?><br />
<?php echo $this->__('Change Password') ?>
</p>
Extracted and adapted from the magento community forums.

The problem was that we had an extension that override the user model/controller/view, example: social login, and because we decided not to use it we Disable it in the advanced settings.
Because it was disable, the list of users was not showing in the back-end, but I could create a new customer, yet in the New customer view the Addresses were not showing either.
So, we activated all the extensions again and suddenly the customers list appears. So like this we found out which extension was breaking and fixed it.

In file :
app\code\core\Mage\Customer\controllers\AccountController.php
/**
* Change customer password action
*/
public function editPostAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/*/edit');
}
if ($this->getRequest()->isPost()) {
$customer = Mage::getModel('customer/customer')
->setId($this->_getSession()->getCustomerId())
->setWebsiteId($this->_getSession()->getCustomer()->getWebsiteId());
$fields = Mage::getConfig()->getFieldset('customer_account');
$data = $this->_filterPostData($this->getRequest()->getPost());
//=========
// ADD THAT // customer cannot change his email // Le customer ne peut pas modifier son email
if(isset($data['email'])){
$data['email'] = $this->_getSession()->getCustomer()->getData('email');
}
//========END
foreach ($fields as $code=>$node) {
if ($node->is('update') && isset($data[$code])) {
$customer->setData($code, $data[$code]);
}
}
$errors = $customer->validate();
if (!is_array($errors)) {
$errors = array();
}

Related

Magento 2.2 - Append Attribute Name To Product Name (H1)

This is driving me nuts, I created a module with a helper:
namespace MyNamespace\MyModule\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $registry;
public function __construct
(
\Magento\Framework\Registry $registry,
\Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet
) {
$this->registry = $registry;
$this->attributeSet = $attributeSet;
}
public function getTitle()
{
$this->product = $this->registry->registry('product');
$product_name = $this->product->getName();
$attributeSetRepository = $this->attributeSet->get($this->product->getAttributeSetId());
if ($attributeSetRepository->getAttributeSetName() == "Default Engine Component"){
$engine = $this->product->getAttributeText('engine_select');
if (!is_array($engine)){
return "$engine $product_name";
}
}
return $product_name;
}
}
...and this works as it should. Then I added the following to:
/app/design/frontend/vendor/theme/Magento_Catalog/layout/catalog_product_view.xml
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument name="title" xsi:type="helper" helper="MyNamespace\MyModule\Helper\Data::getTitle"></argument>
</action>
</referenceBlock>
...but it changes nothing on the product page. I know it's getting called as I can echo out the vars and they show at the top of the page, but it seems that the XML isn't doing what I hoped it would.
Anyone got any ideas?
So, tried multiple variations of achieving what I wanted but in the end, I created a template under Magento_Catalog/templates/product (in my theme), which was based of the magento-theme title.phtml and then modified the page.main.title block in the catalog_product_view layout file.
The template code may look a bit odd (getAttribute and then getAttributeText) but there's no error handling for getAttributeText and with getAttribute, if an attribute has multiple values, it's returned in a string, not an array like getAttributeText. It would have been nicer if I could have made sure the value was always present by checking which attribute set was being used but although getAttributeSetId is part of the product model, it's not available in the product/view interceptor and tbh, I've given up on trying to figure out how all that works!
Anyway, this has taken far more hours than I'd care to admit to figure out so here's the code, hope it helps someone!
Template:
<?php
$product = $block->getProduct();
$product_name = $product->getName();
$attr_exists = $product->getResource()->getAttribute('attr_code');
$title = $product_name;
$cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : '';
if ($attr_exists){
$attr_name = $product->getAttributeText('attr_code');
if (!is_array($attr_name)){
$title = "$attr_name $product_name";
}
}
?>
<?php if ($title): ?>
<div class="page-title-wrapper<?= /* #escapeNotVerified */ $cssClass ?>">
<h1 class="page-title"
<?php if ($block->getId()): ?> id="<?= /* #escapeNotVerified */ $block->getId() ?>" <?php endif; ?>
<?php if ($block->getAddBaseAttributeAria()): ?>
aria-labelledby="<?= /* #escapeNotVerified */ $block->getAddBaseAttributeAria() ?>"
<?php endif; ?>>
<?= /* #escapeNotVerified */ $title ?>
</h1>
<?= $block->getChildHtml() ?>
</div>
<?php endif; ?>
Layout:
<block name="page.main.title" class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/product-h1.phtml" />

Yii model method addError is not working

I have an issue about displaying error in a yii form.
This is my controller:
$custom_user->attributes = $_POST['CustomUser'];
if($custom_user->validate())
{
...
save
...
}
else
{
$custom_user->addError('username', 'Error X');
$this->redirect(array('access/index'),
array('user'=>$custom_user,
'tab'=>$tab_person,
));
}
This is my index view:
<?php $form=$this->beginWidget('BaseForm', array(
'id'=>'user-form',
'action'=>Yii::app()->createUrl('person/createUser'))); ?>
<?php echo $form->errorSummary($user);?>
<div class="right">
<?php echo $form->textField($user,'username',array('size'=>30,'maxlength'=>255)); ?>
<br/><?php echo $form->error($user,'username'); ?>
</div>
...
...
<div style="float: left;">
<?php echo $form->dateField($user,'valid_from',null,'valid_from_formated'); ?>
<br/><?php echo $form->error($user,'valid_from'); ?>
</div>
Here is my BaseForm
public $enableClientValidation = true;
public $enableAjaxValidation = true;
public $clientOptions = array( 'hideErrorMessage'=>false,
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'validateOnType'=>false,
'afterValidateAttribute' => 'js:enableSubmitAV',
'afterValidate' => 'js:submitFormAV'); // always fires this after
Here is the problem:
"$form->errorSummary($user);" is empty
and noting is display under "$form->error($user,'username');"
But if I look in Firebug I can see that under "response" tab:
{"CustomUser_valid_until":["Valid Until must be
greater than \"20121127\"."]}
it's a good thing because it means my rules work great. But none errors are displayed. Not this one and even the error "Error X" I add in my controller is not diplayed... (I'm sure I pass throught the else statement, i tried it).
So, does anyone could have an idea?
Thanks for reading me and sorry for my approximate English.
Have a good day :)
Michaƫl
You are redirecting, meaning a whole new request is called, and any responses are deleted.
Why are you redirecting to "access/index" rather than just calling the view? If you do need to redirect, which you definitely can, try setting a flash variable as it is store in the browser's session and will persist through redirects:
Yii::app()->user->setFlash('username', "Error X");
Then on the access/index page:
<?php if(Yii::app()->user->hasFlash('username')):?>
<div class="error">
<?php echo Yii::app()->user->getFlash('username'); ?>
</div>
<?php endif; ?>
Ok finally I got what was wrong. It was the configuration in my CActiveForm. The option "enableAjaxValidation" seems to make some problem when it's on "true". I don't know really why but I've already had this problem with a login form befor. I'll try to work out this problem.

Handle two different forms in a single page

So I want to handle two forms on one single page, and I've got some problems to do it; I've got a module named 'contact', here is the indexSucces.php
<div id="registerForm">
<form action="<?php echo url_for('contact'); ?>" method="post" id="loginForm">
<?php foreach ($loginForm as $widget): ?>
<?php if(!$widget->isHidden()) { ?>
<?php echo $widget->renderRow(); ?>
<?php } else { ?>
<?php echo $widget->render() ?>
<?php } ?>
<?php endforeach; ?>
<br/><input type="submit" id="loginSubmit" class="btn primary" value="<?php echo __('Envoyer'); ?>" />
</form>
</div>
<div id="registerForm">
<form action="<?php echo url_for('contact'); ?>" method="post" id="registerForm">
<?php foreach ($registerForm as $widget): ?>
<?php if(!$widget->isHidden()) { ?>
<?php echo $widget->renderRow(); ?>
<?php } else { ?>
<?php echo $widget->render() ?>
<?php } ?>
<?php endforeach; ?>
<br/><input type="submit" id="registerSubmit" class="btn primary" value="<?php echo __('Envoyer'); ?>" />
</form>
</div>
Is it possible to handle that in a single action page ? I need to know the way on how to it, I'm stuck since yesterday. For exemple, when I want to submit the first form, it wants to submit the second form with.
Someone can provide me an exemple ? I can post my sh** action page if you want to see how I tried to handle that.
Thanks in advance !
EDIT:
I made this code according to your advice :
public function executeIndex(sfWebRequest $request)
{
$this->loginForm = new loginForm();
$this->registerForm = new registerForm();
$this->processForm($request, $this->loginForm, $this->registerForm);
}
public function processForm(sfWebRequest $request, sfForm $loginForm, sfForm $registerForm)
{
if($request->hasParameter('login'))
{
if($request->isMethod('post'))
{
$loginForm->bind($request->getParameter($loginForm->getName()));
if($loginForm->isValid())
{
$this->redirect('payement');
}
}
} elseif ($request->hasParameter('register'))
{
if($request->isMethod('post'))
{
$registerForm->bind($request->getParameter($registerForm->getName()));
if($registerForm->isValid())
{
$this->redirect('payement');
}
}
}
}
The registerForm is submitting correctly, I can see the errors I've made in the form etc, and if it's correct, it is correctly redirected. But when I submit the loginForm, here is the error :
Argument 1 passed to sfForm::bind() must be an array, string given : on this line
$loginForm->bind($request->getParameter($loginForm->getName()));
Why ?
Yes, you can.
Add a name attribute to your buttons (i.e. login and register), and modify your action to:
if ($request->hasParameter("login")) {
// handle login
}
elseif ($request->hasParameter("register")) {
// handle register
}

Creating child CMS pages in Magento

I would like to create a subordinate set of CMS pages in Magento so that the breadcrumb navigation at the top of the page looks like this:
Home > Parent CMS Page > Child CMS Page
Even though I can specify a hierarchical relationship with the URL key field, it seems to be that all CMS pages in Magento are listed in the root directory by default:
Home > Child CMS Page
Any ideas?
You are right, there is no hierarchy of CMS pages in Magento. The best solution would be to create a real hierarchy by adding a parent_id to CMS pages and modifying the CMS module to handle nested URLs and breadcrumbs. But that requires a lot of coding.
A quick-and-dirty hack is to modify the breadcrumbs manually on each subpage by adding something like this to the layout update XML:
<reference name="root">
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb">
<crumbName>home</crumbName>
<crumbInfo><label>Home page</label><title>Home page</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>myparentpage</crumbName>
<crumbInfo><label>My Parent Page</label><title>My Parent Page</title><link>/myparentpage/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>mysubpage</crumbName>
<crumbInfo><label>My Sub Page</label><title>My Sub Page</title></crumbInfo>
</action>
</block>
</reference>
I had the same problem with breadcrumbs and cms pages a few days ago check here ->
Similar to Anders Rasmussen post I edited every cms page manually
In breadcrumbs.phtml I added a little condition to define if a Page is a CMS page (thanks to Alan Storm) and remove standard crumb(s) and added new crumbs via xmllayout.
<?php
if($this->getRequest()->getModuleName() == 'cms'){
unset($crumbs['cms_page']);
}
?>
xml:
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>cms_page_1st_child</crumbName>
<crumbInfo><label>1st child</label><title>1st child</title><link>/1st child/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>cms_page_2nd_child</crumbName>
<crumbInfo><label>2nd child</label><title>2nd child</title></crumbInfo>
</action>
</reference>
hope that helps,
Rito
For enterprise (version 1.12) use this code at following file, location is:
default->template->page->html->breadcrumb.phtml.
<?php
$cms_id = Mage::getSingleton('cms/page')->getPageId();
if($cms_id):
if($_SERVER['REQUEST_URI']) {
$trim_data = substr($_SERVER['REQUEST_URI'],1);
$data = explode('/',$trim_data);
}
$cms_collection = array();
$url_full = '';
$cms_enterprise = '';
foreach($data as $identifier) {
$page_data = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('identifier', $identifier);
if($page_data) {
foreach($page_data as $single) {
if($single->getContentHeading() != null) {
if($single->getPageId()) {
$cms_enterprise = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->addFieldToFilter('page_id', $single->getPageId());
foreach($cms_enterprise as $single_enterprise) {
$url_full = $single_enterprise->getRequestUrl();
}
}
$cms_collection[] = array($single->getTitle(), $single->getContentHeading(), $url_full );
} else {
if($single->getPageId()) {
$cms_enterprise = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->addFieldToFilter('page_id', $single->getPageId());
foreach($cms_enterprise as $single_enterprise) {
$url_full = $single_enterprise->getRequestUrl();
}
}
$cms_collection[] = array($single->getTitle(), $single->getTitle(), $url_full );
}
}
}
}
$count = count($cms_collection);
$i = 1;
?>
<?php if(count($cms_collection)): ?>
<div class="breadcrumbs">
<ul>
<li>
<a href="<?php echo $this->getUrl() /*Home*/ ?>" title="<?php echo $this->__('Home'); /*Home Title*/ ?>">
<?php echo $this->__('Home'); /*Home Name*/ ?>
</a>
<span>> </span>
</li>
<?php foreach($cms_collection as $key=>$value): ?>
<?php if($i == $count): ?>
<li>
<strong>
<?php echo $value[1]; /*Name*/ ?>
</strong>
</li>
<?php else: ?>
<li>
<a href="<?php echo $this->getUrl().$value[2] /*Identifier*/ ?>" title="<?php echo $value[0] /*Title*/ ?>">
<?php echo $value[1]; /*Name*/ ?>
</a>
<span>> </span>
</li>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php else: ?>
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>> </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Thanks,
Kashif
This is my solution of the problem. I use custom layout for most of the CMS pages (default/template/page/cmsLayout.phtml) so I heve added following code into the layout file:
<div class="col-main">
<?php
$urlPart=str_replace(Mage::getUrl(),'',Mage::getUrl('', array('_current' => true,'_use_rewrite' => true)));
$urlPart=explode('/',$urlPart);
$string='';
$return='<div class="breadcrumbs"><ul><li class="home">Home<span> / </span></li>';
$count=count($urlPart);
foreach($urlPart as $value)
{
$count--;
$string.='/'.$value;
$string=trim($string, '/');
$pageTitle = Mage::getModel('cms/page')->load($string, 'identifier')->getTitle();
if($count==0)
$return.='<li><strong>'.$pageTitle.'</strong></li>';
else
$return.='<li>'.$pageTitle.'<span> / </span></li>';
}
echo $return.'</li></ul></div>';
?>
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
update
-oops- this might be an enterprise feature only
There is a built-in CMS page hierarchy option in Magento.
To turn it on:
System > Configuration > General > Content Management > CMS Page Hierarchy - see here
To organise the hierarchy tree:
CMS > Pages > Manage Hierarchy
To manage the position of a page in the tree, after saving a page, go to its "hierarchy tab" - see the screenshot:
In the example the page "Our culture" is a child of "jobs" and not of the root directory
For Magento Enterprise, I have created an extension to solve this. It uses the built in CMS Hierarchy in the backend. The module is called Demac/BananaBread and shouldn't require any hacks or customization.
Direct download: here
Link to article: http://www.demacmedia.com/magento-commerce/introducing-demac_bananabread-adding-cms-breadcrumbs-from-the-hierarchy-in-magento/
I built a custom block as to generate the crumbs (removing the built-in and replacing with the custom one below in the layout):
namespace Uprated\Theme\Block\Html;
class UpratedBreadcrumbs extends \Magento\Framework\View\Element\Template
{
/**
* Current template name
*
* #var string
*/
public $crumbs;
protected $_template = 'html/breadcrumbs.phtml';
protected $_urlInterface;
protected $_objectManager;
protected $_repo;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\UrlInterface $urlInterface,
\Magento\Framework\ObjectManagerInterface $objectManager,
array $data = [])
{
$this->_urlInterface = $urlInterface;
$this->_objectManager = $objectManager;
$this->_repo = $this->_objectManager->get('Magento\Cms\Model\PageRepository');
$this->getCrumbs();
parent::__construct($context, $data);
}
public function getCrumbs() {
$baseUrl = $this->_urlInterface->getBaseUrl();
$fullUrl = $this->_urlInterface->getCurrentUrl();
$urlPart = explode('/', str_replace($baseUrl, '', trim($fullUrl, '/')));
//Add in the homepage
$this->crumbs = [
'home' => [
'link' => $baseUrl,
'title' => 'Go to Home Page',
'label' => 'Home',
'last' => ($baseUrl == $fullUrl)
]
];
$path = '';
$numParts = count($urlPart);
$partNum = 1;
foreach($urlPart as $value)
{
//Set the relative path
$path = ($path) ? $path . '/' . $value : $value;
//Get the page
$page = $this->getPageByIdentifier($path);
if($page) {
$this->crumbs[$value] = [
'link' => ($partNum == $numParts) ? false : $baseUrl . $path,
'title' => $page['title'],
'label' => $page['title'],
'last' => ($partNum == $numParts)
];
}
$partNum++;
}
}
protected function getPageByIdentifier($identifier) {
//create the filter
$filter = $this->_objectManager->create('Magento\Framework\Api\Filter');
$filter->setData('field','identifier');
$filter->setData('condition_type','eq');
$filter->setData('value',$identifier);
//add the filter(s) to a group
$filter_group = $this->_objectManager->create('Magento\Framework\Api\Search\FilterGroup');
$filter_group->setData('filters', [$filter]);
//add the group(s) to the search criteria object
$search_criteria = $this->_objectManager->create('Magento\Framework\Api\SearchCriteriaInterface');
$search_criteria->setFilterGroups([$filter_group]);
$pages = $this->_repo->getList($search_criteria);
$pages = ($pages) ? $pages->getItems() : false;
return ($pages && is_array($pages)) ? $pages[0] : [];
}
Then used a slightly modified .phtml template to display them:
<?php if ($block->crumbs && is_array($block->crumbs)) : ?>
<div class="breadcrumbs">
<ul class="items">
<?php foreach ($block->crumbs as $crumbName => $crumbInfo) : ?>
<li class="item <?php /* #escapeNotVerified */ echo $crumbName ?>">
<?php if ($crumbInfo['link']) : ?>
<a href="<?php /* #escapeNotVerified */ echo $crumbInfo['link'] ?>" title="<?php echo $block->escapeHtml($crumbInfo['title']) ?>">
<?php echo $block->escapeHtml($crumbInfo['label']) ?>
</a>
<?php elseif ($crumbInfo['last']) : ?>
<strong><?php echo $block->escapeHtml($crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $block->escapeHtml($crumbInfo['label']) ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Working fine for me in 2.1

how can strips html tags in joomla

hi i am working on joomla. and i used the latest news module but it emerging a problem that the new display on page having the tags like paragraph i wanna remove that tags from the news
my code is
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php $i=1 ;?>
<?php foreach ($list as $item): ?>
<?php if($i==1) {echo "<div class='latestnews_ttl'> <p>".$item->cat_title." </p></div>";} $i++; ?>
<div class="news_box">
<p style=" padding:0px;"><strong><?php echo $item->text; ?> </strong></p>
<p><?php if(strlen($item->introtext)>100)
{
$txt = str_split($item->introtext, 100);
echo $txt['0']."...";
}
else{
echo $item->introtext;
}
?></p>
<div class='readmore'>read more</div></div>
<?php endforeach; ?>
It will give news with prefix tag "<p>" so please give the solution of it.
thanks in advance
Tried strip_tags() ?
Always remember in Joomla! never to modify core code, always overwrite the core templates by following the following guide http://docs.joomla.org/Tutorial_talk:Template_overrides
1: http://docs.joomla.org/Tutorial_talk:Template_overrides or a quick how to http://www.techportal.co.za/joomla/joomla-tutorials/124-how-to-modify-the-appearance-of-the-category-list-page-without-having-modifications-done-to-the-joomla-core-code
If you do this in the core it will work, but once you may upgrade your changes could be gone.
Since joomla is written in php you could use strip_tags