Friday, 5 March 2021

Magento 2 Interview Questions and Answers

 -- Magento cloud steps to process

1. Add the new Production domain to the Domains tab in the Cloud UI

2. Update A and CNAME records for each of your domains and hostnames (see above)

3. Change Magento Base URLs to www.yourdomain.com

4. Wait for the TTL time to pass, then restart the web browser

5. Test your website


-- Have you developed a custom payment gateway extension for magento2

Yes, I have developed a custom payment gateway. Here are the steps.

1 - create registration.php file

2 - create etc/module.xml file

3 - declare payment methods, so we need to create another file under the etc/payment.xml folder.

4 - create config.xml file under the etc folder to declare the payment method.

5 - Create a model file

6 - to display payment methods on the checkout page then we create a checkout_index_index.xml page

7 - Create js files to load KO template in checkout page: /view/frontend/web/js/view/payment/simple.js

8 - Now we need to create /view/frontend/web/js/view/payment/method-renderer/simple-method.js

9 - Finally, create KO template file /view/frontend/web/template/payment/simple.html


-- What classes used in payment gateway for developing an extension

Payment classes


-- What is the Plugin and type of plugin

Magento 2 Plugin is a technical plugin for your better writing code. Interception Plugin allows editing the behavior of any public class or method by intercepting a function call and running code either before or after or around the function call.

There are 3 types of plugins available on Magento 2, before, after, and around.


--Difference between around and before the plugin

Around methods allow codes to run before and after observed methods. so you can override a method. and the prefix should be Around.

Before methods are the first methods to run in observed methods. and the prefix should be Before.


-- What is used of preference tag in magento2

Preference is used for overriding class


--How to create a database table in Mysql

Use a CREATE TABLE statement to specify the layout of your table


--Have you worked on Rest API

- etc/module.xml

- registration.php

- Create a webapi.xml file under the etc directory

- create a di.xml file to define an interface and model that defines which model will be called by the defined interface.

- Interface: Api/AddressInterface.php

- Create model - CustomerAddress.php


-- Custom module works, schema uses

db_schema.xml file declares a module’s database structure. If you want to rename a column then use the schema.xml file.

Before running the upgrade command you need to add your schema to the db_whitelist_schema.json file by running the following command :

php bin/magento setup:db-declaration:generate-whitelist --module-name=RH_Helloworld


-- CLI commands do cache clean & flush

php bin/magento cache:clean;

php bin/magento cache:flush;


-- What is the difference between Preference and Plugin?

With Preference, it must extend a core class. Preference can rewrite function. When you declare a Preference, your new class is expected to be a complete implementation of the class you want to override.


While a plugin allows you to execute your functions before, after, or around (before & after) the core function is executed. It's NOT really rewritten function like Preference. 


-- Creating a migration plan

Review extensions on your current site

Build and prepare Magento 2 store for migration

Copy the Magento 1 store data to Magento 2 staging environment

Start your migration

Use the Data Migration Tool to migrate settings and websites

Copy your Magento 1.x media files to Magento 2.x.

Reindex all Magento 2.x indexers


--What Does the setup:di:compile Command Do? 

The above setup:di:compile command basically generates the contents of var/di folder in Magento < 2.2 and for >=2.2. According to the official Magento docs, it compiles code like Factories, Proxies, Interceptors, etc. and puts them in generated or var/generation directory.


Magento2 Service Contract?

- In general understanding, a service contract is an agreement between the two parties, where one is the service provider and the other is the service consumer. A service contract is a set of PHP interfaces that are defined for a module. A service contract includes data interfaces, which preserve data integrity, and service interfaces, which hide business logic details from service requestors such as controllers, web services, and other modules.


Explain RabbitMQ?

- Magento 2 supports MySQL and RabbitMQ systems to create message queues. Magento 2 RabbitMQ works as a message intermediator between sender and receiver. It is an open-source communication broker that provides your applications with a common platform while offering a secure and convenient messaging system.

Tuesday, 15 December 2020

Magento 2 Interview Questions and Answers

 --- the main differences between INNODB and MyISAM

The most commonly used storage engine in MySQL is MyISAM and InnoDB.With this storage engine, there are some advantages and disadvantages according to application needs. As you all know, the default storage engine chosen by the MySQL database is MyISAM.

The main difference between MyISAM and InnoDB are :

