Categories
Magento 2

Magento 2 – Create a New Module / Extension

How to Create Module or Extension in Magento 2 Completed Guide. We know whole Magento 2 system is built with different unique Magento system core modules. Magento is opensource eCommerce platform, So we can add/install our developed custom module on Magento project.

In this article today I discuse how to create new custom Module or Extension for Magento 2. For Magento 2 module create we need to complete the following steps:

  • 1. Create vendor directory
  • 2. Create module directory
  • 3. Create etc/module.xml file
  • 4. Create registration.php file
  • 5. Create composer.json file
  • 6. Create etc/adminhtml/system.xml file
  • 7. Run php bin/magento setup:upgrade command to install the new module
  • 8. Check your created new module is working

Module Folder and Files structure

Let’s go through complete each of above steps.

Create vendor directory

Go to app/code directory on your Magento 2 project and create a directory rename it to as your module vendor name. I have create a directory “ExtendFeature” is vendor.

Create module directory

Go to app/code/ExtendFeature directory on your Magento 2 project and create a directory rename it to as your module name. I have create a directory “HelloWorld” is my custom module name.

Create etc/module.xml file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a directory rename it to etc, Now go to etc directory and crete module.xml file. Each Magento 2 module must have this file.

Open module.xml file and add following code.

Create registration.php file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a PHP file rename it to registration.php. Each Magento 2 module must have this file.

Open registration.php file and add following code.

Create composer.json file

Go to app/code/ExtendFeature/HelloWorld directory on your Magento 2 project and create a composer.json file.

Open composer.json file and add following code.

Create etc/adminhtml/system.xml file

Now create system.xml file in etc/adminhtml/ directory, Open system.xml file and add following code. This file generated some fields on Magento 2 system configuration section. You can view configuration fields by admin menu STORE=>Configurations=>Extend Feature menu.

Run php bin/magento setup:upgrade command to install the new module

Now login into SSH terminal and go to Magento 2 project root directory and run following commands to install/active your new module.

Check your created new module is working

Each Magento 2 module after install/active by command setup:upgrade added a new line on app/etc/config.php file, Now please check the file app/etc/config.php. New module is listed by auto-generated modules that are active. Please never change config list manually!

Also check module status via SHELL command.

After apply these steps, you can successfully create/active a new module in Magento 2 project and enjoy!

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Magento 2

Magento 2 – Create custom Theme step by step

Create Magento 2 custom Theme step by step process. In Magento 2 has by default Luma and Blank themes – that you can see after installing Magento 2 successfully. Magento 2 default demonstration theme is Luma theme, and Blank is basis for custom theme creation.

We can create custom theme by call parent Luma or Blank theme. In this article I will discus create new theme by Luma parent theme.

Theme Folder and Files structure

To create a theme directory for your Magento 2, you need to go: app/design/frontend directory. Under frontend directory, create a new directory according to your theme vendor name: app/design/frontend/Extendfeature directory, I have choose Extendfeature for my theme vendor name under your theme vendor directory, create a directory for your Magento 2 theme: app/design/frontend/Extendfeature/ultimate I have choose ultimate for my theme name directory.

After creating files and folder structure, we need to declare name/title your Magento 2 theme, So that Magento knows it exists and we can set your theme as the current store theme in your Magento 2 backend.

Declare your Magento 2 theme

Now you need to create the theme.xml file under app/design/frontend/Extendfeature/ultimate/ directory and use the code below:

In <title> tag enter the name of your theme, and in the <parent> tag you can specify parent theme for fallback purposes. I am using the Luma theme. In the <preview_image> tag I declare a theme preview image.

Make Your Theme a Composer package

PHP dependency management tool is composer. it allows declare the libraries your project depends on and composer will manage install/update them for you and distribute theme as a package, we need to add a composer.json file to the theme directory.

Register your Magento 2 Custom theme

Add registration.php to register your Magento 2 Custom theme in your theme directory: app/design/frontend/Extendfeature/ultimate/registration.php and add the following content in your registration.php file.

Creating web static files, folders

For theme design view, we need to many static files such as javascript, css, images and fonts. Magento 2 are stored in separate folders in web of theme package.

Here are the structure

Configure storefront images size

Copy the view.xml file from the vendor/magento/theme-frontend-luma/etc directory of an existing theme (for example, from the Luma theme) to your theme app/design/frontend/Extendfeature/ultimate/etc directory. And let update the image configuration for storefront catalog product grid and others template page.

Configure Magento 2 Custom Theme via Admin panel

Run following commands and check your newly created theme is working.

After adding your theme to the file system, everything is ready for you to activate your theme and apply it to your magento store. Login into Magento 2 admin panel, then go to Content > Design > Themes. And make your sure your theme title appears on this list.

Custom Theme in theme list

Theme Configuration, When you can see your theme in this list, go to Content > Design > Configuration, select your newly created theme from those shown in the image below. After change your theme, click on “Save Config” button.

Theme configuration add theme

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE

Categories
Magento 2

Install Magento 2 Using Composer in localhost XAMPP server

Install Magento 2 Using Composer in localhost. In this article I will guide to you how to install composer and how to install Magento 2 with Composer in localhost XAMPP server or web server.

At first we want to know about Magento 2 System Requirements? Here is the full checklist.

Step 1: Install Composer

After setup XAMPP server go htdocs directory E:\xampp\htdocs and Download and Run the Composer Windows Installer from here:
Download Composer

Check the installation using composer -V
Output: Composer version 1.10.1 2020-03-13 20:34:27

If you want to Composer setup on web server please please login into SSH terminal and run following commands to check and install composer. If nothing displays or you face any errors, please install Composer Download Composer

Step 2: Setup Virtual Hosts

Setup Virtual Hosts and create a url for run magento project. Open E:\xampp\apache\conf\extra\httpd-vhosts.conf add following lines for setup Virtual Hosts.

Step 3: Setup a URL

Setup URL on windows host file. Open C:\Windows\System32\drivers\etc\hosts add following lines for browse site via browser.

Step 4: Download Magento 2

Go to XAMPP server htdocs E:\xampp\htdocs directory via SSH terminal and Run the following command in the htdocs directory.

Note: I have define “magento23” is project install directory in Setup Virtual Hosts section.

Step 5: Create The Database

Create an empty database to work with MySQL in case you have already created so ignore database creating step and next step.

Step 6: Install Magento 2

Run the following lines in Command Line to install your Magento 2

Magento 2 console command setup:install install Magento 2 via Command Line. If this command run without error you can see like following image:

Install Magento 2 by command line

Please check your Magento 2 project admin amd database information in app\etc\env.php file backend and db section.

Now Magento 2 setup is done in XAMPP windows server. Now write http://magento2demo.com/ in your web browser and enjoy magento 2 project.

Exception: in module: ‘Magento_Backend’ block’s name: ‘require.js’

If we gitting Exception: Invalid template file: vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml in module: ‘Magento_Backend’ block’s name: ‘require.js’

Open file vendor\magento\framework\View\Element\Template\File\Validator.php line no 138.

change line 138 from

to

See more derails Here…

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE