Magento - Get Transactional Email Variables - magento

I was just reading over
http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_email_template/index#email_variables
Anyone know how I can find these variables on my own? The wiki page says they may not actually work, and the variable I am trying to work with is {{var shippingMethod}}, however, it is returning blank.
I am wondering, one if that is the correct variable name, and two, if that is the correct variable name, what function do I need to add to my custom shipping method?
Thank you!
Jeff

Here's the piece of code that migiht help You:
public function sendMail() {
$mailTemplate = Mage::getModel('core/email_template');
$template = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE); // template id of email template
$email = Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT); // recipient example: example#yahoo.com
$mailTemplate->setDesignConfig(array('area'=>'frontend'))
->sendTransactional(
$template,
Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY),
$email,
null,
array(
'subject' => $this->getSubject(),
'line' => $this->getLine(),
'message' => $this->getMessage()
)
);
$translate->setTranslateInline(true);
return $this;
}
the array of
array(
'subject' => $this->getSubject(),
'line' => $this->getLine(),
'message' => $this->getMessage()
)
can be get by {{var subject}} {{var line}} {{var message}}
Then how to get shippingMethod ??
You must getModel of shipping method and load the shipping method first and then set it to the array.

Related

Trying to get property of non-object in laravel shopping cart

I am using darryldecode for shopping cart in my project
this is my shoppingcartController and add method:
public function add(){
$pdt = Singleproduct::find(\request()->id);
\Cart::add(array(
array(
'id' => $pdt->id,
'name' => $pdt->name ,
'price' => $pdt->price,
'quantity' => \request()->qty ,
'attributes' => array()
)));
}
and this is route list:
Route::post('/cart/add' , 'admin\ShopingController#add')->name('cart.add');
and in my SingleProduct i have id,price and name!
the error is:"Trying to get property 'id' of non-object"
where is the problem??
The id may be returning null, or you may not be getting the right request object. Try injecting it into the method (which is kind of a 'Laravel') way to do it:
public function add(Illuminate\Http\Request $request){
$pdt = Singleproduct::find($request->input('id'));
}
Dump the request variable if you want to double check it has the id from your form: dd($request->all()); If id is not there in the dump, you can see where your problem lies.

How to get Template Variables inside sendMessage() function in Magento 2?

I am trying to send transactional emails from Magento through Listrack. I have override the default sendMessage function using Magento plugin method. Now I have to fetch template variables and process the data inside this function. I tried a lot and was not able to fetch any details regarding the template. Can anyone please help me to resolve this?
sendMessage function is located in Transport.php file.
Replace the "Email Template Name" with your Template Name
$templateId = Mage::getModel('core/email_template')->loadByCode('Email Template Name')->getId();
$customerEmail = 'your mail Id';
$customerName = 'your name';
$senderName=Mage::getStoreConfig('trans_email/ident_general/name');
$senderEmail= Mage::getStoreConfig('trans_email/ident_general/email');
$sender = Array('name' => $senderName,'email' => $senderEmail);
$vars = array(
'customerName' => $customerName,
'date' => $date,
'url'=>$url,
'number'=>$number,
'barcode'=>$serial_barcode,
);
$translate = Mage::getSingleton('core/translate');
Mage::getModel('core/email_template')->sendTransactional($templateId, $sender, $customerEmail, $customerName, $vars, null);
$translate->setTranslateInline(true);

Magento controller url redirects to dashboard

