:::: MENU ::::
Browsing posts in: Magento 2

Get all module list in Magento 2

This tutorial is about Get all module list in Magento 2 .i.e how to get all module or extension list in magento 2. Also the status, whether it’s enable or disabled. I assume your question is,how to get it? And in this tutorial i will try to explain it briefly and also make it convenient.

There are few ways to achieve it. We will discuss few here.

Lets start with a method, in which we can get the desired result using CLI command.

Using CLI command

There is a CLI command

bin/magento module:status

which returns the list of enabled and disbaled modules. Check the below given path to know how it’s done.

\Magento\Setup\Console\Command\ModuleStatusCommand::execute

Basically

\Magento\Framework\Module\ModuleList::getNames

returns you a list of enabled modules. Similarly

\Magento\Framework\Module\FullModuleList::getNames

returns you a full list of all modules.Furthermore we will have to do an array_diff() to get the disabled modules.

Secondly we can take help from Magento’s core codebase.

Magento Corebase

Since we already discuss the command that lists all modules:

php bin/magento module:status

Let me share with you that magento uses

\Magento\Framework\Module\FullModuleList

class to get the list of enabled and disabled modules.

Based on Magento’s implementation, I have implemented my code in the following way:

<?php
namespace QaisarSatti\HelloWorld\Block;

class Modules extends \Parent\Class
{
    protected $fullModuleList;

    public function __construct(
        \Other\Dependenciy\Classes,
        \Magento\Framework\Module\FullModuleList $fullModuleList
    ) {

        $this->fullModuleList = $fullModuleList;
    }

    public function modulesList()
    {
        ...
        $allModules = $this->fullModuleList->getAll();
        ...
    }
}

I hope it is quite efficient and fulfill its use.

Furthermore there are another two ways to get this done.

Lets have a look at the them respectively.

1.

Following code will give the enabled and disabled modules list. I have commented the code to make it easy to understand what the code is doing.

protected $fullModuleList;
protected $moduleManager;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\Manager $moduleManager,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleManager = $moduleManager;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getAll();
    $listOfModules = [];
    foreach ($allModules as $key => $value) {
        $listOfModules[] = $key;
    }
    foreach ($listOfModules as $key => $value) {
        if ($this->moduleManager->isEnabled($value)) {
            echo $value; //Enable Module List
        } else {
            echo $value; //Disable Module List
        }
    }
    ...
}
Similarly the second method is as follows.<strong>
2.</strong>

protected $fullModuleList;
protected $moduleList;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\ModuleList $moduleList,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleList = $moduleList;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getNames(); //List of All Module Names
    $enabled_list = $this->moduleList->getNames(); //List of Enabled Module Names
    $disabled_list = array_diff($enabled_list, $allModules); //List of Disabled Module Names

That’s it from this tutorial. I hope it serves the purpose.
Since these are learning tutorials,please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: November 9, 2018


Magento 2 after save and before save method

This tutorial is about Magento 2 after save and before save method .i.e how to use after save and before save methods in magento 2.I assume you want to add after save and before save method of Magento 2 in your model.So, how can we do this?. This tutorial will tell us,how we can do that?

Magento is a flexible platform and it covers almost all the basic and necessary functionalities. Magento has its own _beforeSave and _afterSave functions. You can use them in your ResourceModel using below code.

Before Save

_beforeSave function called when you tried to update or insert data in database table with your model. Then _beforeSave function is called. You can implement you logic like validation, Post data change or any other functionality you want perform.

<?php
    namespace QaisarSatti\HelloWorld\Model\ResourceModel;
    class Test extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb  {

        protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
        {
            // do your logic here

        }

 

    }

After Save

_afterSave function called when After update or insert data in database table with your model. Then _afterSave function is called. You can implement you logic like sending email, Add related data or any other functionality you want perform.

<?php
    namespace QaisarSatti\HelloWorld\Model\ResourceModel;
    class Test extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb  {

       protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
        {  
          //do your logic here
        }

    }

