:::: MENU ::::
Monthly Archives: October 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


Cookie in magento 2

This tutorial is about Use or Set cookie in magento 2. i.e how to set or use cookie in magento 2?. Suppose you want to set a value to the cookie in a phtml file and need to get it’s value in another phtml file.

There are many ways in magento 2.I will try to discuss some in this tutorial.
Certainly magento uses jquery and it is possible to set and get the values using jQuery.

First of all lets have a look at our first setp. i.e

Set the cookies

You can set the cookies using below code:

<script>
    require([
        'jquery',
        'mage/cookies'
    ], function ($) {
       $.cookie('cookie_name', 'value', { path: '/' });//Set the cookies
    });
</script>

Please note that if you want to get the value from another page, notice the path setting { path: ‘/’ }!

Because cookies are only accessible to the specified path and any subpaths.

Similarly to get cookies:

Get Cookies

<script>
    require([
        'jquery',
        'mage/cookies'
    ], function ($) {
        var temp = $.cookie('cookie_name');//Get the cookies
    });
</script>

Similarly another piece of code is as below:

<script>
    require(
        [ 'jquery'],function($){
            //set cookie
            $.cookie('customname', 'customvalue', { expires: 365, path: '/' });

            //get cookie
            getCookieValue(customname)
        });

        function getCookieValue(cookiename) {
                var name = cookiename + "=";
                var cookieSplit = document.cookie.split(';');
                for(var i = 0; i <cookieSplit.length; i++) {
                    var a = cookieSplit[i];
                    while (a.charAt(0)==' ') {
                        a = a.substring(1);
                    }
                    if (a.indexOf(name) == 0) {
                        return a.substring(name.length,a.length);
                    }
                }
                return "";
            }
</script>

Furthermore there are other way too to do so. I am going to discuss them below. Wil try to keep it short and precise.

Create Cookie

Create a test controller to create:

app/code/QaisarSatti/HelloWorld/Controller/Cookie/Addcookie.php

<?php
namespace QaisarSatti\HelloWorld\Controller\Cookie;
class Addcookie extends \Magento\Framework\App\Action\Action
{
const COOKIE_NAME = 'test';
const COOKIE_DURATION = 86400; // lifetime in seconds
/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/

protected $_cookieManager;
/**
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
*/

protected $_cookieMetadataFactory;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
*/

public function __construct(
     \Magento\Framework\App\Action\Context $context,
     \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
     \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
)
{
     $this->_cookieManager = $cookieManager;
     $this->_cookieMetadataFactory = $cookieMetadataFactory;
     parent::__construct($context);
}
public function execute()
{
     $metadata = $this->_cookieMetadataFactory
         ->createPublicCookieMetadata()
         ->setDuration(self::COOKIE_DURATION);
     $this->_cookieManager->setPublicCookie(
         self::COOKIE_NAME,
         'YOUR COOKIE VALUE',
         $metadata
     );
     echo('Create Cookie');
}
}

Similarly to Read cookie

Read Cookie

Create a Readcookie.php controller to read cookie

app/code/QaisarSatti/HelloWorld/Controller/Cookie

<?php
namespace QaisarSatti\HelloWorld\Controller\Cookie;
class Readcookie extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/

protected $_cookieManager;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
*/

public function __construct(
     \Magento\Framework\App\Action\Context $context,
     \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
)
{
     $this->_cookieManager = $cookieManager;
     parent::__construct($context);
}
public function execute()
{
     $cookieValue = $this->_cookieManager->getCookie(\[Name_Space]\[Your_Module]\Controller\Cookie\Addcookie::COOKIE_NAME);
     echo($cookieValue);
}
}

Furthermore Delete Cookie.

Delete Cookie

Create a Deletecookie.php controller to create cookie.

<?php
namespace QaisarSatti\HelloWorld\Controller\Cookie;
class Deletecookie extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\Stdlib\CookieManagerInterface
*/

protected $_cookieManager;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
*/

public function __construct(
     \Magento\Framework\App\Action\Context $context,
     \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
)
{
     $this->_cookieManager = $cookieManager;
     parent::__construct($context);
}
public function execute()
{
     $this->_cookieManager->deleteCookie(
         \[Name_Space]\[Your_Module]\Controller\Cookie\Addcookie::COOKIE_NAME
     );
     echo('DELETED');
}
}

Hence above mentioned steps are the shortest process for you to Use Cookie in Magento 2. I have tried to provide you the code with simple logic.

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


Magento 2 shipping extensions

Today we will discuss about Free magento 2 shipping extensions.In this tutorial we will discuss available free magento 2 shipping extensions.This tutorial just have information of free extensions that are available on magento marketplace or any other extension provider.I have tried to list a few.So let’s start with our list.

Free magento 2 Shipping extensions

Magento provides its own shipping methods.Yet here we will discuss free magento shipping extensions.Because these are available for free so anyone can use them.Lets have a look.

Shipping Flat Rate5

This is an upgraded extension that allows the merchant to offer a single flat rate shipping option to their Magento store by serving multiple flat rate methods based on different prices and conditions. This extension overcomes the limitation of having only one flat rate shipping method available in Magento.

Key features:

  • Complete backend configuration
  • Create 5 flat rate shipping methods with different prices and conditions
  • Magento Multi-Store full support and Multiple Currencies as well
  • Select admin section of shipping methods
  • Shipping methods a enable/disable setting
  • Set minimum/maximum order amount for free shipping feature
  • Flat rate shipping methods in fixed manner
  • Dispaly diferent error message for specific shipping method.

Extension Link

ShipRocket

It is a unique E-commerce Shipping Solution which gives access to multiple courier partners on a single platform. With Shiprocket, merchants can automate their shipping seamlessly without any technical know how.
Shiprcoket offers four plans:

  • Lite
  • Basic
  • Advanced
  • Pro

