Skip to main content
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 ...
Prince Patel's user avatar
  • 22.9k
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": <?= /* @...
Aasim Goriya's user avatar
  • 5,454
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\...
Ansar Husain's user avatar
  • 3,479
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 ...
Jorge1o1's user avatar
  • 331
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," ...
Vijay Khirade's user avatar
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 ...
Shubham Khandelwal's user avatar
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(...
crrdr's user avatar
  • 46
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 ...
Rick Buczynski's user avatar
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 ...
Pankaj Bhope's user avatar
  • 1,546
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.
Aaron Allen's user avatar
  • 9,029
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 ...
nikola99's user avatar
  • 528
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-...
Murtuza Zabuawala's user avatar
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 ...
David Stillson's user avatar
2 votes

Hide {{var comment}} when field empty in email

{{if comment}} {{var comment}} {{/if}}
goivvy.com's user avatar
  • 4,213
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('...
Marius's user avatar
  • 199k
2 votes

Magento2 variable in transactional email

You can get customer email by below line, {{var order.getCustomerEmail()}}
Rakesh Jesadiya's user avatar
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, ...
Giel Berkers's user avatar
  • 12.3k
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 $...
Rohan Hapani's user avatar
  • 17.5k
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=''}}
Naveed Asim's user avatar
  • 3,667
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")....
ASQ's user avatar
  • 1,062
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/...
Amit Bera's user avatar
  • 77.7k
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, ....... ) { ... ...
ecommerce's user avatar
2 votes
Accepted

Email variable order.getShippingAddress().getStreet1() returns null

Try this instead : {{var order.getShippingAddress().getStreetLine(1)}}
Arif Ahmad's user avatar
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); ?>
Rohan Hapani's user avatar
  • 17.5k
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 ...
Evgeni Obukhovsky's user avatar
1 vote

Magento 2 system variable for "Order Created at" for email templates

Use : {{var order.getCreatedAtFormatted(2)|raw}}
Sarasranglt's user avatar
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 ...
Hitesh's user avatar
  • 1,579
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 => $...
sheraz khan's user avatar
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()); /...
Arslan Tabassum's user avatar
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/...
Vivek Kumar's user avatar
  • 5,740

Only top scored, non community-wiki answers of a minimum length are eligible