Magento 2 Development

  1. Magento 2 Create Invoice Programmatically

    Invoice is an element of the Magento order processing that is as important as the order itself. An invoice is a document that signifies the "agreement" between a store and a person and contains all of the order details. 

    Usually, order invoices in Magento 2 are created automatically, once the payment was authorized or captured by the store. However, there are cases when you need to create an invoice programmatically in Magento 2.

    This is just the case. We will show you how to do this is in just 1 step:

    Read more »
  2. Run Magento 2 Static Content Deploy Like a Pro

    Magento 2 static content deploy is the Magento feature that helps to keep the user experience at the top levels. Why? It ensures your store pages are built correctly, static view files are downloaded by the browser, and static content is displayed according to user requests.

    In this comprehensive guide, you will find everything you need to know about static content deploy in Magento 2: what it is, reasons to use it, how to deploy static content in Magento 2 in three different ways and how to reduce deployment time to zero.

    Moreover, we’ll cover the static content deployment strategies and examples to help you comprehend the topic better.

    Read more »
  3. Magento 2 Preferences

    Magento 2 Preferences is used by the Magento 2 object manager to extend the default implementation. You can use preferences in Magento 2 to implement some interfaces or to rewrite/override the existing PHP classes and their methods. 

    In this article, you'll learn how to do it and discover useful examples that will help you along the way.

    Read more »
  4. Magento 2 Object Manager

    Magento 2 Object Manager is a PHP class responsible for creating and retrieving objects in Magento 2. It also manages to create factories and proxies.

    How does it work?

    To get the object manager instance use the code:

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    To add object Manager to constructor:

         * @var \Magento\Framework\ObjectManagerInterface
        private $objectManager;
         * @param \Magento\Framework\ObjectManagerInterface $objectmanager
        public function __construct(
            \Magento\Framework\ObjectManagerInterface $objectmanager
        ) {
            $this->objectManager = $objectmanager;

    Using the ObjectManager you can get a singleton object (method "get") of PHP class or create a new one (method "create").


    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    Read more »
  5. Create Configurable Product in Magento 2 Programmatically

    Creating configurable products you just` create simple products with some configurable options for customers to choose from. So, to create a configurable product programmatically you should start by creating a simple product and then assigning some features to it. 

    Follow these steps to create a configurable product in Magento 2 programmatically:

    Read more »
  6. How to Create Simple Product Programmatically in Magento 2?

    Magento 2 being a multifunctional e-commerce platform allows you to create products from the admin panel. There are plenty of options to fill out to create a simple product in Magento 2, which obviously takes some time.

    And what if you have to create a huge amount of products, especially during the development or testing? 

    The easiest, in this case, would be to create products programmatically. And that is exactly what you're going to learn in this article.

    Use the following method to create a simple product in Magento 2 programmatically:

    $state = $objectManager->get('\Magento\Framework\App\State');
    Read more »
  7. How to Pass Magento 2 Certification [Useful Tips]

    Magento has developed several certificates for Magento 2, one of which is — Magento 2 Certified Professional Developer.

    To get this certificate, you need to take an exam to test your knowledge and skills required to modify Magento 2 in the following areas: user interface, databases, admin panel, ordering process, catalog and extensions functionality.

    The Magento 2 Developer Exam is for those who have a deep understanding of the Magento concepts and experience of developing Magento 2. It is recommended that you have not less than 1.5 years of experience in customizing Magento 2 before applying for the exam.

    The exam consists of 60 single and multiple choices questions in English. The duration time is 90 minutes (1.5 hour). To successfully pass the exam you need to receive 64% or higher.

    In this article, we will walk you through the low-cost options to prepare for the Magento 2 Certification without courses such as, for example, Magento U for $ 950.

    Read more »
  8. How to Create Custom Cron Job in Magento 2?

    Magento 2 is a complex unity of features that help you to build a successful, easily-manageable store. There are a lot of processes to be handled in Magento 2 admin that require automation and scheduling. And that is exactly where cron job comes in handy. So...

    Let's find out what exactly is it, why you need it and how to create custom cron job in Magento 2.

    What is Magento cron job?

    Magento cron job — is one of the most important Magento 2 features. It helps to configure commands or script that systematically runs and performs the tasks you intend it to.

    With the cron job you don't need to manually reindex, generate google sitemaps, send Magento emails, update currency rates etc. The cron job does it all for you automatically, on a specific date and time if you configure it correctly. 

    Read more »
  9. How to Run Magento 2 Code in External File/Script?

    Sometimes you need to run Magento 2 code externally, in the following cases:

    • Magento 2 integration with other frameworks or platforms that are installed on the same web server,
    • quick test execution of some method, for example, cron job.

    Read more »
  10. Magento 2 Plugin | Before, After, Around Plugins Example

    In Magento 2 you can create plugins (interceptors) that allow you to extend functionality and execute your own code before, after, or around any PHP class public method. 

    For example there is a PHP class with public functions "setName", "getName", "save":


    namespace VendorName\ModuleName\Folder;

    class SomeModel
    private $name;

    public function setName($name, $storeId = 0) {
    $this->name[0] = $name;

    public function getName($storeId = 0) {
    return $this->name[$storeId];

    public function save($fields, $customData) {
    /* some save logic here */

    How to create plugin in Magento 2?

    1. Create the etc/di.xml file in your module folder and add the following code there:

    <?xml version="1.0"?>
    <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="VendorName\ModuleName\Folder\SomeModel">
            <plugin name="mycompany_mymodule_plugin_modulename_Folder_somemodel"
                    type="MyCompany\MyModule\Plugin\ModuleName\Folder\SomeModelPlugin" sortOrder="10" />
    Read more »
  11. Load Data from Magento 2 Database

    In the previous article you learned how to create new tables in Magento 2 database. In this one, you will learn more about the models used to work with the Magento 2 database which allows you to read, edit and delete the data. 

    Magento 2 and Magento 1 uses the Model/ResourceModel/Collection ORM (Object-relational mapping) for these purposes. To implement this concept you need to create 3 files (model, resource model, collection).

    Read more »
  12. Override Magento 2 Storefront View Files in Theme

    When developing an online store based on Magento 2, you might face the problem of extending the standard Magento 2 or Magento 2 extensions functionality.

    Editing Magento core files or modules is not allowed because these changes will be overwritten during the upgrade.

    So, how to make changes to the storefront (frontend) template file, css, js?

    WARNING! The following instructions cannot be used to override the layout files.

    Override module view-files in the app/code folder.

    Let's say you need to change this file:


    Make its copy in the theme folder with the following path:


    Make the necessary changes to the newly created theme file.

    If your own theme is missing from your Magento installation, create new theme.

    Read more »
  13. Change Attribute from DROPDOWN to TEXT in Magento 2

    If you want to change product attribute type from dropdown to text in Magento 2, all you need to do is to run the following SQL queries (please make a Database backup before execution):

    1. This query will change the attribute settings and convert it to a text attribute.

    UPDATE eav_attribute SET
    backend_type = "varchar",
    frontend_input = "text",
    source_model = ""
    WHERE attribute_code = "MY_ATTRIBUTE_CODE";

    2. This query will copy dropdown attribute data to the text attribute value table and replace the option IDs with their actual labels (text).

    INSERT INTO catalog_product_entity_varchar
    SELECT null as value_id, pei.attribute_id, pei.store_id, pei.entity_id, aov.value as value
    FROM catalog_product_entity_int pei
    LEFT JOIN eav_attribute_option ao ON pei.attribute_id = ao.attribute_id
    LEFT JOIN eav_attribute_option_value aov ON ao.option_id = aov.option_id
    pei.value IS NOT NULL
    AND pei.attribute_id
    Read more »
  14. Magento 2 Get Current Store ID, Code, Name, Website ID, URL

    Sometimes, during Magento 2 customization you need to get the store Information programmatically. You may need to get a current Store ID, Store Code, Name, Website ID, or current URL. 

    To retrieve this data use the singleton instance of the following class:


    For example, you can include it in your class constructor and then call:


    namespace \MyCompany\ExampleModule\Model;

    class Example
    private $storeManager;
    public function __construct( ... \Magento\Store\Model\StoreManagerInterface $storeManager, ... ) {
    ... $this->storeManager = $storeManager; ... }     /**
        * Examples
    Read more »
  15. Get URLs in Magento 2

    Get URL in the .phtml template files

    1. Get URL of the store homepage (

    <?= $this->getUrl() ?>

    2. Get URL of some page, e.g. "Contact Us" (

    <?= $this->getUrl('contacts') ?>

    3. Get URL of the theme static file, e.g.:


    use the following code:

    <?= $this->getViewFileUrl('css/custom.css') ?>
    <?= $this->getViewFileUrl('Magefan_Blog::js/lazyload.js') ?>
    Read more »
  16. List of Magento 2 Admin Panel Menu Identifiers

    Menu Title [identifier]

    Dashboard [Magento_Backend::dashboard]
    Sales [Magento_Sales::sales] Operations [Magento_Sales::sales_operation] Orders [Magento_Sales::sales_order] Invoices [Magento_Sales::sales_invoice] Shipments [Magento_Sales::sales_shipment] Credit Memos [Magento_Sales::sales_creditmemo] Billing Agreements [Magento_Paypal::paypal_billing_agreement] Transactions [Magento_Sales::sales_transactions]
    Read more »
  17. How to Add New Element to Magento 2 Admin Panel Menu?

    The etc/adminhtml/menu.xml file is used to control the Magento 2 admin panel menu and add new items to it, in particular.

    Меню адмін-панелі Magento 2

    Read more »
  18. Default Values for the Magento 2 Configuration Page

    In the previous article we described how to create your own section on the Magento 2 configuration page (Stores > Configuration).

    In order to set the default values for the configuration fields, you need to create the following file in the module folder:


    and add this code:

    <?xml version="1.0"?>
    <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">

    Read more »
  19. Extend the Magento 2 Access Control List

    In the previous article we explained how to configure and delimitate access rights for the Magento 2 admin panel users. In this article, you will learn how to create your own access rules (Role Resources).

    User Role Reasources in Magento 2

    You need to create ACL file (ACL - Access Control List) in your module folder:


    Read more »
  20. How to Create Configuration Section (system.xml) in Magento 2?

    To find the Magento 2 configuration page navigate to Magento 2 Admin Panel > Stores > Configuration.

    Налаштування Magento 2

    All tabs and forms on this page are customized using this file


    Read more »
Posts loader