Key features:

  • Automatic Order Sync
  • Automatic shipping status sync
  • Catalog and Inventory sync

Extension Link

MatrixRate Table Rate Shipping

The MatrixRate shipping extension enables you to offer multiple shipping options to customers based on their location.

Key features:

  • The most popular multiple table rates extension for Magento
  • Display multiple delivery methods
  • Customize shipping rates based on destination
  • Customize shipping rates based on cart weight, subtotal or quantity
  • Pattern-based zipcode filtering to determine shipping charges
  • Supports zipcode numerical ranges (e.g. 5000-6000)
  • Proven success across the world – used widely in the UK, Europe, US and Australia
  • Excellent documentation, including walkthrough examples

Extension Link

bpost Shipping Manager

This module implements 5 new shipping methods in Magento. The merchant can create bpost shipping and return labels in the administration panel of Magento. These labels can be generated in bulk or for each order separately.The tracking numbers are automatically filled in.

Key features:

  • Receive your parcel at home or at the office (national or international)
  • Over 1.250 locations (pick-up points) nearby home or the office
  • Pick-up your parcel whenever you want, thanks to the 24/7 service of bpost (parcel locker)
  • Pick-up your parcel on your own shops thanks to Click&Collect delivery method

Extension Link

Shipping Easy

Your orders will automatically download from Magento to ShippingEasy, where powerful automation streamlines carrier/service selection and printing of shipping labels, packing slips, and pick lists, with carrier and tracking information automatically sent back to Magento. Includes full support for leading carriers: USPS, UPS, FedEx, and DHL.

Key features:

  • Savings add up quickly using ShippingEasy
  • Save time on multichannel order fulfillment
  • Streamline inventory processes with Inventory Management
  • Increase sales with Customer Marketing
  • A powerful enterprise platform for high-volume shippers

Extension Link

Advanced Shipping

With Advanced Shipping, you can set shipping fees by using almost all the variables available, such as destination, weight, price, quantity, categories, product attributes, item options, the customer group, customer attributes, coupon codes, Magento custom variables, date, etc.

Key features:

  • Manage one shipping mode or carrier
  • Several conditional shipping methods
  • Shipping fees based on destination, weight, price, quantity
  • Shipping fees based on the customer group or customer attribute
  • Shipping fees based on categories, product attributes or item options
  • Shipping fees based on custom variables, the coupon code, the date
  • Shipping fees based on formulas combining all the variables you need
  • Filtering zip codes with regular expressions
  • Extension used in many countries in the world
  • Documentation in english

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: October 22, 2018


Magento shipping extensions

Today we will discuss about Free magento shipping extensions.In this tutorial we will discuss available free magento shipping extensions.This tutorial just have information of free extensions that are available on magento marketplace or any other extension provider.I have tried to list a few.So let’s start with our list.

Free magento Shipping extensions

Magento provides its own shipping methods.Yet here we will discuss free magento shipping extensions.Because these are available for free so anyone can use them.Lets have a look.

ShipperHQ

ShipperHQ provides you the options to fully control and customize your shipping rates like never before. You define the carriers to use, the shipping methods that apply, and the unique rules of your own rate structure.

Key features:

  • Multi Carrier Support
  • Fully Customizable Rate Management
  • Dimensional Shipping
  • Multi-Origin Shipping
  • Date & Time

Extension Link

R+L Carriers Freight Shipping

R+L Carriers is an American private freight shipping company who provides freight services such as LTL, Truckload, Logistics, and more.Freight shipping is used when large and heavy items need to be shipped.This extension provides the integration of R+L Carriers Freight to show freight shipping quotes and delivery tracking on your Magento® store.This extension fetch live freight rates from R+L Carriers using their available Rate Quote API.

Key features:

  • Retrieve live rates from the R+L Carriers freight
  • Supports accessorial services and can be manage from the admin
  • Set Min/Max package weight to show freight rates from R+L Carriers
  • Support all product types
  • Support Magento® multi store functionality
  • Assign a store freight class or assign freight classes per product basis

Extension Link

ShipStation

ShipStation is a powerful, yet easy to use web-based, multi-channel, multi-carrier shipping solution designed to facilitate the order fulfillment process for your Magento store. ShipStation downloads your orders in real-time, allows you to create USPS, UPS, FedEx, DHL, Royal Mail, Canada Post, Australia Post, and more shipping labels and packing slips in batch, and communicates tracking information to your customers.

Key features:

  • Print Shipping Labels and Packing Slips in Batch
  • Consolidate Orders from Multiple Channels
  • Unlimited Selling Channels
  • No Software to Install
  • Free USPS Provider Account

Extension Link

Shipwire Fulfillment Platform

This extension provides Magento Enterprise and Community edition merchants with e-commerce order fulfillment, shipping software, and cloud-based logistics services from fulfillment centers around the world.Also the Shipwire Platform helps brands grow sales, expand into new markets, and delight their customers by eliminating shipping and storage hassles.

Key features:

  • Order entry sync
  • Order tracking
  • Inventory status
  • Shipping rates

Extension Link

Shipping Tracker

This versatile extension lets you customize the shipment tracking links provided to your customers. Shipping Tracker is easy to set up and supports up to five carriers as long as they provide a tracking URL and reference number. Shipping Tracker uses the Magento mechanism to add a tracking ID to a shipment. When you create a shipment, select a tracking carrier you have configured and add the tracking ID.

Key features:

  • Embeds shipment tracking links in shipping confirmation emails
  • Completely generic – not tied to any carrier
  • Supports up to five carriers at any one time
  • Features a dropdown menu with known tracking URLs from major shipping carriers
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 1
Last Modified: October 22, 2018


Pages:12