I need to use the greeting as "Hello customer_firstname" in Invoice emails.
In the Invoice email template file invoice_new.html file, the following line is written, however it is showing the full name of the customer.
Hello, {{htmlescape var=$order.getCustomerFirstname()}
Try
{{var order.getCustomerFirstname()}}
<h4>Ficou com dúvidas? {{var order.getCustomerFirstname()}}</h4>
I found a solution where I modified the class Mage_Sales_Model_Order a little and added a new Method called "getCustomerOnlyFirstName" as shown below ::
The class "Mage_Sales_Model_Order" can be found in app\code\core\Mage\Sales\Model\Order.php path..
public function getCustomerOnlyFirstName()
{
$name = trim($this->getCustomerName());
$pos = strpos($name," ");
if($pos !== false) /// FirstName can be extracted
{
$name = trim(substr( $name, 0, $pos ));
}
return $name;
}
And in Email templates ( invoice_new.html and invoice_new_guest.html ), I had to write the following lines to get the things done ...
Hello, {{htmlescape var=$order.getCustomerOnlyFirstName()}}
It worked perfectly.
Try
<p class="greeting">{{trans "%name," name=$order.getBillingAddress().getFirstname()}}</p>
Related
In Magento $this->__('Create an Account') How this echo Create an Account?
abstract class Mage_Core_Helper_Abstract{ public function __()
{
$args = func_get_args();
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->_getModuleName());
array_unshift($args, $expr);
return Mage::app()->getTranslator()->translate($args);
}
I saw that __ function in Mage_Core_Helper_Abstract Class.but i cant understand Mage::app()->getTranslator()->translate($args) what's happending in that getTranslator function.
public function getTranslator()
{
if (!$this->_translator) {
$this->_translator = Mage::getSingleton('core/translate');
}
return $this->_translator;
}
Mage::getSingleton('core/translate') what's happening there ? and why in this function call like core/translate which file its denote and how it Create an Account text?
You might search how the magento translator works
What ever text is written in $this->_('') will dynamically translated to the current locale which is loaded in your current store(That text must be specified in magento-root/app/locale//.csv)
I think the below answer might be helpfull
How does Magento translate works?
I' am using Joomla 3, I have module called "Who we Are" and it's being displayed on position "top_row2". I' am trying to get this modules ID and modules Name.
After Searching I found few solutions which doesn't seem to work for me.
Solution 1
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('Who we Are');
echo $module->id;
Solution 2
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModules('Who we Are');
echo $module->id;
//Note the "s" in getModules
Solution 3
global $module;
$module->id;
$module->title;
I' am using this solutions on the override PHP files of this Module.
Location:: templates\corporate_response\html\mod_mymodule_item.php
You can define your own unique Class under "Module Class Suffix" and in your module override item page do a conditional to check which module is being rendered into the page
This might help explain calling modules in overrides.
To call a Joomla! module with the title in a template override:
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position');
foreach($modules as $module) {
echo '<h3>' . $module->title . '</h3>';
echo JModuleHelper::renderModule($module);
}
This will call the module id.
echo $module->id;
This will call the module title in H3, adjust to what you need.
echo '<h3>' . $module->title . '</h3>';
This part will render the module.
echo JModuleHelper::renderModule($module);
You can get all modules by position and then select by title like this:
$module = false;
if ($modules = JModuleHelper::getModules('top_row2')) {
foreach ($modules as $module2) {
if ($module2->title == 'Who we Are') {
$module = $module2;
break;
}
}
}
if ($module) {
printf(
'Found module with name "%s" and id "%d"',
$module->name,
$module->id
);
} else {
echo "Found no matching module.";
}
If someone ever has the same question:
Within the modules code you can simply use the variable $module which contains all information about this specific module like id, title, position, ...
Here is example of URl_title CI, i know this code is do this
$title = "Whats wrong with CSS";
$url_title = url_title($title, '_', TRUE);
// Produces: whats_wrong_with_css
But hot to revers, is there a function in Ci to reverse something like this and return the true value?
like this ?
// Produces: Whats wrong with CSS
hi you can do it just with simple way
$title = ucfirst(str_replace("_",' ',$url_tilte));
echo $title;
I would "extend" CI's URL helper by creating a MY_url_helper.php file in application/helpers and create a function similar to what umefarooq has suggested.
/*
* Un-create URL Title
* Takes a url "titled" string as de-constructs it to a human readable string.
*/
if (!function_exists('de_url_title')) {
function de_url_title($string, $separator = '_') {
$output = ucfirst(str_replace($separator, ' ', $string));
return trim($output);
}
}
Providing you have loaded the url helper, you will then be able to call this function throughout your application.
echo de_url_title('whats_wrong_with_css'); // Produces: Whats wrong with css
The second ($separator) paramater of the function allows you to convert the string dependent on whether it's been "url_title'd" with dashes - or underscores _
In yii i am creating project. After validation of user's entered email, i am displaying password.php file which is having textfield for entering new password.
Password.php=
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('Enter new password');
echo CHtml::textField('Repeat password');
echo CHtml::submitButton('Submit');
$this->endWidget();
When user will enter new password and click on submit button i want to insert this new password into User table's password field, in such a way that it overright old password.
In controller i had created method as-
public function actionCreate(){
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
echo "email exists";
$this->render('Password');
if(isset($_POST['Password']))
{
$command = Yii::app()->db->createCommand();
$command->insert('User', array(
'password'=>$_POST['password'] ,
//'params'=>array(':password'=>$_POST['password'])
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
But its not inserting new password. So How can i implement this...Please help me
First of all the way you are handling the form is certainly not Yii-ish which means it's not really the way to go.
The way you should handle this is by creating an object which extends from the CFormModel and put all your logic code in there instead of in the controller.
Now, if you want to continue working with your piece of code, then it would be best to place the following piece of code
$this->render('Password');
BELOW the if isset password stuff.
For your problem, the reason why your password isn't being updated is because the query you created is not being executed. If we take a look here then we can see that the following piece of code should be added:
$command->execute();
Which will execute your piece of sql.
Something like this...
$user = User::find('email = :email', ':email' => $_POST['email']);
if( empty($user) )
return;
$user->password = $_POST['password'];
$user->save();
You can't get password like this $_POST['Password'], because you haven't set this post variable.
You had to use:
echo CHtml::textField('password');
echo CHtml::textField('repeatPassword');
echo CHtml::hiddenField('email', $email);
'password' and 'repeatPassword' are names of POST vars
And in your controller you have too many mistakes, try this (check for typos):
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
if(isset($_POST['password']) && isset($_POST['repeatPassword']) && ($_POST['password'] === $_POST['repeatPassword']))
{
$record->password = $_POST['password'];
if ($record->save()) {
$this->render('saved');
}
}
$this->render('Password' array('email'=>$_POST['email']));
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
In your code if(isset($_POST['Password'])) won't ever execute, because after sending password you haven't set email variable. So you just $this->render('emailForm');. Thus we set it by CHtml::hiddenField('email', $email);
Upd. I strongly recommend you to read this guide. It will save a lot of time for you.
How to add unsubscribe link in custom email notification i am sending an email through zend mail function i follow this function sending mail in magento in body part i want to add unsubscribe link how can we implement that?
In my e mail notification i am using this function.
public function sendMail()
{
$post = $this->getRequest()->getPost();
if ($post){
$random=rand(1234,2343);
$to_email = $this->getRequest()->getParam("email");
$to_name = 'Hello User';
$subject = ' Test Mail- CS';
$Body="Test Mail Code : ";
$sender_email = "sender#sender.com";
$sender_name = "sender name";
$mail = new Zend_Mail(); //class for mail
$mail->setBodyHtml($Body); //for sending message containing html code
$mail->setFrom($sender_email, $sender_name);
$mail->addTo($to_email, $to_name);
//$mail->addCc($cc, $ccname); //can set cc
//$mail->addBCc($bcc, $bccname); //can set bcc
$mail->setSubject($subject);
$msg ='';
try {
if($mail->send())
{
$msg = true;
}
}
catch(Exception $ex) {
$msg = false;
//die("Error sending mail to $to,$error_msg");
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($msg));
}
}
If you have a custom module use this code:
Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getUnsubscriptionLink();
Explanation:
first part is the model for the subscriber.
If you want to see al the available methods within the model just use this code:
$myModel = Mage::getModel('newsletter/subscriber');
foreach (get_class_methods(get_class($myModel)) as $cMethod) {
echo '<li>' . $cMethod . '</li>';
}
the second part of the code loadByEmail($email) is to get 1 specific subscriber object. $email should be a string of the emailaddress.
The last part of the code is a selfexplaning method. It will generate a link to unsubscribe. This is a method that is given by Magento.
In my Magento version I get the following code by default when creating a new newsletter template:
Follow this link to unsubscribe <!-- This tag is for unsubscribe link -->{{var subscriber.getUnsubscriptionLink()}}
I expect it to work in any Magento version.
I am using Magento 1.9.
To add newsletter unsubscribe link in newsletter template here are following steps:
Override the core file
/app/code/core/Mage/Newsletter/Model/Subscriber.php
by copy in local directory
/app/code/local/Mage/Newsletter/Model/Subscriber.php
Open in editor to edit the code and seacrh the function sendConfirmationSuccessEmail()
replace the code
$email->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
$this->getEmail(),
$this->getName(),
array('subscriber'=>$this)
);
with this
$email->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
$this->getEmail(),
$this->getName(),
array('subscriber'=>$this, 'unsubscribe' =>$this->getUnsubscriptionLink())
);
and place this code in email template where you want to use unsubscribe link:
Unsubscribe here
That's it!
Hope this helps someone.