That’s it from this tutorial. I hope it serves the purpose.
Since these are learning tutorials,please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: November 9, 2018


Magento 2 free payment extensions

This article is about Magento 2 free payment extensions . Many people often look for payment methods of magento and find it difficult to find a suitable method or extension.In this tutorial i will try to list available free magento 2 payment extensions.This tutorial just have information of free extensions that are available on magento marketplace or any other extension provider store.I will try to list few here with brief descriptions as well.

Below are the free magento payment method extensions.

Magento payment extensions

Magento provides its own payment methods.But here we will discuss free magento shipping extensions.Because these are available for free so anyone can use them.First,lets have a look at the default magento payment methods.

Default magento payment methods:

  • Saved CC
  • Check / Money Order
  • Zero Subtotal Checkout
  • Bank Transfer Payment
  • Cash On Delivery Payment
  • Purchase Order
  • Authorize.net Direct Post
  • Authorize.net

Above are the default payment methods provided by magento.You can use them by going to configuration settings and then modifying payment methods.

Now lets have a look at the free available magento 2 payment extensions.

WAVES Crypto Currency Payments

The blockchain is the technology that has been slowly but steadily taking root in multiple spheres of businesses. It triggered the emergence of cryptocurrencies that progressively find the way into eCommerce. WAVES is the decentralized blockchain platform that focuses on custom blockchain tokens operations. It has high usability and can boast of the wallets that are securely protected to ensure that their owners are the only ones to access the crypto payments.

Key features

  • Inexpensiveness
  • Speed
  • Security
  • Transparency
  • Irreversibility

Extension Link

Ingenico ePayments

Ingenico ePayments is the online and mobile commerce division of Ingenico Group. We connect merchants and consumers, enabling businesses everywhere to go further beyond today’s boundaries and creating the future of global commerce.

Key features

  • Origin verification based on the SHA verification
  • 1-step checkout for credit cards
  • PCI compliant template handling
  • Multiple/Partial captures/refunds
  • Accept payments by mail or telephone (MOTO)
  • Send reminder mail with link to payment page
  • Display fraud result in order
  • Improve fraud detection through device fingerprinting
  • Credit/Debit card split
  • Dynamically add payment methods
  • Advanced fraud detection support

Extension Link

Stripe Payments

Stripe is a global technology company that builds economic infrastructure for the internet. Businesses of every size—from startups to public companies—use our software to accept payments and manage their businesses. Millions of companies in 120+ countries use Stripe to start, run, and scale their businesses.

Key features

  • Accept all major debit and credit cards as well as local payment methods
  • Benefit from Stripe Elements, which helps your users input their payment information quickly and correctly at checkout
  • Achieve PCI-DSS compliance with Stripe Elements hosted input fields
  • Optimized for mobile and fast checkout with Apple Pay, Google Pay, and Payment Request API support
  • Better detect and prevent fraud with the help of Stripe Radar and optional 3D Secure
    Easily capture authorizations and process refunds from your Magento Backend

Extension Link

Internal Payment Method

This extension for Magento 2 allows you to have a specific payment method in your store’s backend for capturing offline payments. With this payment method enabled, you are able to create orders in your store’s backend for your customers and they will not be visible on the checkout page.

Key features

  • Only visible at the backend orders page
  • The store admin can use the method in a similar way as other payment methods in the backend
  • Custom payment name
  • The store admin can use the method in a similar way as other payment methods in the backend
  • It’s OpenSource

Extension Link

Mollie

Mollie allows you to accept payments and donations online and expand your customer base internationally with support for all major payment methods through a single integration. No need to spend weeks on paperwork or security compliance procedures.

Key features

  • Online within minutes
  • A single solution
  • Transparent pricing
  • Serious security
  • Streamlined checkout
  • Easy refunds
  • Personal Dashboard

Extension Link

Coin Payments

