Magento 2 Tips : How to get client ip
The client ip can be retrieved using
getClientIp()
method in
Magento\Framework\HTTP\PhpEnvironment\Request
class. This is very useful , when do the ip restriction in maintenance page development.
Related cards:
Magento 2 : How to use Javascript in Magento
Javascript in Magento 2
Magento 2 uses Require JS lib and Knockout JS lib to solve the page speed and manage the JS dependency.
As JS are loaded asynchronously in backend, it helps to increase the page speed.
The JS files can be found in f...
How to use Mailhog in magento 2 development with docker
Mailhog is a tool to test the you application mail outgoing.
Steps to use with docker
First, install mailhog sendmail tool in your php docker container
wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linu...
Magento 2 : How to hide a image path in a page
Following example explains how to add encoded url for image
1) Create a function to get the path in block class
public function getEncodedPath()
{
$ext = pathinfo($this->getPath(), PATHINFO_EXTENSION);
if ($ext) {
...
Magento 2 : How to write a controller to download a file
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Framework\App\Action\Action;
use Magento\Customer\Model\Session;
class DownloadPres...
Magento 2 : How to add a column in Order Grid and Order
Following steps explain how to add new column in order and grid tables
1) Add the columns in order, quote and grid tables using declarative schema
**2) Add arguments to Magento\Sales\Model\ResourceModel\Order\Grid virtual class that alrea...
Magento 2 Tips : Install external lib
How to install a excel lib to generate formatted excel file
Step 1) Go to the magento 2 root folder then execute following command
sudo -uwww-data composer require phpoffice/phpspreadsheet
Magento 2 : API with GET and POST
Magento 2 API are used to fetch the data and create or update data in magento.
Following is the example of creating custom api for GET and POST
In Magento 2, a module is developed with service contract design pattern, the RepositoryInterface is...
Magento 2 Tips : System Configuration field dependent on multiple values
How to show a field dependent on another field multiple values
<depends>
<field id="vasan/general/enable">1</field>
<field id="vasan/email_dispatch/receiver" separator=",">2,3</field>
...
Magento 2 Tips : Date Format
use Magento\Framework\Intl\DateTimeFactory;
=====================================
$endDate = $this->dateTimeFactory
->create($milestone->getData('end_date'), new \DateTimeZone('UTC'))->format('d/m/Y');
==========================...
Magento 2 Tips : Conditionally Loading Javascript and css in layout xml
First create your conditions in the system.xml..
Second add your css and js in your local xml.
<reference name="head">
<action method="addCss" ifconfig="my_config_section/advanced/load_css"><stylesheet>css/my_module/my_module.css</st...