How to add a new container in a existing docker-compose file.
Steps:
The existing docker-compose file
version: '3.3'
networks:
pwa_net:
ipam:
driver: default
config:
- subnet: 60.0.0.0/24
gateway: 60.0.0.1
services:
mysql-cont:
image: mysql:8.0
container_name: springboot-mysql-cont
networks:
pwa_net:
ipv4_address: 60.0.0.11
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: bookstore
MYSQL_USER: bookstore
MYS...
How to add di.xml configuration for simplet grid.
<!-- City listing definitions -->
<virtualType name="Kemana\Directory\Model\ResourceModel\City\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">kemana_directory_city</argument>
<argument name="resourceModel" xsi:type="string">Kemana\Directory\Model\ResourceModel\City</argument>
</arguments>
</virtualType>
<type name="Magento\Framewor...
Virtual Classes
The Virtual classes are not created physically with all features but it will be created by dependency injection file in magento 2.
Developers define these classes in di.xml when they want to use the existing classes with argument replacement to create additonal functionality without chaning the original class.
<virtualType name="MilestoneRepositoryExtended" type="Vasan\Training\Model\MilestoneRepository">
<arguments>
<argument name="milestoneManagement" xsi:type="object">Vasan\Training\Model\M...
Step 1:
Create system.xml file with configuration field.
<group id="cron" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>MSD Cron</label>
<field id="schedule" translate="Schedule" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Schedule</label>
</field>
</group>
Step 2 :
Create crontab.xml content
<group id="...
The API funcational testing can be implemented using following steps
First Step : Develop your API
Second Step : Write the API Test class
Eg:
<?php
/**
* OrganisationRepositoryTest
*
* @copyright Copyright © 2023 Vasan. All rights reserved.
* @author psureshvasan@yahoo.com
*/
namespace Vasan\Organisation\Test\Api;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Vasan\Organisation\Model\ResourceModel\OrganisationRepository;
use Magento\Customer\Model\ResourceModel\CustomerRepository;
use Magento\TestFramework\Helper\...
Fix for logging issue
ERROR 1419 (HY000) at line 410: You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
Take the backup of my.cnf and execute following commant to add it in the end of the file
echo 'log_bin_trust_function_creators = 1' >> my.cnf
Adding searchable drop-down
Simply following steps to add searchable drop-down ui component in a form
1. Add element in form xml
<field name="rateselection" component="Vasan_Bidding/js/form/components/rate-select" formElement="select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="multiple" xsi:type="boolean">false</item>
...
Searchable drop-down component with Jquery Plugin
Following example shows the steps to use Select2 Jquery Plugin in Magento 2 admin form.
Stesps :
1. Download the required files from Repository
https://github.com/select2/select2/tree/4.1.0-rc.0
2. Add the required files in magento 2 module
In view/adminhtml/web/js folder
Add the downloaded select2.js in above folder
In view/adminhtml/web/css folder
Add the select2.css file under above folder
In required-config.js
var config = {
...
Custom time component
Magento2 time component does not pass the selected time when post the form to controller.
Following custom time component is used to capture the time.
In form xml
<field name="start_time" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">milestone</item>
</item>
</argument>
<settings>
<elementTmpl>Vasan_Bidding/form/el...
Date columns with date formatting
Following example shows how to use date component in listing
In xml
<column name="due_date" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Due Date</item>
<item name="timezone" xsi:type="string">false</item>
<item name="dataType" xsi:type="string">date</item>
...
Text box component with suffix
Magento use ui component with suffix in product form for weight.
Following example shows how to use the suffix for a text ui component.
In xml
<field name="duration" formElement="input" component="Vasan_Bidding/js/form/components/duration">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">milestone</item>
</item>
</argument>
<settings>
...
Text box component with currency symbol as prefix
In Product Form, Magento uses the text ui component with currency symbol as a prefix for price.
Following example shows how to get the prefix in text component
In form xml
<field name="final_total_text" formElement="input" sortOrder="120" component="Vasan_Bidding/js/form/components/price">
<settings>
<elementTmpl>Vasan_Bidding/form/element/currency_text</elementTmpl>
<label translate="true">Total</label>
<dataScope>amoun...
Adding dataprovider for listing component with filtering and sorting
Listing component default data provider get all the data from collection.
Sometime we need to do filer and sorting.
Following example shows how to do the filer and sorting of a listing component
class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
{
/**
* @inheritdoc
*/
public function getData()
{
$this->addFilter(
$this->filterBuilder->setField('proposal_id')->setValue($thi...
This section contains the edit UI components and layout xml files
Stesps :
create a file kpsaddress_index_lising.xml for grid under ui_component
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">kpsaddressindex_lis...
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 created by admin in back-end, the it is a system attribute but if it is created with script then it is custom attribute.
Following example shows that creating new dropdown attribute for customer.
Steps:
<?php
/**
* CreateAgeGroupAttribute
*
* @copyright C...
Docker compose file for magento 2.4
version: '3.3'
networks:
pwa_net:
ipam:
driver: default
config:
- subnet: 40.0.0.0/24
gateway: 40.0.0.1
services:
web-cont:
image: registry.vasan.com/magento24_fpm74:1.0
container_name: magentoent242-web-cont
volumes:
- /home/suresh/works/projects/magentoEnt242:/var/www/html
environment:
SERVER_NAME: magentoent242.dev.local
USER_ID: 1000
networks:
pwa_net:
ipv4_address: 40.0.0.10
...
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 used for
API GET and POST to get the records and save the record respectively.
Refer the webapi.xml in the etc folder of CMS module
However, the custom API can be implemented by customizing the RepositoryInterface or creating new Interface
The new interface should be created with '@api' anotat...
In magento 2, custom log file is important to verify the log for specific critical function implementation and debug the issues in the server level
Custom log file can be created by simply creating two virtual classes.
Virtual class definition in di.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* di
*
* @copyright Copyright © 2021 Vasan. All rights reserved.
* @author survasp@gmail.com
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Obje...
In this example, you can learn how to add additional attributes for customer address
Steps
In this example, district and sub_district attributes will be added in the EAV t...
Address model class extends the AddressInterface and it contains the data object getters setter methods.
<?php
/**
* Address
*
* @copyright Copyright © 2021 Vasan. All rights reserved.
* @author survasp@gmail.com
*/
namespace Vasan\KpsAddress\Model;
use Vasan\KpsAddress\Api\Data\AddressInterface;
use Magento\Framework\Model\AbstractModel;
use Vasan\KpsAddress\Model\ResourceModel\Address as ResourceModel;
class Address extends AbstractModel implem...
Vasan
--KpsAddress
--Api
--Data
--AddressInterface.php
--AddressSearchResultsInterface.php
--AddressRepositoryInterface.php
--Block
--Adminhtml
--Edit
--DeleteButton.php
--GenericButton.php
--ResetButton.php
--SaveAndContinueButton.php
--SaveButton.php
--Console
--InstallAddress.php
--Controller
--Adminhtml
--Index
--Delete.php
...
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 already defined in Magento_Sales di.xml
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="channel" xsi:type="string">sales_order.channel</item>
</argument>
</a...
Sometime , we need to create multisite application using magento 2 framework.
Following example shows the nginix confgiration of multisite application with magento website or store
In this example contains three sites and each has different domain
upstream fastcgi_backend {
server unix:/run/php/php7.4-fpm.sock;
}
map $http_host $MAGE_RUN_CODE {
default '';
magento2lst.dev.bn.com ban;
magento2lst.dev.jk.com jak;
}
server {
listen 80;
server_name magento2lst.dev.com magento2lst.dev.bn.com magento2ls...
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="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="vender_email_paymentlinkemail" label="Payment Link Email" file="paymentlinkemail.html" type="html" module="Vender_Prescription" area="frontend...