oinPayments extension integrates your Magento 2 store with CoinPayments – a popular online platform that allows accepting, storing, converting, and withdrawing altcoins. At the moment, it supports 70+ cryptocurrencies and provides a unique $tag for accepting payments.

Key features

  • Magento 2 cryptocurrency trading: accept Bitcoin, Ethereum, and other altcoins as payment for products and services you sell
  • Use Magento 2 cryptocurrency wallets to store the altcoins
  • Magento 2 Ethereum wallet
  • Magento 2 Bitcoin wallet
  • Various Magento 2 altcoin wallets
  • Magento 2 Cryptocurrency PayPal integration: send payments to PayPal without any fees
  • Transparent transaction history: view separate logs for deposits, transfers, withdrawals, and conversions

Extension Link

Similarly there are many other extensions available. I tried to list a few. I hope this tutorial help you in any way.

Please feel free to drop any suggestions or queries in comments section. It will be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: November 9, 2018


Magento2 load Customer by Id

This tutorial is about Magento 2 Load Customer by Id. I assume the question arises is What is the best way to load Customer by Id?. And how can we do it?.Furthermore,there are different ways in magento 2, to do so.

Like we can do so using customer interface or customer factory.

Like i said there are many ways,But the best practice is to use service contracts.

Api Repository:

In my case i would use

\Magento\Customer\Api\CustomerRepositoryInterface

Similarly use the below code.

protected $_customerRepositoryInterface;
public function __construct(
    ....
    \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,
    ....
) {
    ....
    $this->_customerRepositoryInterface = $customerRepositoryInterface;
}

Furthermore call this function in your code like:

$customerId = 1;
$customer = $this->_customerRepositoryInterface->getById($customerId);

Factory Method:

namespace QaisarSatti\Module\Block;

class Product extends \Magento\Framework\View\Element\Template
{

  protected $customer;  


  public function __construct(
     
        \Magento\Customer\Model\Customer $customer

    ) {


        $this->customer = $customer;
     
    }
    public function getLoadProduct()
    {
        $customer_id=7;
        return $this->customer->create()->load($customer_id);
    }

}

Object Manager:

No recommended method to use in magento2 but so magento use it so here it is just for knowledge.

$customer_id=7;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerData = $objectManager->create('Magento\Customer\Model\Customer')->load($customer_id);

That’s it from this tutorial. I hope it serves the purpose.
Please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: November 18, 2018


Magento 2 create js Popup

This tutorial is about Magento 2 Create Popup.How to create Popup in magento 2.First of all i assume that you are familiar with magento 2 and hence you are at this level where you want to know how to Create Popup in magento 2. Above all if you are not familiar with advance magento concepts. Than you must look for basics,and please look for magento 2 basic tutorials.

So lets start our tutorial and focus on our topic.Lets suppose you want to create Popup in magento 2.Lets see how we can do this in a simple way.

In Magento 2 we can simply call modal popup using default modal.js library.

Create phtml file

First of all create a phtml(template) file.And paste the following code in it:

<div class="main-block">
    <div class="content">
     <a href="javascript:void(0)" id="popup-open"><?php echo __('Chart Link');?></a>
    </div>
    <!-- Your Popup content with main div display none -->
 <div id="popup-div" style="display:none;">
     YOUR POPUP CONTENT GOES HERE
 </div>
</div>
<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal',
            'domReady!'
        ],
        function($,modal) {
            $(function() {
             $("#popup-open").on('click',function(e){
                    var options = {
                        type: 'popup',
                        responsive: true,
                        innerScroll: true,
                        buttons: false
                    };
              var elementObj = $('#popup-div');
                    var popup = modal(options, elementObj);
                    elementObj.modal("openModal");
                }
            });
        }
    );
</script>

In above template file we showed popup,based on click on chart link.It means When click on chart link is defined in our DOM element, popup modal will be displayed automatically.

So the next step is to Call Magento_Ui/js/modal/modal object in your require dependency(file).