MyISAM does not support transactions by tables while InnoDB supports.

There are no possibility of row-level locking, relational integrity in MyISAM but with InnoDB this is possible. MyISAM has table-level locking.

InnoDB does not support FULLTEXT index while MyISAM supports.

Performance speed of MyISAM table is much higher as compared with tables in InnoDB.

InnoDB is better option while you are dealing with larger database because it supports transactions, volume while MyISAM is suitable for small project.

As InnoDB supports row-level locking which means inserting and updating is much faster as compared with MyISAM.

InnoDB supports ACID (Atomicity, Consistency, Isolation and Durability) property while MyISAM does not support.

In InnoDB table,AUTO_INCREMENT field is a part of index.

Once table in InnoDB is deleted then it can not re-establish.

InnoDB does not save data as table level so while implementation of select count(*) from table will again scan the whole table to calculate the number of rows while MyISAM save data as table level so you can easily read out the saved row number.

MyISAM does not support FOREIGN-KEY referential-integrity constraints while InnoDB supports.


-- What is proxy and why we use it


 Inject Proxy class when you feel object creation will be expensive and class’s constructor is particularly resource-intensive. - when you don't want unnecessary performance impact due to object creation. - when you feel object creation should happen when you call a particular method in a particular condition not always. For example, the Layout constructor is resource-intensive.

 Proxy behaves acts on behalf of others.


-- What is virtual type and type

Virtual types are a way to inject different dependencies into existing classes without affecting other classes.


Type lets us manipulate the dependencies injected into class constructors. It’s a powerful tool that e.g. allows us to add new Routers in Magento.


--What caching by default use in magento2

File system


--why we use static version and what is effect if we dont use it

Static files are the files that can be cached on the site, which increases page loading speed. These include CSS, fonts, images, and JavaScript used by the theme. Such files are located in the / pub / static and / var / view_preprocessed / pub / static folders, which get there after deployment. From this article you will learn how to deploy static files.


--Where static version defined and where we use it.

We are using from Store - Configuration - Advance - Developer - Static File Setting - Yes

Such files are located in pub/static and var/view_preprocessed/pub/static


--Stpes for create around plugin

A plugin is a great way to expand or edit a public method’s behavior by using code before, after or around method.


app/code/vendorname/modulename/registration.php

app/code/vendorname/modulename/etc/module.xml

app/code/vendorname/modulename/etc/di.xml

app/code/vendorname/modulename/controller/index.php

app/code/vendorname/modulename/Plugin/example.php


--What is the usage of di.xml file

Dependency Injection is a design pattern that allows an object A to declare its dependencies to an external object B

you can map your own implementation of a Magento interface to a dependent class or service using the di.xml file.


--what is interface and where we use it

Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.


--Difference bewteen interface and abstractclass

Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs.



-- how we cached specific block

Setting cache_lifetime via layout XML:

Setting cache_lifetime via DI.XML

Setting cache_lifetime via block file.


--We need to add custom fields in checkout page and what are the steps

Create the JS implementation of the form UI component. In your <your_module_dir>/view/frontend/web/js/view/ directory, create a custom-checkout-form.js file

Create the knockout.js HTML template for rendering the form. <your_module_dir>/view/frontend/web/template directory called custom-checkout-form.html

Declare the form in the checkout page layout. <Checkout_module_dir>/view/frontend/layout/checkout_index_index.xml.


-- What is security tool we use in magento2

Use security scan

Use frontend/backend CAPTCHA

Use two-factor authentication

Use strong passwords

Use advanced admin access permissions


--How will you manage the security if you will create custom API?

We have to set the resouce ref to the vendor_Module ACL key in etc/webapi.xml

in the acl.xml file need to setup for the roles group

then set permissions in the backend system -> permissions -> user roles



--What is repository

Repositories give service requestors the ability to perform create, read, update, and delete (CRUD) operations on entities or a list of entities.


--What is di.xml?

Magento reads all the di.xml configuration files declared in the system and merges them all together by appending all nodes


--What is the use of di:compile command

The above setup:di:compile command basically generates the contents of var/di folder in Magento < 2.2 and for >=2.2.


--Whats is the use sttaic-content:deploy command

Simple run the following command line to deploy static content your store when install / update an extension


--How will you remove fpc from specific block.

cacheable = "false" has only one meaning.



-- Payment Method

Create file registration.php

Declare module.xml file