Basically in trying to create an inbox message which "read details" should redirect the user to a custom controller, however i can see the desired url in the browser for a second and then it redirects to the dashboard; this is how, currently, im trying to achieve that:
$myId = $myJson['id'];
$title = "Title of my notice";
$description = $myJson['text'];
$url= Mage::helper("adminhtml")->getUrl('My_Module/Controller/index', array('id' => $myId));
$sendingMessage = Mage::getModel('adminnotification/inbox')->addNotice($title,$description,$url);
The code above successfully adds the message to the inbox, however as i said before, i can see the desired URL in the browser before it gets redirected to the dashboard.
I'm accessing the same controller from another one and it does it as expected, the one that is actually working is a Grid and it looks something like this:
$this->addColumn('action',
array(
'header' => __('Answer'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => __('Answer'),
'url' => array('base'=> '*/Controller'),
'field' => 'id'
)),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
So, am i missing something here ?
BTW, is there any way to make the "read details" link to open in the same page instead of a new tab?
==================================================================
UPDATE
Disabling the "Add Secret Key to URLs" in the security options allowed me get it work, however i would like to make use of the secret keys.
The URLs i'm generating in the first code block actually have a key/value in the URLs, they look something like this:
https://example.com/index.php/mymodule/Controller/index/id/3963566814/key/f84701848a22d2ef36022accdb2a6a69/
It looks like you're trying to generate an admin URL. In modern versions of Magento, admin urls must use the adminhtml front name, using the Magento Front Name Sharing technique (described in this article). That's must as in if you don't, the URLs won't work. Magento removed the ability to create non-adminhtml URLs in the backend.
Second, here's where Magento generates the secret keys
#File: app/code/core/Mage/Adminhtml/Model/Url.php
public function getSecretKey($controller = null, $action = null)
{
$salt = Mage::getSingleton('core/session')->getFormKey();
$p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/'));
if (!$controller) {
$controller = !empty($p[1]) ? $p[1] : $this->getRequest()->getControllerName();
}
if (!$action) {
$action = !empty($p[2]) ? $p[2] : $this->getRequest()->getActionName();
}
$secret = $controller . $action . $salt;
return Mage::helper('core')->getHash($secret);
}
and here's where it validates the secret key
#File: app/code/core/Mage/Adminhtml/Controller/Action.php
protected function _validateSecretKey()
{
if (is_array($this->_publicActions) && in_array($this->getRequest()->getActionName(), $this->_publicActions)) {
return true;
}
if (!($secretKey = $this->getRequest()->getParam(Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME, null))
|| $secretKey != Mage::getSingleton('adminhtml/url')->getSecretKey()) {
return false;
}
return true;
}
Compare the pre/post hash values of $secret to see why Magento's generating the incorrect key on your page.

Add my custom attribute to customer object in Magento (1.7.x)

I have created an custom attribute using the Magento installer script below:
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();
$installer->addAttribute('customer', 'organisation_id', array(
'input' => 'select', //or select or whatever you like
'type' => 'int', //or varchar or anything you want it
'label' => 'Organisation ID',
'visible' => 1,
'required' => 0, //mandatory? then 1
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$installer->endSetup();
On the onepage checkout screen I have a dropdown where a customer selects an organisation from a dropdown menu - once they click the 'Continue' button it posts an ajax request and goes to the next step 'Billing' e.g the post request looks like this..
org[organisation_id] - 12345
org[name] - ACME Inc
My function that deals with this is follows - can anyone assist how to add this to the customer & order object?
public function saveOrgAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('org', array());
// todo:hook up saving the org id passed here to customer & order object
// UPDATE... I believe this is correct?
$customer = Mage::getSingleton('customer/session')->getCustomer(); // get customer object
$customer->setOrganisationId($org_id)->save();
if (!isset($result['error'])) {
$result['goto_section'] = 'billing';
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
What is the best way to add this 'organisation_id' attribute to the customer object (note I am using Magento 1.7.2)
$customer->setOrganisationId('123')->save();
if you need it in the order you have to set it in the current quote object
via
$quote->setOrganisationId('123');
and use this explanation to push the attribute automatically through quote to order conversion. But dont forget to create the correct labled column in sales_flat_order!
explanation how to push any attribute automatically through quote to order conversion

How to pass external validation through model labels and error messages?

In Kohana 3.2, passing external validation on Model_User upon save, why won't the correct message show?
I have user.php in application/messages/models which reads and translates fine for the "internal" data, while _external.php resides in application/messages/models/user.
When _external data is invalid, the default error message from Kohana is shown, and thus not correctly translated or given the correct labels from Model_User.
Edit, with code:
// We have $_POST, register a new user
$user = ORM::factory('user');
/*
* Here a bunch of variables are set
*/
$extra = Validation::factory($_POST)->
rule('email', 'email')-> // I run this check, because in my Model_User, email is filtered through Encrypt
rule('name', 'not_empty'); // Same goes for name
try {
$user->save($extra);
} catch (ORM_Validation_Exception $e) {
$this->template->errors = $e->errors('models', true);
}
So, when $extra variables don't match the rule, I would like to get nice error messages from application/messages/models/user/_external.php, which looks like:
return array(
'email' => array(
'email' => ':field must be a valid email address',
),
'name' => array(
'not_empty' => ':field must not be empty',
),
);
Also, it would be nice if :field was fetched from Model_User "labels".
You need to put _external.php next to your user.php in the messages/models directory, not in the messages/models/user directory. I had the same problem, it worked for me.

Resources