Mysql
Mysql Secure Installation in ubuntu 18.04
sudo apt install mysql-server
enter Y to install
2.
sudo mysql_secure_installation
to run automated securing script
3. Press N for VALIDATE PASSWORD plugin
4. Set root password
5. Remove anonymous users? Y
6. Disallow root login remotely? N
7. Remove test database and access to it? Y
8. Reload privilege tables now? Y
9.
sudo mysql
to enter MySQL CLI
10.
SELECT user,authentication_string,plugin,host FROM mysql.user;
to verify root user's auth method
11....
Magento 2 : Popup
Simple popup can be generated with magento 2 popup model
First, create a phtml to load the popup message and it should be added in footer section to load in every page
If you define the phtml in default.xml file then, simply you can call it as child component
<div class="note">
<div class="popup-open" ></div>
</div>
<div id="popup" style="display: none;">
<?php echo $this->getChildHtml('popup-content') ?>
</div>
<script type="text/x-magento-init">
{
".popup-open": {
"Vender_Module/js/popup": {}
}
}
</script>
...
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
Following two files are mandatory to execute a process using cron
A class file and a crontab.xml file
class Notifier
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function execute()
{
$this-...
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_linux_amd64
sudo chmod +x mhsendmail_linux_amd64
sudo mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail
Second, change your php.ini sendmail_path value as follows
sendmail_path = '/usr/local/bin/mhsendmail --smtp-addr="mailhog-cont:1025"'
Third, add mailhog in your docker compose f...
Magento 2 : Customer attribute creation
CustomerSetupFactory and Attribute SetFactory classes should be used to create the customer attribute using setup script
<?php
namespace ExamNotes\Chapter10\Setup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Customer\Model\ResourceModel\Attribute;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
cla...
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 following locations :
lib/web
view/area/web
theme/module/web
theme/web
Magento 2 uses requirejs-config.js in module view/area/ folder to map the JS file with alias.
Magento 2 declares JS using following ways :
data-mage-init
<script type="text/x-magento-init"> ...........
Docker Compose Network
This example shows that how the static ip can be assigned to container and how to add another container network to a container. This can be done only for version 2 compose.
version: '2'
services:
app:
image: busybox
command: ping www.google.com
networks:
app_net:
ipv4_address: 10.0.0.10
webapp:
image: busybox
command: ping www.yahoo.com
network_mode: service:app
networks:
app_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.0.0.0/24
g...
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</stylesheet></action>
<action method="addItem" ifconfig="my_config_section/advanced/load_js"><type>skin_js</type><name>js/my_module/my_module.js</name></action>
</reference>
Display Product Price without GST based on customer group
Following methods of the Config.php(app/code/core/Mage/Tax/Model) need to be changed as follows to display the product price excluding GST
public function getPriceDisplayType($store = null)
{
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if (isset($groupId) && ($groupId == 2) &&
((int)$this->_getStoreConfig(self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, $store)) == self::DISPLAY_TYPE_INCLUDING_TAX){
return self::DISPLAY_TYPE_EXCLUDING_TAX;
}
...
Executing remote script via ant
Following ant build script to help you to execute command in remote server.
<?xml version="1.0"?>
<project basedir="." default = "build">
<target name="build" description="Running test" >
<path id="jsch.class.path">
<pathelement location="/usr/share/ant/lib/ant-jsch-1.9.2.jar" />
<pathelement location="/usr/share/ant/lib/jsch-0.1.51.jar" />
</path>
<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp"...
PHP Composer
It is really useful to install the required library specific to the php project.
Following simple command help you to install it in your linux env.
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Not only you can get the lib but also you can publish your lib.
In following site you can check the available package.
Packagist.
In windows, It can be installed simply download and run the following exe file and It will be set in the PATH as well.
[Composer e...