There are many default options available for modal.js file in magento 2.You can use or you can pass any of them as per your requirement in above options object.
For that below is the List of default options for modal popup.Therefore if you want to override the default value,then you can set options value in your custom template in options object.

You can modify the below code according to your needs.

    type: 'popup',
    title: '',
    subTitle: '',
    modalClass: '',
    focus: '[data-role="closeBtn"]',
    autoOpen: false,
    clickableOverlay: true,
    popupTpl: popupTpl,
    slideTpl: slideTpl,
    customTpl: customTpl,
    modalVisibleClass: '_show',
    parentModalClass: '_has-modal',
    innerScrollClass: '_inner-scroll',
    responsive: false,
    innerScroll: false,
    modalTitle: '[data-role="title"]',
    modalSubTitle: '[data-role="subTitle"]',
    modalBlock: '[data-role="modal"]',
    modalCloseBtn: '[data-role="closeBtn"]',
    modalContent: '[data-role="content"]',
    modalAction: '[data-role="action"]',
    focusableScope: '[data-role="focusable-scope"]',
    focusableStart: '[data-role="focusable-start"]',
    focusableEnd: '[data-role="focusable-end"]',
    appendTo: 'body',
    wrapperClass: 'modals-wrapper',
    overlayClass: 'modals-overlay',
    responsiveClass: 'modal-slide',
    trigger: '',
    modalLeftMargin: 45,
    closeText: $.mage.__('Close'),
    buttons: [{
        text: $.mage.__('Ok'),
        class: '',
        attr: {},
 
        /**
         * Default action on button click
         */

        click: function (event) {
            this.closeModal(event);
        }
    }],

That’s it from this tutorial. I hope it serves the purpose.
Furthermore please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: October 29, 2018


Magento 2.3 new features

Today we will talk about magento 2.3 new features. Though the magento version 2.3 is not released yet,but magento is planning to release it by the end of this year.During its imagine conference magento announced its plans for the upcoming Magento 2.3 release.Like every major release, there are various exciting features that are set to bring new opportunities for magento clients to sell to their customers, as well as notable back-end efficiencies.

In this article we will look at new features of an enhanced version.i.e magento 2.3.

Magento 2.3 new features

We will have a brief look at the new features and improvements.

PWA

A Progressive Web App is an application,built to take advantage of modern technology features. It provides the feature of caching of data so the website can be used (partially or fully) in an offline mode when internet service is unavailable.
Magento recognizes the multiple benefits to this, and in late 2017 announced its efforts in building what it calls the PWA Studio. PWA Studio will contain tools to develop and deploy a PWA for Magento’s front end. Along with PWA Studio will come a lightweight (not feature-full) demo site. The immediate benefits will be a major increase in front-end performance and a close to 10X increase in speed of onboarding new Magento front-end developers.

GraphQL

GraphQL is a query language for using APIs. With advancement in PWA,it is the need of the hour to get smaller amounts of data and to make fewer API requests.GraphQL’s query language makes this possible by allowing the requestor to request a limited subset of attributes to be returned about an entity (significantly smaller responses) and allows you to chain requests (smaller number of requests).

Magento currently supports REST and SOAP API requests that use Service Contracts. However, to support GraphQL,Magento is writing an entirely new layer that interfaces directly to the Query API. The GraphQL implementation will be the underpinnings on how a PWA frontend will retrieve the data it needs.

Declarative Database Schema

Until now the to change the schema of magento database, you can do that using InstallSchema and UpgradeSchema classes where code is written to modify the schema.

Furthermore Magento 2.3 will change the recommended way by implementing a declarative database schema. This technique will try to accomplish multiple goals, some of which were discussed here. Instead of the database schema definitions being fragmented throughout many install and upgrade scripts, it will be fully defined via XML.

Multi-Source Inventory (MSI)