Declare payment method module

Now we create file payment.xml file in etc folder etc/payment.xml

Create config.xml file in etc folder.

Create file Model/Payment/Simple.php

Create layout file: view/frontend/layout/checkout_index_index.xml

/view/frontend/web/js/view/payment/simple.js



-- what is difference between compiler and interpreter


Interpreter translates just one statement of the program at a time into machine code. Compiler scans the entire program and translates the whole of it into machine code at once. An interpreter takes very less time to analyze the source code. However, the overall time to execute the process is much slower


--Difference between abstract class and interface


1) Abstract class can have abstract and non-abstract methods. Interface can have only abstract methods. Since Java 8, it can have default and static methods also.

2) Abstract class doesn't support multiple inheritance. Interface supports multiple inheritance.

3) Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables.

4) Abstract class can provide the implementation of interface. Interface can't provide the implementation of abstract class.

5) The abstract keyword is used to declare abstract class. The interface keyword is used to declare interface.

6) An abstract class can extend another Java class and implement multiple Java interfaces. An interface can extend another Java interface only.

7) An abstract class can be extended using keyword "extends". An interface can be implemented using keyword "implements".

8) A Java abstract class can have class members like private, protected, etc. Members of a Java interface are public by default.

9)Example:

public abstract class Shape{

public abstract void draw();

} Example:

public interface Drawable{

void draw();

}



-- difference between abstraction and encapsulation in php

Encapsulation: Wrapping code and data together into a single unit. Class is an example of encapsulation, because it wraps the method and property.


Abstraction: Hiding internal details and showing functionality only. Abstraction focus on what the object does instead of how it does. It provides generalized view of classes.


--HOW CAN YOU IMPROVE THE PERFORMANCE OF MAGENTO 2?

Optimizing image size

MySQL Query Caching

Enable Magento caching

Enable Gzip caching

Disabling modules that aren’t in use

Write clean code

Use dedicated hosting services because it’s a resource-hungry platform.



--WHICH COMMAND IS USED TO ENABLE OR DISABLE A MAGENTO 2 CACHE?

php bin/magento cache:enable

php bin/magento cache:disable


--WHAT IS THE DIFFERENCE BETWEEN A CACHE:CLEAN AND CACHE:FLUSH?

Cache:clean deletes all the cache that has been enabled for Magento. Cache: flush on the other hand deletes all the cache storage whether it is from a third party or Magento cache.



--HOW MANY TABLES WILL BE CREATED WHEN YOU MAKE A NEW EAV MODEL?

Six tables will be created. These include:


Module_datetime

Module

 module_decimal,

module_int

module_text

Module_varchar




--HOW CAN YOU RESET MAGENTO FILE & DIRECTORY PERMISSIONS?

You can reset them by following commands through the directory where Magento is installed.


find . –type f –exec chmod 644 {} ;


find . –type d –exec chmod 755 {} ;


chmod +x mage



--WHICH FILE STORES THE VENDOR PATH?

It’s vendor_path.php situated at app/etc/ folder



--WHAT ARE THE DIFFERENT DEPLOY MODES IN MAGENTO 2?

The different deploy modes are:


Default mode: Through this mode, you can deploy Magento applications on a single server. This mode is not optimized for production.

Developer mode: used when you’re extending the functionality of your website or customizing it.

Production: This mode is enabled when your Magento 2 website is in production.

Maintenance: this mode prevents access to a Magento website when it is being updated or reconfigured


--WHAT IS A FACTORY CLASS IN MAGENTO 2?

Factory classes are used to create, change, or get an entity without having to access the object manager since it is discouraged by Magento. These classes are created during code generation and do not need to be manually defined.



--WHAT IS DEPENDENCY INJECTION IN MAGENTO 2?

Dependency injection is used in Magento 2 to replace the Mage class functionality that Magento 1 used.


It’s a pattern in which object 1 can declare its dependencies on object 2, and then object 1 doesn’t have to worry about procuring its own dependency requirements. Object 2 will do that based on desired behavior or configurations.



--PHP OOP - Constructor

A constructor allows you to initialize an object's properties upon creation of the object.


If you create a __construct() function, PHP will automatically call this function when you create an object from a class.


--12 Design Patterns Found In Magento

Model View Controller Pattern

Front Controller Pattern

Factory Pattern

Singleton Pattern

Registry Pattern

