9
votes
Accepted
How to retrieve variable from CMS page in Magento 2
You can use in Magento 2 like this
{{block class="Magento\Framework\View\Element\Template" name="blockname" template="Vendor_Module::test.phtml" my_vars="123,456"}}
Now you can get the data by ...
7
votes
Accepted
Magento 2: Pass variable from phtml to js
In your .phtml please add following code.
<script type="text/x-magento-init">
{
"*": {
"Magepow_Ajaxcart/js/view/minicartaddons": {
"maxpriceShipping": <?= /* @...
4
votes
Accepted
How to set session variable
You can use to set and get custom session value like below
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$catalogSession = $objectManager->get('\Magento\...
4
votes
Passing magento username and email variables into js script (Magento ver. 2.1.8)
Assuming that this is a JavaScript Component in the Magento sense of the word, you can basically "insert" it into any HTML element.
Let's say you want to put your chat inside a div you can do ...
4
votes
Accepted
Magento2.3 : Email template address variable not displays the value
For email template changes following section
For Guest User
{{trans "%customer_name," customer_name=$order.getBillingAddress().getName()}}
For Customer
{{trans "%customer_name," ...
3
votes
Accepted
Getting the Store Name in a Block
We can get store name like this:
In Phtml:
$storeName = Mage::app()->getStore()->getName();
In Cms Page:
{{config path="general/store_information/name"}}
Don't forget to configure your ...
3
votes
Accepted
Magento 2: format var invoice.created_at
I solved the problem by adding a new function to Model/Order/Invoice.php:
public function getInvoiceDate(){
$cdate = $this->getCreatedAt();
$invoiceDate = date('d. M. Y', strtotime(...
3
votes
Getting the shipping method code in transactional emails
Not sure I follow 100%, but I'll take a shot at it.
{{var shippingMethod}} is not a standard variable on sales email templates, so it must be something you already inject as custom.
Default ...
3
votes
Accepted
Magento 2 - How can I define constants or variables once and reuse them in a custom module?
There are different ways like:
a) helper class
1) Declare the helper class and define your constants and variables in it.
2) Inject it as a dependency in all your classes.
3) Now the constants ...
3
votes
Magento 2 - How can I define constants or variables once and reuse them in a custom module?
Pick a PHP class in your module and define the constant in there using const keyword. For example const LOG_FILE = 'file/path';.
You can access it from anywhere like \Class\Name::LOG_FILE.
3
votes
Accepted
Where do we store persistent single variables in Magento 2 (module settings)?
Magento provides a facility to persist configuration values like tokens, passwords, URLs etc. This is the System (Store) Configuration (Menu > Stores > Configuration).
See the /etc section of this ...
2
votes
How do I” Pass variable between .phtml files?
I dont know why you want to do this But you can use Magento registry for this.
Set data to registry
Mage::register('name-of-registry-key', $postdata);
Get your data
$var = Mage::registry('name-of-...
2
votes
Magento 2 : How to call block file in order email with order variable?
This was my method for getting product attributes into my email template. I utilize the productRepositoryInterface to pull custom attributes that we store as JSON strings.
Our business uses core ...
2
votes
2
votes
Accepted
Magento 1.9 {{var payment_html}} alternative
You cannot the payment html directly form the order because there is a block involved.
You can generate the html like this:
Let's say $order is your order object.
$paymentBlock = Mage::helper('...
2
votes
Magento2 variable in transactional email
You can get customer email by below line,
{{var order.getCustomerEmail()}}
2
votes
Accepted
How can I use my own custom system settings in e-mail templates?
I found the problem. In my source model I hooked into the toOptionArray()-method, but this had to be the getData()-method:
public function afterGetData(\Magento\Email\Model\Source\Variables $subject, ...
2
votes
Accepted
How to get value in function that is retrieved and stored in a variable of another function in same class | Magento 2
Instead of set public, try with set variable private.
class Observer implements ObserverInterface
{
private $orderId;
public function __construct(
\Magento\Framework\Registry $...
2
votes
Accepted
Magento 2 | Variable with StoreViewCode
use following variable to get url with store code :
{{store direct_url=""}}
Also this will work :
{{store url=''}}
2
votes
how to validate custom fields using variables in magento 2
<input type = "text" id ="price1" ?>
<input type = "text" id ="price2" ?>
<div id = "error"></div>
<script>
$(document).ready(function(){
$("#price2")....
2
votes
Accepted
Dynamically add year variable to meta title / description in Magento 2
In this case, you can use event/observer.
Fire an observer on the event catalog_category_load_after at frontend area set meta description on the fly.
Create events.xml at
app/code/...
2
votes
Variable for invoice date - Magento 2.2.6
yes there is. Similar to order the invoices get a timestamp "created_at".
protected $order;
public function __construct(
.....
\Magento\Sales\Model\OrderFactory $order,
.......
) {
...
...
2
votes
Accepted
Email variable order.getShippingAddress().getStreet1() returns null
Try this instead :
{{var order.getShippingAddress().getStreetLine(1)}}
2
votes
Accepted
Issue with get product attribute value in other place than list.phtml
Try with this below code inside foreach in that file :
<?php /* @escapeNotVerified */ echo $_item->getResource()->getAttribute('subname')->getFrontend()->getValue($_item); ?>
1
vote
Magento 2 system variable for "Order Created at" for email templates
You can either set is_legacy column in email_template table to 1
or use {{var created_at_formatted}} variable instead (but it doesn't available for shipping, creditmemo and invoice emails)
The reason ...
1
vote
Magento 2 system variable for "Order Created at" for email templates
Use :
{{var order.getCreatedAtFormatted(2)|raw}}
1
vote
Accepted
Magento 2: Parsing Item information through block
you can do by the following code
{{block class="Magento\Framework\View\Element\Template" name="blockname" template="Vendor_Module::test.phtml" product_id="30"}}
in your phtml file
Now you can get ...
1
vote
Accepted
How can we pass table to an html variable in php code? Magento2 TCPDF
Try to append your next iteration in $html variable by using dot ( . )
$html='';
foreach(-------------)
{
$html . = <table>
<?php if (is_array($t->a)) foreach($t->a as $k => $...
1
vote
Magento2: variables
you can get customer data as
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($block- >getOrderId()); /...
1
vote
Accepted
Source location for variables that can be change e.g background-color - Magento 2
The exact path would depend on whether you've installed magento using composer or web setup.
If you've used web setup, the files will be located here -
vendor/magento/theme-frontend-luma/web/css/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
variables × 112magento2 × 49
email-templates × 25
magento-1.9 × 21
email × 11
transactional-mail × 10
phtml × 8
magento-2.1 × 7
custom-variable × 6
product × 5
php × 4
checkout × 4
javascript × 4
blocks × 4
cms × 4
order-email × 4
magento2.3 × 3
magento-1.7 × 3
magento2.2 × 3
product-attribute × 3
price × 3
template × 3
cms-block × 3
php-5.4 × 3
layout × 2