Magento is introducing multi-source inventory management to Magento’s core.This will let merchants to natively manage inventory via multiple sources.This will also enhance the shipping methods like the shipping of items and tracking of stock levels from multiple warehouses,as well as inventory within retail stores to support “ship from store” and “pick up in store”.
Furthermore Magento 2.3 will also include new functionality around the reservation mechanism of inventory. Inventory is now reserved within a new table structure instead of the direct decrementing of stock. This will increase performance and prevent database unnecessary locking during the order.

Asynchronous API

The Asynchronous WebAPI allows a system to execute API calls asynchronously against the Magento REST API.Because of this, integrations don’t have to wait for requests to fully process when making the calls. This improves the performance of integrations that require many API calls, such as a bulk product integration or customer import. A separate status reporting API will be available to check on the progress of the request by ID. This functionality will be available in both Magento Commerce 2.3 and Magento Open Source.

Page Builder

One of the most amazing and waited for feature of magento is Magento’s native CMS.Magento purchased the Blue Foot CMS technology from Gene Commerce and has made that available to its Magento Commerce merchants. Page Builder is a rewrite of Blue Foot CMS using much of the same foundational features and concepts. These features include template creation, drag-and-drop layout management, and a UX that is clean and friendly to use for a non-technical user.
Page Builder will come natively with Magento Commerce 2.3 and will be available for purchase inside the Magento Marketplace for Open Source implementations.

2FA

Magento 2.3 will have enhanced security.To protect against malicious users that have obtained a password,in any way magento is implementing two-factor authentication. This extra layer of security will require a user to prove that they have access by sending a security code to their phone or email.Similar to many web applications as it is already implemented across the globe extensively.

Message Queue

Support for message queuing is being extended from Magento Commerce to Magento Open Source. Message queues enable asynchronous communication between systems.

ElasticSearch

Support for ElasticSearch is being extended from Magento Commerce to Magento Open Source. ElasticSearch, in addition to many other usages, powers Magento’s site search capabilities, including faceted search (filtering by attributes).

PHP 7.2

PHP 7.2 brings new development features, as well as an increase in performance and security.

Libsodium

Because 7.2 is dropping support for mcrypt (PHP’s go to encryption module), the libsodium module will now be used for encryption.

Import/Export Improvements

Through community engineering, many improvements in speed and usability of import/export functionality are being added to the Magento core.

Contact DEG to learn how our customized ecommerce solutions can boost engagement and improve your conversion rate.

Cache Management ACL

Magento is adding fine-grained administration access control around the ability to interact with the system cache. Caching provides a much-needed layer of performance for Magento, and in the wrong hands, performance can dramatically suffer.

Google reCAPTCHA

Magento is switching the technology used for proving that users are humans, not bots, when interacting with a site. Google’s reCAPTCHA tool will now come native.

So after knowing that what will magento 2.3 bring in, it seems really a hard worked and enhanced version.And certainly it will bring more flexibility and versatile features in magento.

Right then this article is purely informational.I hope it will serve its purpose.I am always open to queries and suggestions. Please feel free to drop any.

Author: Qaisar Satti
Category: Magento 2
Last Modified: October 29, 2018


Magento 2 add canonical link

This tutorial is about Magento 2 add canonical link .i.e how to add a canonical link to a page through it’s layout file?. I assume your question is,is it possible?
So the answer is, Yes.It is possible. And in this tutorial i will try to explain it briefly and in a simple way.

Lets suppose you have a custom page and you want to add a canonical link to it in the layout file. Well,in magento 2 we can specify meta data in the head node.Similarly it is possible to add the canonical link in the layout as well.

It is quite doable and in a very easy way.

Just put the below lines of code in your own code.

<head>
      <link rel="canonical" src="pageurl" src_type="url"/>
</head>

Furthermore change the ‘pageurl’ as per your requirements. And place it in custom layout section in admin , if you want the functionality using admin custom layout section.

That’s it from this tutorial. I hope it serves the purpose.
Since these are learning tutorials,please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: October 22, 2018


Pages:1234567...17