Prototype Pattern

Object Pool Pattern

Iterator Pattern

Lazy Loading Pattern

Service Locator Pattern

Module Pattern

Observer Pattern

--20 Design Patterns Found In Magento

Factory Pattern

Singleton Pattern

Model View Controller Pattern

Front Controller Pattern

Registry Pattern

Prototype Pattern

Iterator Pattern

Object Pool Pattern

Service Locator Pattern

Lazy Loading Pattern

Observer Pattern

Module Pattern

Service Contract

Object Manager (which consist of 11+ Design Patterns)

Proxy Pattern

Factory Classes

Dependency Injection

Injectable Objects

Non-injectable objects

Active records

The main difference between plugins and observers is

Plugins can modify only public methods while observers can modify private, protected as well.

There is a sort order for plugins but there is no sort order for observers.

You can add observer only to the events that are already dispatched in Magento. Plugins are more flexible here.




Monday, 11 November 2019

Magento 2 admin product disabled filter issues

You have to copy the vendor\magento\module-catalog\Ui\DataProvider\Product\ProductCollection.php  
to
app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php  

Replace the following code in addAttributeToFilterAllStores(Attribute $attributeModel, array $condition): void function

$condition = "({$pKey} = {$fKey}) AND ("
            . $this->_getConditionSql("{$tableName}.value", $condition)

            . ')';


With 


$attributeId = $attributeModel->getAttributeId();
        $condition = "({$pKey} = {$fKey}) AND ("
            . $this->_getConditionSql("{$tableName}.value", $condition)
            . ') AND ('
            . $this->_getConditionSql("{$tableName}.attribute_id", $attributeId)

            . ')';

Friday, 8 November 2019

Magento 2 Order Grid not showing NEW orders

1 - Go to Admin panel
2 - Click Stores - Configuration
3 - Advanced - Developer - Grid Settings
4 - Set Asynchronous Indexing to "Enable"
5 - Flush cache - (php bin/magento cache:flush;)
6 - Go to the database table "sales_order_grid". You can truncate this table.
7 - run this command twice - php bin/magento cron:run
8 - Flush cache - (php bin/magento cache:flush;)
9 - Set Asynchronous Indexing to "Disable"
10 - Flush cache - (php bin/magento cache:flush;)

Saturday, 5 October 2019

10 Top Unix Shell Scripting Interview Questions And Answers

1) What is Shell?

Ans: Shell is a command interpreter, which interprets the command which the user gives to the kernel. It can also be defined as an interface between a user and operating system.

2) What is Shell Scripting?

Ans: Shell scripting is nothing but series or sequence of UNIX commands written in a plain text file. Instead of specifying one job/command at a time, in shell scripting we give a list of UNIX commands like a to-do list in a file to execute it.

3) What is the Importance of writing Shell Scripts?

Ans: The points given below explain the importance of writing shell scripts.

Shell script takes input from the user, file and displays it on the screen.
Shell scripting is very useful in creating your own commands.
It is helpful in automating some tasks of the day to day life.
It is useful for automating system administration tasks.
Mainly it saves time.

4) What are the Advantages of C Shell over Bourne Shell?

Ans: The advantages of C Shell over Bourne Shell are:

C shell allows aliasing of commands i.e. a user can give any name of his choice to the command. This feature is mainly useful when a user has to type the lengthy command again and again. At that point of time, instead of typing a lengthy command a user can type the name that he has given.
C shell provides command history feature. C shell remembers the previously typed command. Thus, it avoids typing the command again and again.

5) How many shell scripts come with UNIX operating system?

Ans: There are approximately 280 shell scripts that come with the UNIX operating system.

6) What are the default permissions of a file when it is created?

Ans: 666 i.e. rw-rw-rw- is the default permission of a file when it is created.


7) What are Shell Variables?

Ans: Shell variables are the main part of shell programming or scripting. They mainly provide the ability to store and manipulate information within a shell program.


8) What is the lifespan of a variable inside a shell script?

Ans: The lifespan of a variable inside shell script is only until the end of execution.


9) Generally, each block in UNIX is how many bytes?

Ans: Generally, each block in UNIX is of 1024 bytes.

10) What is a file system?

Ans: The file system is a collection of files which contain related information of the files.

How to check cronjob details in Magento 2?

Use the following command


crontab -l

Git fetch all data without checkout

git fetch origin master:master