Allow Selected State At checkout Page

In magento In Checkout We have to allow Some specific State For That you need to customize, extend Magento functionality.

For extend this functionality you have to Make plugin To avoid conflicts in future for Upgradation of Magento 2.

If you don’t Know How to make Plugin Visit Here

After creating a Custom Module You have to Extend Function of Vendor by Plugin Method.

Create a di.xml file In Your Module  Panchal/Module/etc/di.xml

 <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Customer\Controller\Account\Create" type="Panchal\Preference\Controller\Account\Create" /> </config> 

Override Magento 2 Class using Preference Method.

In Magento, sometimes we have to customize core function and classes. Whenever we have to override or rewrite class( Controller, Block & Model) Magento provides some methods.

1) Preference Method

2) Plugin Method

Override controller using Preference method. Preference overridden all function of the controller if some function is not listed in override controller execute from the original method.

For override some function you have to create a module. For module, creation check Click here.

After creating module Make di.xml file. In module make Panchal\Preference\etc/di.xml file.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="Magento\Customer\Controller\Account\Create" type="Panchal\Preference\Controller\Account\Create" />
</config>

Now Make override controller in module Panchal\Preference\Controller\Account\Create.php
In controller, we override execute function you can override any function of this class.


<?php
namespace Panchal\Preference\Controller\Account;

class Create extends \Magento\Customer\Controller\Account\Create
{
    public function execute()
    {
		// Add your Logic here ( Restricat Some Country or IP)
		
        if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
            /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
            $resultRedirect = $this->resultRedirectFactory->create();
            $resultRedirect->setPath('*/*');
            return $resultRedirect;
        }

