Category: Magento2

Magento 2 Order Delivery Date extension

The Order Delivery Date Extension gives your customers possibility to choose the date on which they want the products purchased from your store to be delivered.


      1. Simple and quick installation
      2. Allows users to provide expected shipping arrival date
      3. Users can also write comments while placing an order from your online shop
      4. Option to display shipping arrival date and comment in order view page
      5. Previous date selection is not possible
      6. Disable week off days (like Saturday and Sunday) [Stores -> Configuration -> Sales -> Order Delivery Date Settings]
      7. 100% open source
      8. No limitations, no extra costs

Download ‘Order Delivery Date’ extension for Magento 2 from here


How to create custom product type in magento2

Sometimes you need some extra product type for some needs. So today I discuss about how you can achieve this.

1. Create module.xml [app/code/SR/CustomProductType/etc]

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="SR_CustomProductType" setup_version="2.0.0">

2. Create registration.php [app/code/SR/CustomProductType]


3. Create composer.json [app/code/SR/CustomProductType]

    "name": "sr/module-custom-product-type",
    "description": "N/A",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/module-store": "100.0.0",
        "magento/module-backend": "100.0.0",
        "magento/framework": "100.0.0",
        "lib-libxml": "*"
    "type": "magento2-module",
    "version": "100.0.0",
    "license": [
    "autoload": {
        "files": [ "registration.php" ],
        "psr-4": {
            "SR\\CustomProductType\\": ""

In Magento2, xml configuration file are divided into small file. So for product type, you need to create product_types.xml inside [app/code/SR/CustomProductType/etc]

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
    <type name="customProductType" label="Custom Product Type" modelInstance="SR\CustomProductType\Model\Product\Type\CustomType" indexPriority="100" sortOrder="100" isQty="true">
        <priceModel instance="SR\CustomProductType\Model\Product\Price" />
            <attribute name="refundable" value="true"/>
            <attribute name="taxable" value="true"/>
        <type name="customProductType" />

name: custom product type code
label: Type view
modelInstance: Model class
priceModel: Price model, you can calculate price your custom need

So now create modelInstance [SR/CustomProductType/Model/Product/Type/CustomType.php]

namespace SR\CustomProductType\Model\Product\Type;

class CustomType extends \Magento\Catalog\Model\Product\Type\AbstractType
     * Delete data specific for Custom product type
     * @param \Magento\Catalog\Model\Product $product
     * @return void
    public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)

Create priceModel [SR/CustomProductType/Model/Product/Price.php]

namespace SR\CustomProductType\Model\Product;

class Price extends \Magento\Catalog\Model\Product\Type\Price


Now create a setup installer for this module

namespace SR\CustomProductType\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

 * Class InstallData
 * @package 
class InstallData implements InstallDataInterface
     * EAV setup factory
     * @var EavSetupFactory
    private $eavSetupFactory;

     * Init
     * @param EavSetupFactory $eavSetupFactory
    public function __construct(
        EavSetupFactory $eavSetupFactory
    ) {
        $this->eavSetupFactory = $eavSetupFactory;

     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        $attributes = [

        foreach ($attributes as $attributeCode) {
            $relatedProductTypes = explode(
                $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'apply_to')
            if (!in_array('customProductType', $relatedProductTypes)) {
                $relatedProductTypes[] = 'customProductType';
                    implode(',', $relatedProductTypes)

Run following command

php bin/magento setup:upgrade

You can download full module from here.

That’s it!

Process indexing from admin in Magento2

In magento2, you unable to process indexing from admin. You can only set the mode. If you need to run indexing from admin, then this module will help you.

This is independent module, so that this module can’t create any effect to core indexer module. You can use without hesitate.

After install this module go to Admin -> System -> Product Index Management
Download module from here

How to add configurable editor in Magento2 admin form

If you miss create admin module series then click here

So I working with following admin form function


So for editor configuration I am going to create a configuration class


namespace SR\Weblog\Block\Adminhtml\Blog\Editor;

class Editor extends \Magento\Framework\Data\Form\Element\Textarea
     * Adminhtml data
     * @var \Magento\Backend\Helper\Data
    protected $_backendData = null;

     * Module data
     * @var \Magento\Framework\Module\Manager
    protected $_moduleManager = null;

     * @var \Magento\Cms\Model\Wysiwyg\Config
    protected $_wysiwygConfig;

     * @var \Magento\Framework\View\LayoutInterface
    protected $_layout;

     * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
     * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
     * @param \Magento\Framework\Escaper $escaper
     * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
     * @param \Magento\Framework\View\LayoutInterface $layout
     * @param \Magento\Framework\Module\Manager $moduleManager
     * @param \Magento\Backend\Helper\Data $backendData
     * @param array $data
    public function __construct(
        \Magento\Framework\Data\Form\Element\Factory $factoryElement,
        \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
        \Magento\Framework\Escaper $escaper,
        \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
        \Magento\Framework\View\LayoutInterface $layout,
        \Magento\Framework\Module\Manager $moduleManager,
        \Magento\Backend\Helper\Data $backendData,
        array $data = []
    ) {
        $this->_wysiwygConfig = $wysiwygConfig;
        $this->_layout = $layout;
        $this->_moduleManager = $moduleManager;
        $this->_backendData = $backendData;
        parent::__construct($factoryElement, $factoryCollection, $escaper, $data);

     * Retrieve additional html and put it at the end of element html
     * @return string
    public function getAfterElementHtml()
        $config = $this->_wysiwygConfig->getConfig();
        $config = json_encode($config->getData());

        $html = parent::getAfterElementHtml();
        if ($this->getIsWysiwygEnabled()) {
            $html = <<<HTML

], function(jQuery){

var config = $config,

jQuery.extend(config, {
    settings: {
        theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' +
        theme_advanced_buttons2: null,
        theme_advanced_buttons3: null,
        theme_advanced_buttons4: null,
        theme_advanced_statusbar_location: null
    files_browser_window_url: false

editor = new tinyMceWysiwygSetup(



        return $html;

     * Check whether wysiwyg enabled or not
     * @return bool
     * @SuppressWarnings(PHPMD.BooleanGetMethodName)
    public function getIsWysiwygEnabled()
        return true;

Now inside


add following line:

                'name' => 'content',
                'required' => true,

Click here for updated code

How to programmatically create invoice in magento2

If we need to programmatically create invoice for an order then you can create by following way.

// Load the order

 $order = $this->_objectManager->create('Magento\Sales\Model\Order')
    ->loadByAttribute('increment_id', '000000009');

// OR

$order = $this->_objectManager->create('Magento\Sales\Model\Order')

if ($order->canInvoice()) {
    // Create invoice for this order
    $invoice = $this->_objectManager->create('Magento\Sales\Model\Service\InvoiceService')->prepareInvoice($order);

    // Make sure there is a qty on the invoice
    if (!$invoice->getTotalQty()) {
        throw new \Magento\Framework\Exception\LocalizedException(
                    __('You can\'t create an invoice without products.')

    // Register as invoice item

    // Save the invoice to the order
    $transaction = $this->_objectManager->create('Magento\Framework\DB\Transaction')


    // Magento\Sales\Model\Order\Email\Sender\InvoiceSender
        __('Notified customer about invoice #%1.', $invoice->getId())

How to add custom javascript in magento 2

Magento 2 ship with most popular javascript library like Jquery, requireJS, KnockoutJS. Today I discuss, how you can create a custom javascript and load using requireJS. So lets start…

If you miss my previous post Click Here

Create a custom js file following location.

], function($) {
    "use strict";

    //creating jquery widget
    $.widget('mage.srjs', {
        _create: function() {
            console.log('hey, srjs is loaded!')
            //bind click event of elem id
            this.element.on('click', function(e){
                console.log('Click ME!')


    return $.mage.srjs;

Create a phtml file. location

    <p id="elem">Click Me!</p>
<script type="text/x-magento-init">
    "#elem": { "SR_Js/js/srjs": {} }

That’s it!

Magento 2 Trashcan extension

It might have happened with each of the Magento 2 store owners out there that you deleted any product by mistakes. This extension might come in handy at that time to recovers those deleted products from the trashcan. A must have extension for all Magento 2 stores.


      Simple and quick installation
      Restore of products, including metadata and images
      100% open source
      No limitations, no extra costs
      Restore easily from the trashcan (Trashcan > Manage Trashcan)

Download TrashCan for Magento 2 from here