Wednesday, 15 August 2018

Magento 2 Areas


Magento has 5 areas types:
  1. adminhtml: entry point for this area is index.php or pub/index.php. The Admin panel area includes the code needed for store management. The /app/design/adminhtml directory contains all the code for components you’ll see while working in the Admin panel.
  2. frontend: entry point for this area is index.php or pub/index.php. The frontend contains template and layout files that define the appearance of your storefront.
  3. base: used as a fallback for files absent in adminhtml and frontend areas.
  4. webapi_rest: entry point for this area is index.php or pub/index.php. The REST area has a front controller that understands how to do URL lookups for REST-based URLs.
  5. webapi_soap: entry point for this area is index.php or pub/index.php.


Tuesday, 14 August 2018

Create a module Magento 2

1) Create folder in app/code/<Vender>/<ModuleName>, For Example using Vendor as Mywork and ModuleName as HelloWorld
2) Declear module by creating module.xml in app/code/Mywork/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mywork_HelloWorld" setup_version="1.0.0" />
</config>
3) Register the module by registration.php in app/code/Mywork/HelloWorld/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mywork_HelloWorld',
    __DIR__
);
4) Run command: php bin/magento setup:upgrade

Monday, 13 August 2018

Register Custom Theme in Magento 2

1) Create Folder in side app/design/frontend/<Vendor>/<ThemeName>
2) Declear your theme by creating theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Theme Name</title> <!-- your theme's name -->
    <parent>Magento/blank</parent> <!-- parent theme, in case your theme inherits from an existing theme -->
    <media>
        <preview_image>media/preview.jpg</preview_image> <!-- path of your theme's preview image -->
    </media>
</theme>

3) Register the theme by creating registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
   \Magento\Framework\Component\ComponentRegistrar::THEME,
   'frontend/<Vendor>/<ThemeName>',
   __DIR__
);

4)Upgrade System:php bin/magneto setup:upgrade

Magento 2 admin url not working and Frontend is messy

1) In core config table change value for web/seo/use_rewrites to 0 
2) disable versioning form admin:
    System>Advanced>developer: Static Files Settings: No

Query to do this:

INSERT INTO 'core_config_data' ('path', 'value') VALUES
VALUES ('dev/static/sign', 0) ON DUPLICATE KEY UPDATE value
ON DUPLICATE KEY UPDATE value = 0;

3) Run command to clear a configuration cache:
     magento cache:clean config

Basic Commands for Magento 2

To clear cache
php bin/magneto clean:cache
To flush cache
php bin/magneto flush:cache
To enable a module
php bin/magento module:enable
To disable a module
php bin/magento module:disable
To update module in database tables
php bin/magneto setup:upgrade
To deploy static content
php bin/magento setup:stactic-content:deploy
To set mode
php bin/magento deploy:mode:set (developer/default/production)
To view enabled mode
php bin/magento deploy:mode:show



Commands to run after new theme installation

After changing default theme to custom theme run these commends
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex
php bin/magento cache:flush
this only your theme contents and blocks indexing