        /** @var \Magento\Framework\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        return $resultPage;
    }
}

Base64 is Not Defined in Magento 2.3

In Magento 2.3 Admin Theme Configuration Tab is Continous Loading or Favicon or Logo File is Not Uploading.

How to Solve :
This Magento Bug is Overcome BY change Design.config.xml

Go to In Magento root Directory then vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml

Original Code :
Line 57

        <field name="head_shortcut_icon" formElement="fileUploader">
                <settings>
                    <notice translate="true">Allowed file types: ico, png, gif, jpg, jpeg, apng. Not all browsers support all these formats!</notice>
                    <label translate="true">Favicon Icon</label>
                    <componentType>fileUploader</componentType>
                </settings>

Line 154

<field name="header_logo_src" formElement="fileUploader">
                <settings>
                    <notice translate="true">Allowed file types: png, gif, jpg, jpeg.</notice>
                    <label translate="true">Logo Image</label>
                    <componentType>fileUploader</componentType>
                </settings>

Resolved Code :
line 57

        <field name="head_shortcut_icon" formElement="imageUploader">
                <settings>
                    <notice translate="true">Allowed file types: ico, png, gif, jpg, jpeg, apng. Not all browsers support all these formats!</notice>
                    <label translate="true">Favicon Icon</label>
                    <componentType>fileUploader</componentType>
                </settings>

Line 154

<field name="header_logo_src" formElement="imageUploader">
                <settings>
                    <notice translate="true">Allowed file types: png, gif, jpg, jpeg.</notice>
                    <label translate="true">Logo Image</label>
                    <componentType>fileUploader</componentType>
                </settings>

Replace New Code with old one, then Refresh cache.

Enjoy Your Development.
Pratik Panchal.

MAGENTO 2.3.0 Theme Configuration Issue

In Magento 2.3 Admin Theme Configuration Tab is Continous Loading or Favicon or Logo File is Not Uploading.

How to Solve :
This Magento Bug is Overcome BY change Design.config.xml

Go to In Magento root Directory then vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml

Original Code :
Line 57

        <field name="head_shortcut_icon" formElement="fileUploader">
                <settings>
                    <notice translate="true">Allowed file types: ico, png, gif, jpg, jpeg, apng. Not all browsers support all these formats!</notice>
                    <label translate="true">Favicon Icon</label>
                    <componentType>fileUploader</componentType>
                </settings>

Line 154

<field name="header_logo_src" formElement="fileUploader">
                <settings>
                    <notice translate="true">Allowed file types: png, gif, jpg, jpeg.</notice>
                    <label translate="true">Logo Image</label>
                    <componentType>fileUploader</componentType>
                </settings>

Resolved Code :
line 57

        <field name="head_shortcut_icon" formElement="imageUploader">
                <settings>
                    <notice translate="true">Allowed file types: ico, png, gif, jpg, jpeg, apng. Not all browsers support all these formats!</notice>
                    <label translate="true">Favicon Icon</label>
                    <componentType>fileUploader</componentType>
                </settings>

Line 154

<field name="header_logo_src" formElement="imageUploader">
                <settings>
                    <notice translate="true">Allowed file types: png, gif, jpg, jpeg.</notice>
                    <label translate="true">Logo Image</label>
                    <componentType>fileUploader</componentType>
                </settings>

Replace New Code with old one, then Refresh cache.

Enjoy Your Development.
Pratik Panchal.

Magento 2.3.0 Localhost (Frontend are Blank)

Frontend is Blank

All Template File is Not loading

After installing Magento 2.3 on localhost, some-time Magento all Template file is not loading, due to that Frontend id blank.

For debugging set developer mode in Magento. Then you got error Require-js.phtml is not defined or valid.

How to Solve it.

Open Magento\vendor\magento\framework\View\Element\Template\File\Validator.php File and edit Line no 138.
Old Code :

$realPath = $this->fileDriver->getRealPath($path);

New Code :

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));

Replace New Code with old one, then Refresh cache.

Enjoy Your Development.
Pratik Panchal.

Create a Custom Magento Module

Magento Custom Module

Magento will provide all feature but sometimes we want to extend Magento basic function or class, make some content based extension (plug-In) or make some website(ex. e-bay, Amazon), application(ex. payment method, shipping method) integration for Magento 2.

How to make Custom Module ?, Which file is required?, Where to put in Magento root folder?

Magento is a bunch of many modules. specific features have own module in Magento like for product module name “module-catalog”. Custom Module Structure is same like Magento default module structure.
In custom module three file is required.
1) registration.php
2) etc/module.xml
3) composer.json (required if module want to install using SSH.)

Sample File of all Required Files.

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'CodeWithGeek_Custom',
    __DIR__
);

Module.xml File is register module when deploy a magento. module.xml put in etc folder. “etc” folder located in Custom module root directory. In code is there, it means your module will be executed after tis module.

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="CodeWithGeek_Custom" setup_version="1.0.0"></module>
        <sequence>
            <module name="Magento_Backend"/>
             <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Checkout"/>
        </sequence>
</config>

composer.json

{
    "name": "codewithgeek/custom",
    "description": "CodeWithGeek Custom",
    "require": {
      "php": "~5.6.0|7.0.2|~7.0.6",
      "magento/magento-composer-installer": "*"
    },
    "type": "magento2-module",
    "version": "0.74.0-beta4",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "extra": {
        "map": [
            [
                "*",
                "CodeWithGeek/Custom"
            ]
        ]
    }
}

Magento Architecture & Customization (Part – 3)

Magento Module Section

Module located in ‘App/code/Vendor_Name/Module_Name’ or using composer located in ‘Vendor/Vendor_Name/Module_Name’.

In Vendor_Name/Module_Name these section is included…

  • API: New API interface class or extended api interface class of core magento 2.
  • Block: PHP files of blocks. block PHP file is to collect data from the model and use in PHTML. In the layout file, we also declare a support block for PHTML.
  • Console: PHP classes for CLI (Command Line Interface) calls. Need to create this class when in the module we create some extra command who handle module operation by SSH.
  • Controller: Controller is defined as Two types. Who route in Magento admin that define in ‘Controller/Adminhtml’ directory & route in frontend that defines in ‘Controller’ directory. controller template URI is normally defined as uri_1/uri_2/Controller. uri_1 & uri_2 is define in module’s  route.xml.
  • etc: This directory contains two directory frontend & adminhtml. In this directory module.xml is required file for creating a module, also config.xml, di.xml, ack.xml, and Cron’s XML files are also included in etc, frontend or adminhtml directory as per requirement.
  • Helper: Auxiliary classes. these classes access in controller, block and in PHTML.
  • i18n: Language Pack CSV is uploaded here. Like de_DE/de_DE.csv.
  • Model: models, model resources are defined. A model who collects data and interact with View. Resource model is the connection between MySql and Model.
  • Services: These sections contain many Directory. Directory’s list is Observer, Plugin & UI.
    1. Observer: Observer Directory contains an event class. Magento has many predefined events so some module wants to use event then define in etc/di.xml and their classes are in Observer.
    2. Plugin: Plugin’s PHP file who’s extended version of Magento core Module, Controller & Block’s file.
    3. Ui: Required UI Components of a module.
  • Setup: This directory contains database files.
    1. InstallSchema.php: Create Database
    2. InstallData.php: Installation Data (Customer’s, Category’s, Product’s attributes)
    3. UpgradeSchema.php: Update Database
    4. UpgradeData.php: Update Data (Customer’s, Category’s, Product’s attributes)
  • Test: This Directory contains Test Data of Module.
    • View: Template( PHTML, HTML), CSS, js, media file. As usual, This directory contains divide into Adminhtml, Frontend & Base (Applied for both Adminhtml, frontend) Directory. This Directory is used to collect user input and display data according to the user’s data.
  • registration.php: This file is required for a module.
  • composer.json:  This file is required if a module is installed by the Composer. this JSON schema is contained the dependent module, module version, PHP version and other require module and system.

Magento Architecture & Customization (Part – 2)

Make own module in Magento 2.

  • Why create a module?

Magento is basically a collection of a module, Developer needs to create module whenever Magento shop want to extend & change core feature, add some extra logic or feature, add extra content & integration of other websites(eBay, Instagram,  Amazon etc.) with Magento.

  • Where located module?

Magento core module is located in Magento directory ‘vendor/magento’.  If we create module we have to place in ‘vendor’ folder or ‘app/code/’. if we have to put a module in vendor required module compser.json file.

  • How to create a Module?

First, we have to declare module name like {company_name}{module_name}.

  • Which section and file are included in the Module structure?

In module required file is

  1. Registration.php
  2. Composer.json
  3. etc Folder
  4. In etc folder Module.xml
  • How to install and uninstall module?

Magento Module is installed by two method

  1. Copying Module files in ‘app/code’ or ‘vendor’ directory.
  2. Install by Composer through SSH. (Module have the compulsory composer.json file)

Magento Architecture & Customization (Part – 1)

Magento is MVC Framework, Magento module architecture is EDA.

What is MVC Framework?

  • Model: Work with data, stores, take out data from the database. It is also work in data performance and accuracy of data optimization.
  • View: Showing changes of the system to a user according to data of the model.
  • Controller: Interaction between View and Model. Collect Data from Model and Display on View.

Now Discuss Magento module architecture, Magento module is implemented by MVVM architecture.

  • Model: This model behaves as a normal model. Data management, data handling is performed in this section.
  • View: Graphical Interface handle, Interaction process handle between model and View Model. sending values according to user input in View Model.
  • View Model: this section provides or displays user data, that comes from View section. Model present so converts data into view.

Interaction of the View and View model is identified as a presentation layer. Interaction of the Model and View Model is identified as a Business logic layer.