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 : Admin Module Part 2
5.Create Model and Resource model
Address model class extends the AddressInterface and it contains the data object getters setter methods.
<?php
/**
* Address
*
* @copyright Copyright © 2021 Va...
Magento 2 : Custom Email Sending
Email can be sent in magento customization with following implementation
First, The email template should be created in view section and registered in etc using email_template.xml
email_template.xml
<?xml version="1.0"?>
<config xmlns:xsi...
Magento 2: Create new customer attribute
How to create a new custom attribute to Customer
This article explain the custom customer attribute creation and showing that in account creation and account edit
Magento Customer module is developed with EAV attributes
if a attribute is cr...
Magento 2 : Address additional attributes
In this example, you can learn how to add additional attributes for customer address
Steps
- Add additional attributes to EAV table
- Create extension attributes to link with models to save additional attributes values in databases
- Crea...
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...
Magento 2 : Admin Module Part 1
1. Create required folders and files for a module
Vasan
--KpsAddress
--Api
--Data
--AddressInterface.php
--AddressSearchResultsInterface.php
--AddressRepositoryIn...
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...
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 Notes
1) Non Auto Increment Primary key
The $_isPkAutoIncrement should be assigned as false in resource model, when a primary key of a table is used as non auto increment.
protected $_isPkAutoIncrement = false;
2) Custom Cron Job
F...
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) {
...