Best way to Edit Default files & Apply Custom Application in Magento 2.3?












0














What are all the best way to edit core files in Magento 2.3. eg: magento 1.9 edit app/code/local or community instead of app/code/core.



Note: What are all files I need to focus for Future Version updates.










share|improve this question

















This question has an open bounty worth +50
reputation from zus ending in 6 days.


Looking for an answer drawing from credible and/or official sources.












  • 1




    Still Looking Best Answer...
    – zus
    Dec 27 '18 at 5:49










  • Please check my answer
    – Sourav
    yesterday










  • Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
    – Aditya Shah
    yesterday
















0














What are all the best way to edit core files in Magento 2.3. eg: magento 1.9 edit app/code/local or community instead of app/code/core.



Note: What are all files I need to focus for Future Version updates.










share|improve this question

















This question has an open bounty worth +50
reputation from zus ending in 6 days.


Looking for an answer drawing from credible and/or official sources.












  • 1




    Still Looking Best Answer...
    – zus
    Dec 27 '18 at 5:49










  • Please check my answer
    – Sourav
    yesterday










  • Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
    – Aditya Shah
    yesterday














0












0








0


1





What are all the best way to edit core files in Magento 2.3. eg: magento 1.9 edit app/code/local or community instead of app/code/core.



Note: What are all files I need to focus for Future Version updates.










share|improve this question















What are all the best way to edit core files in Magento 2.3. eg: magento 1.9 edit app/code/local or community instead of app/code/core.



Note: What are all files I need to focus for Future Version updates.







upgrade core magento2.3 edit application






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 26 '18 at 7:25









Amit Bera

57.2k1374170




57.2k1374170










asked Dec 26 '18 at 7:02









zus

83116




83116






This question has an open bounty worth +50
reputation from zus ending in 6 days.


Looking for an answer drawing from credible and/or official sources.








This question has an open bounty worth +50
reputation from zus ending in 6 days.


Looking for an answer drawing from credible and/or official sources.










  • 1




    Still Looking Best Answer...
    – zus
    Dec 27 '18 at 5:49










  • Please check my answer
    – Sourav
    yesterday










  • Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
    – Aditya Shah
    yesterday














  • 1




    Still Looking Best Answer...
    – zus
    Dec 27 '18 at 5:49










  • Please check my answer
    – Sourav
    yesterday










  • Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
    – Aditya Shah
    yesterday








1




1




Still Looking Best Answer...
– zus
Dec 27 '18 at 5:49




Still Looking Best Answer...
– zus
Dec 27 '18 at 5:49












Please check my answer
– Sourav
yesterday




Please check my answer
– Sourav
yesterday












Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
– Aditya Shah
yesterday




Hello @zus, I recommend if you just want to modify output on minor customization I recommend Plugins for the same. Override via preference is for big customization not for small.
– Aditya Shah
yesterday










3 Answers
3






active

oldest

votes


















0















For new storefront theme







  1. Create a directory for the theme under app/design/frontend/<your_vendor_name>/<your_theme_name>.


  2. Add a declaration file theme.xml and optionally create etc directory
    and create a file named view.xml to the theme directory.


  3. Add a composer.json file.

  4. Add registration.php.

  5. Create directories for CSS, JavaScript, images, and fonts.

  6. Configure your theme in the Admin panel.


Create a theme directory
To create the directory for your theme:




  1. Go to /app/design/frontend.


  2. Create a new directory named according to your vendor name:
    /app/design/frontend/.


  3. Under the directory, create a directory named according to
    your theme.





app/design/frontend/
├── <Vendor>/
│ │ ├──...<theme>/
│ │ │ ├── ...
│ │ │ ├── ...


Create directories for static files
Your theme will likely contain several types of static files:




  • Styles

  • Fonts

  • JavaScript

  • Images


Each type should be stored in a separate sub-directory of web in your theme folder:



app/design/<area>/<Vendor>/<theme>/
├── web/
│ ├── css/
│ │ ├── source/
│ ├── fonts/
│ ├── images/
│ ├── js/


Your theme directory structure now
At this point your theme file structure looks as follows:



app/design/frontend/<Vendor>/
├── <theme>/
│ ├── etc/
│ │ ├── view.xml
│ ├── web/
│ │ ├── images
│ │ │ ├── logo.svg
│ ├── registration.php
│ ├── theme.xml
│ ├── composer.json


Recommended reading




  • Theme

  • Checklist of modules

  • Static view files processing



For Block




Build directories just like above -



magento2 --- app --- code

|--- Sample --- HelloWorld

| --- Block

| --- etc

| --- module.xml

| --- di.xml



  • Create module.xml to define a Magento 2 extension:




<?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="Sample_HelloWorld" setup_version="0.0.1"/>

</config>



  • Set preference in di.xml


Create di.xml to refer the overriding block class:



<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

<preference for="MagentoThemeBlockHtmlTitle" type="SampleHelloWorldBlockHelloTitle" />

</config>



  • Define an overriding class


Define HelloTitle.php under magento2/app/code/Sample/HelloWorld/Block:



<?php

namespace SampleHelloWorldBlock;

use MagentoFrameworkViewElementTemplate;

class HelloTitle extends MagentoThemeBlockHtmlTitle

{
public function getPageTitle()
{
return 'haha9999';
}

protected function _toHtml()
{
$this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTitle'));

return parent::_toHtml();
}
}



For Models




Create Directories



magento2 --- app --- code

|--- Sample --- HelloWorld

| --- etc

| --- Model

| --- Catalog


Configuration of Module



Create module.xml in app/code/Sample/HelloWorld/etc and add the following code in it:



<?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="Sample_HelloWorld" setup_version="1.0.1">
</module>
</config>


Override 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="MagentoCatalogModelProduct" type="SampleHelloWorldModelCatalogProduct" />
</config>


Override Product.php



Now create Product.php in app/code/Sample/HelloWorld/Model/Catalog and add the following code in it.



<?php

namespace SampleHelloWorldModelCatalog;

class Product extends MagentoCatalogModelProduct

{
   public function getName()
   {
       return $this->_getData(self::NAME) . ' + Demo Text';
   }

public function getSku()
   {
       return "123-Demo";
   }
}


Launch SSH and Run Commands



php bin/magento module:enable Magenticians_Moduleproduct
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean
php bin/magento cache:flush



Note : We're using preference to override Above model and blocks,
Where (in some cases, it always depends on customization) we can also use Plugins and Virtual classes using Dependency
Injections which is Highly recommended.







share|improve this answer





























    1














    If you want to override block, controller, model ... files, then you have to create module.
    If you want to change only template file then create theme and put your file in theme.



    How to create custom module
    https://www.magestore.com/magento-2-tutorial/magento-2-modules/



    How to override block, controller, model
    https://webkul.com/blog/overriding-rewriting-classes-magento2/



    How to create custom theme
    https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-create.html



    I hope this will help you.






    share|improve this answer





























      0














      One of the most common tasks for a Magento 2 developer is overriding a template.



      In Magento 2, there are two main methods for overriding a template:



      Theme file path



      Layout Block Argument



      The template path method is used when building a theme and the layout method is used when building a module. They are the simplest, most straightforward, and easiest to understand methods. You will almost always be using one of these two methods. For the very few times, these two methods are not available, you have two other methods to choose from:



      Class preference



      Plugin



      1) Theme File Path



      In Magento 2, themes can override any module’s or parent theme’s layout, template, or web (css, js, etc.) file simply by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file
      For example, If you want to override the template located at <theme_dir>/<Vendor>_<Module>/view/html/header.phtml for the Magento_Theme module, you would place your template in <theme_dir>/Magento_Theme/templates/html/header.phtml.



      There are several block definitions in Magento 2 that do not have the Vendor_Module prefix to specify which module the template belongs to. In these cases, the block’s class attribute will define what module the template belongs to. For example if you were to find a block definition in the Magento_Checkout module like this you would place your template inside the Magento_Checkout module directory inside your theme.



      This Magento 2 devdoc on theme-inheritance goes into more detail on how to override a template in a theme.



      2) Layout Block Argument



      Module Creator



      The layout method should be used when building a module. To override a template using layout XML, you only need to override the block’s template argument. Using the template Magento_Wishlist/view/frontend/templates/view.phtml as an example, to override view.phtml with your own template, you first have to create a new layout file. <Vendor>_<Module>/view/frontend/layout/wishlist_index_index.xml



      wishlist_index_index.xml



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
      <referenceBlock name="customer.wishlist">
      <arguments>
      <argument name="template" xsi:type="string">Vendor_Module::view.phtml</argument>
      </arguments>
      </referenceBlock>
      </body>
      </page>


      Now you have to place your new custom template in the location you specified in your layout file. For this example, that is <Vendor>_<Module>/view/frontend/templates/view.phtml






      share|improve this answer





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "479"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f255777%2fbest-way-to-edit-default-files-apply-custom-application-in-magento-2-3%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0















        For new storefront theme







        1. Create a directory for the theme under app/design/frontend/<your_vendor_name>/<your_theme_name>.


        2. Add a declaration file theme.xml and optionally create etc directory
          and create a file named view.xml to the theme directory.


        3. Add a composer.json file.

        4. Add registration.php.

        5. Create directories for CSS, JavaScript, images, and fonts.

        6. Configure your theme in the Admin panel.


        Create a theme directory
        To create the directory for your theme:




        1. Go to /app/design/frontend.


        2. Create a new directory named according to your vendor name:
          /app/design/frontend/.


        3. Under the directory, create a directory named according to
          your theme.





        app/design/frontend/
        ├── <Vendor>/
        │ │ ├──...<theme>/
        │ │ │ ├── ...
        │ │ │ ├── ...


        Create directories for static files
        Your theme will likely contain several types of static files:




        • Styles

        • Fonts

        • JavaScript

        • Images


        Each type should be stored in a separate sub-directory of web in your theme folder:



        app/design/<area>/<Vendor>/<theme>/
        ├── web/
        │ ├── css/
        │ │ ├── source/
        │ ├── fonts/
        │ ├── images/
        │ ├── js/


        Your theme directory structure now
        At this point your theme file structure looks as follows:



        app/design/frontend/<Vendor>/
        ├── <theme>/
        │ ├── etc/
        │ │ ├── view.xml
        │ ├── web/
        │ │ ├── images
        │ │ │ ├── logo.svg
        │ ├── registration.php
        │ ├── theme.xml
        │ ├── composer.json


        Recommended reading




        • Theme

        • Checklist of modules

        • Static view files processing



        For Block




        Build directories just like above -



        magento2 --- app --- code

        |--- Sample --- HelloWorld

        | --- Block

        | --- etc

        | --- module.xml

        | --- di.xml



        • Create module.xml to define a Magento 2 extension:




        <?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="Sample_HelloWorld" setup_version="0.0.1"/>

        </config>



        • Set preference in di.xml


        Create di.xml to refer the overriding block class:



        <?xml version="1.0"?>

        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

        <preference for="MagentoThemeBlockHtmlTitle" type="SampleHelloWorldBlockHelloTitle" />

        </config>



        • Define an overriding class


        Define HelloTitle.php under magento2/app/code/Sample/HelloWorld/Block:



        <?php

        namespace SampleHelloWorldBlock;

        use MagentoFrameworkViewElementTemplate;

        class HelloTitle extends MagentoThemeBlockHtmlTitle

        {
        public function getPageTitle()
        {
        return 'haha9999';
        }

        protected function _toHtml()
        {
        $this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTitle'));

        return parent::_toHtml();
        }
        }



        For Models




        Create Directories



        magento2 --- app --- code

        |--- Sample --- HelloWorld

        | --- etc

        | --- Model

        | --- Catalog


        Configuration of Module



        Create module.xml in app/code/Sample/HelloWorld/etc and add the following code in it:



        <?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="Sample_HelloWorld" setup_version="1.0.1">
        </module>
        </config>


        Override 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="MagentoCatalogModelProduct" type="SampleHelloWorldModelCatalogProduct" />
        </config>


        Override Product.php



        Now create Product.php in app/code/Sample/HelloWorld/Model/Catalog and add the following code in it.



        <?php

        namespace SampleHelloWorldModelCatalog;

        class Product extends MagentoCatalogModelProduct

        {
           public function getName()
           {
               return $this->_getData(self::NAME) . ' + Demo Text';
           }

        public function getSku()
           {
               return "123-Demo";
           }
        }


        Launch SSH and Run Commands



        php bin/magento module:enable Magenticians_Moduleproduct
        php bin/magento setup:upgrade
        php bin/magento setup:di:compile
        php bin/magento cache:clean
        php bin/magento cache:flush



        Note : We're using preference to override Above model and blocks,
        Where (in some cases, it always depends on customization) we can also use Plugins and Virtual classes using Dependency
        Injections which is Highly recommended.







        share|improve this answer


























          0















          For new storefront theme







          1. Create a directory for the theme under app/design/frontend/<your_vendor_name>/<your_theme_name>.


          2. Add a declaration file theme.xml and optionally create etc directory
            and create a file named view.xml to the theme directory.


          3. Add a composer.json file.

          4. Add registration.php.

          5. Create directories for CSS, JavaScript, images, and fonts.

          6. Configure your theme in the Admin panel.


          Create a theme directory
          To create the directory for your theme:




          1. Go to /app/design/frontend.


          2. Create a new directory named according to your vendor name:
            /app/design/frontend/.


          3. Under the directory, create a directory named according to
            your theme.





          app/design/frontend/
          ├── <Vendor>/
          │ │ ├──...<theme>/
          │ │ │ ├── ...
          │ │ │ ├── ...


          Create directories for static files
          Your theme will likely contain several types of static files:




          • Styles

          • Fonts

          • JavaScript

          • Images


          Each type should be stored in a separate sub-directory of web in your theme folder:



          app/design/<area>/<Vendor>/<theme>/
          ├── web/
          │ ├── css/
          │ │ ├── source/
          │ ├── fonts/
          │ ├── images/
          │ ├── js/


          Your theme directory structure now
          At this point your theme file structure looks as follows:



          app/design/frontend/<Vendor>/
          ├── <theme>/
          │ ├── etc/
          │ │ ├── view.xml
          │ ├── web/
          │ │ ├── images
          │ │ │ ├── logo.svg
          │ ├── registration.php
          │ ├── theme.xml
          │ ├── composer.json


          Recommended reading




          • Theme

          • Checklist of modules

          • Static view files processing



          For Block




          Build directories just like above -



          magento2 --- app --- code

          |--- Sample --- HelloWorld

          | --- Block

          | --- etc

          | --- module.xml

          | --- di.xml



          • Create module.xml to define a Magento 2 extension:




          <?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="Sample_HelloWorld" setup_version="0.0.1"/>

          </config>



          • Set preference in di.xml


          Create di.xml to refer the overriding block class:



          <?xml version="1.0"?>

          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

          <preference for="MagentoThemeBlockHtmlTitle" type="SampleHelloWorldBlockHelloTitle" />

          </config>



          • Define an overriding class


          Define HelloTitle.php under magento2/app/code/Sample/HelloWorld/Block:



          <?php

          namespace SampleHelloWorldBlock;

          use MagentoFrameworkViewElementTemplate;

          class HelloTitle extends MagentoThemeBlockHtmlTitle

          {
          public function getPageTitle()
          {
          return 'haha9999';
          }

          protected function _toHtml()
          {
          $this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTitle'));

          return parent::_toHtml();
          }
          }



          For Models




          Create Directories



          magento2 --- app --- code

          |--- Sample --- HelloWorld

          | --- etc

          | --- Model

          | --- Catalog


          Configuration of Module



          Create module.xml in app/code/Sample/HelloWorld/etc and add the following code in it:



          <?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="Sample_HelloWorld" setup_version="1.0.1">
          </module>
          </config>


          Override 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="MagentoCatalogModelProduct" type="SampleHelloWorldModelCatalogProduct" />
          </config>


          Override Product.php



          Now create Product.php in app/code/Sample/HelloWorld/Model/Catalog and add the following code in it.



          <?php

          namespace SampleHelloWorldModelCatalog;

          class Product extends MagentoCatalogModelProduct

          {
             public function getName()
             {
                 return $this->_getData(self::NAME) . ' + Demo Text';
             }

          public function getSku()
             {
                 return "123-Demo";
             }
          }


          Launch SSH and Run Commands



          php bin/magento module:enable Magenticians_Moduleproduct
          php bin/magento setup:upgrade
          php bin/magento setup:di:compile
          php bin/magento cache:clean
          php bin/magento cache:flush



          Note : We're using preference to override Above model and blocks,
          Where (in some cases, it always depends on customization) we can also use Plugins and Virtual classes using Dependency
          Injections which is Highly recommended.







          share|improve this answer
























            0












            0








            0







            For new storefront theme







            1. Create a directory for the theme under app/design/frontend/<your_vendor_name>/<your_theme_name>.


            2. Add a declaration file theme.xml and optionally create etc directory
              and create a file named view.xml to the theme directory.


            3. Add a composer.json file.

            4. Add registration.php.

            5. Create directories for CSS, JavaScript, images, and fonts.

            6. Configure your theme in the Admin panel.


            Create a theme directory
            To create the directory for your theme:




            1. Go to /app/design/frontend.


            2. Create a new directory named according to your vendor name:
              /app/design/frontend/.


            3. Under the directory, create a directory named according to
              your theme.





            app/design/frontend/
            ├── <Vendor>/
            │ │ ├──...<theme>/
            │ │ │ ├── ...
            │ │ │ ├── ...


            Create directories for static files
            Your theme will likely contain several types of static files:




            • Styles

            • Fonts

            • JavaScript

            • Images


            Each type should be stored in a separate sub-directory of web in your theme folder:



            app/design/<area>/<Vendor>/<theme>/
            ├── web/
            │ ├── css/
            │ │ ├── source/
            │ ├── fonts/
            │ ├── images/
            │ ├── js/


            Your theme directory structure now
            At this point your theme file structure looks as follows:



            app/design/frontend/<Vendor>/
            ├── <theme>/
            │ ├── etc/
            │ │ ├── view.xml
            │ ├── web/
            │ │ ├── images
            │ │ │ ├── logo.svg
            │ ├── registration.php
            │ ├── theme.xml
            │ ├── composer.json


            Recommended reading




            • Theme

            • Checklist of modules

            • Static view files processing



            For Block




            Build directories just like above -



            magento2 --- app --- code

            |--- Sample --- HelloWorld

            | --- Block

            | --- etc

            | --- module.xml

            | --- di.xml



            • Create module.xml to define a Magento 2 extension:




            <?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="Sample_HelloWorld" setup_version="0.0.1"/>

            </config>



            • Set preference in di.xml


            Create di.xml to refer the overriding block class:



            <?xml version="1.0"?>

            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

            <preference for="MagentoThemeBlockHtmlTitle" type="SampleHelloWorldBlockHelloTitle" />

            </config>



            • Define an overriding class


            Define HelloTitle.php under magento2/app/code/Sample/HelloWorld/Block:



            <?php

            namespace SampleHelloWorldBlock;

            use MagentoFrameworkViewElementTemplate;

            class HelloTitle extends MagentoThemeBlockHtmlTitle

            {
            public function getPageTitle()
            {
            return 'haha9999';
            }

            protected function _toHtml()
            {
            $this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTitle'));

            return parent::_toHtml();
            }
            }



            For Models




            Create Directories



            magento2 --- app --- code

            |--- Sample --- HelloWorld

            | --- etc

            | --- Model

            | --- Catalog


            Configuration of Module



            Create module.xml in app/code/Sample/HelloWorld/etc and add the following code in it:



            <?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="Sample_HelloWorld" setup_version="1.0.1">
            </module>
            </config>


            Override 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="MagentoCatalogModelProduct" type="SampleHelloWorldModelCatalogProduct" />
            </config>


            Override Product.php



            Now create Product.php in app/code/Sample/HelloWorld/Model/Catalog and add the following code in it.



            <?php

            namespace SampleHelloWorldModelCatalog;

            class Product extends MagentoCatalogModelProduct

            {
               public function getName()
               {
                   return $this->_getData(self::NAME) . ' + Demo Text';
               }

            public function getSku()
               {
                   return "123-Demo";
               }
            }


            Launch SSH and Run Commands



            php bin/magento module:enable Magenticians_Moduleproduct
            php bin/magento setup:upgrade
            php bin/magento setup:di:compile
            php bin/magento cache:clean
            php bin/magento cache:flush



            Note : We're using preference to override Above model and blocks,
            Where (in some cases, it always depends on customization) we can also use Plugins and Virtual classes using Dependency
            Injections which is Highly recommended.







            share|improve this answer













            For new storefront theme







            1. Create a directory for the theme under app/design/frontend/<your_vendor_name>/<your_theme_name>.


            2. Add a declaration file theme.xml and optionally create etc directory
              and create a file named view.xml to the theme directory.


            3. Add a composer.json file.

            4. Add registration.php.

            5. Create directories for CSS, JavaScript, images, and fonts.

            6. Configure your theme in the Admin panel.


            Create a theme directory
            To create the directory for your theme:




            1. Go to /app/design/frontend.


            2. Create a new directory named according to your vendor name:
              /app/design/frontend/.


            3. Under the directory, create a directory named according to
              your theme.





            app/design/frontend/
            ├── <Vendor>/
            │ │ ├──...<theme>/
            │ │ │ ├── ...
            │ │ │ ├── ...


            Create directories for static files
            Your theme will likely contain several types of static files:




            • Styles

            • Fonts

            • JavaScript

            • Images


            Each type should be stored in a separate sub-directory of web in your theme folder:



            app/design/<area>/<Vendor>/<theme>/
            ├── web/
            │ ├── css/
            │ │ ├── source/
            │ ├── fonts/
            │ ├── images/
            │ ├── js/


            Your theme directory structure now
            At this point your theme file structure looks as follows:



            app/design/frontend/<Vendor>/
            ├── <theme>/
            │ ├── etc/
            │ │ ├── view.xml
            │ ├── web/
            │ │ ├── images
            │ │ │ ├── logo.svg
            │ ├── registration.php
            │ ├── theme.xml
            │ ├── composer.json


            Recommended reading




            • Theme

            • Checklist of modules

            • Static view files processing



            For Block




            Build directories just like above -



            magento2 --- app --- code

            |--- Sample --- HelloWorld

            | --- Block

            | --- etc

            | --- module.xml

            | --- di.xml



            • Create module.xml to define a Magento 2 extension:




            <?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="Sample_HelloWorld" setup_version="0.0.1"/>

            </config>



            • Set preference in di.xml


            Create di.xml to refer the overriding block class:



            <?xml version="1.0"?>

            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

            <preference for="MagentoThemeBlockHtmlTitle" type="SampleHelloWorldBlockHelloTitle" />

            </config>



            • Define an overriding class


            Define HelloTitle.php under magento2/app/code/Sample/HelloWorld/Block:



            <?php

            namespace SampleHelloWorldBlock;

            use MagentoFrameworkViewElementTemplate;

            class HelloTitle extends MagentoThemeBlockHtmlTitle

            {
            public function getPageTitle()
            {
            return 'haha9999';
            }

            protected function _toHtml()
            {
            $this->setModuleName($this->extractModuleName('MagentoThemeBlockHtmlTitle'));

            return parent::_toHtml();
            }
            }



            For Models




            Create Directories



            magento2 --- app --- code

            |--- Sample --- HelloWorld

            | --- etc

            | --- Model

            | --- Catalog


            Configuration of Module



            Create module.xml in app/code/Sample/HelloWorld/etc and add the following code in it:



            <?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="Sample_HelloWorld" setup_version="1.0.1">
            </module>
            </config>


            Override 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="MagentoCatalogModelProduct" type="SampleHelloWorldModelCatalogProduct" />
            </config>


            Override Product.php



            Now create Product.php in app/code/Sample/HelloWorld/Model/Catalog and add the following code in it.



            <?php

            namespace SampleHelloWorldModelCatalog;

            class Product extends MagentoCatalogModelProduct

            {
               public function getName()
               {
                   return $this->_getData(self::NAME) . ' + Demo Text';
               }

            public function getSku()
               {
                   return "123-Demo";
               }
            }


            Launch SSH and Run Commands



            php bin/magento module:enable Magenticians_Moduleproduct
            php bin/magento setup:upgrade
            php bin/magento setup:di:compile
            php bin/magento cache:clean
            php bin/magento cache:flush



            Note : We're using preference to override Above model and blocks,
            Where (in some cases, it always depends on customization) we can also use Plugins and Virtual classes using Dependency
            Injections which is Highly recommended.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            Aditya Shah

            3,5932834




            3,5932834

























                1














                If you want to override block, controller, model ... files, then you have to create module.
                If you want to change only template file then create theme and put your file in theme.



                How to create custom module
                https://www.magestore.com/magento-2-tutorial/magento-2-modules/



                How to override block, controller, model
                https://webkul.com/blog/overriding-rewriting-classes-magento2/



                How to create custom theme
                https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-create.html



                I hope this will help you.






                share|improve this answer


























                  1














                  If you want to override block, controller, model ... files, then you have to create module.
                  If you want to change only template file then create theme and put your file in theme.



                  How to create custom module
                  https://www.magestore.com/magento-2-tutorial/magento-2-modules/



                  How to override block, controller, model
                  https://webkul.com/blog/overriding-rewriting-classes-magento2/



                  How to create custom theme
                  https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-create.html



                  I hope this will help you.






                  share|improve this answer
























                    1












                    1








                    1






                    If you want to override block, controller, model ... files, then you have to create module.
                    If you want to change only template file then create theme and put your file in theme.



                    How to create custom module
                    https://www.magestore.com/magento-2-tutorial/magento-2-modules/



                    How to override block, controller, model
                    https://webkul.com/blog/overriding-rewriting-classes-magento2/



                    How to create custom theme
                    https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-create.html



                    I hope this will help you.






                    share|improve this answer












                    If you want to override block, controller, model ... files, then you have to create module.
                    If you want to change only template file then create theme and put your file in theme.



                    How to create custom module
                    https://www.magestore.com/magento-2-tutorial/magento-2-modules/



                    How to override block, controller, model
                    https://webkul.com/blog/overriding-rewriting-classes-magento2/



                    How to create custom theme
                    https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-create.html



                    I hope this will help you.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 26 '18 at 7:22









                    user55548

                    19718




                    19718























                        0














                        One of the most common tasks for a Magento 2 developer is overriding a template.



                        In Magento 2, there are two main methods for overriding a template:



                        Theme file path



                        Layout Block Argument



                        The template path method is used when building a theme and the layout method is used when building a module. They are the simplest, most straightforward, and easiest to understand methods. You will almost always be using one of these two methods. For the very few times, these two methods are not available, you have two other methods to choose from:



                        Class preference



                        Plugin



                        1) Theme File Path



                        In Magento 2, themes can override any module’s or parent theme’s layout, template, or web (css, js, etc.) file simply by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file
                        For example, If you want to override the template located at <theme_dir>/<Vendor>_<Module>/view/html/header.phtml for the Magento_Theme module, you would place your template in <theme_dir>/Magento_Theme/templates/html/header.phtml.



                        There are several block definitions in Magento 2 that do not have the Vendor_Module prefix to specify which module the template belongs to. In these cases, the block’s class attribute will define what module the template belongs to. For example if you were to find a block definition in the Magento_Checkout module like this you would place your template inside the Magento_Checkout module directory inside your theme.



                        This Magento 2 devdoc on theme-inheritance goes into more detail on how to override a template in a theme.



                        2) Layout Block Argument



                        Module Creator



                        The layout method should be used when building a module. To override a template using layout XML, you only need to override the block’s template argument. Using the template Magento_Wishlist/view/frontend/templates/view.phtml as an example, to override view.phtml with your own template, you first have to create a new layout file. <Vendor>_<Module>/view/frontend/layout/wishlist_index_index.xml



                        wishlist_index_index.xml



                        <?xml version="1.0"?>
                        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                        <body>
                        <referenceBlock name="customer.wishlist">
                        <arguments>
                        <argument name="template" xsi:type="string">Vendor_Module::view.phtml</argument>
                        </arguments>
                        </referenceBlock>
                        </body>
                        </page>


                        Now you have to place your new custom template in the location you specified in your layout file. For this example, that is <Vendor>_<Module>/view/frontend/templates/view.phtml






                        share|improve this answer


























                          0














                          One of the most common tasks for a Magento 2 developer is overriding a template.



                          In Magento 2, there are two main methods for overriding a template:



                          Theme file path



                          Layout Block Argument



                          The template path method is used when building a theme and the layout method is used when building a module. They are the simplest, most straightforward, and easiest to understand methods. You will almost always be using one of these two methods. For the very few times, these two methods are not available, you have two other methods to choose from:



                          Class preference



                          Plugin



                          1) Theme File Path



                          In Magento 2, themes can override any module’s or parent theme’s layout, template, or web (css, js, etc.) file simply by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file
                          For example, If you want to override the template located at <theme_dir>/<Vendor>_<Module>/view/html/header.phtml for the Magento_Theme module, you would place your template in <theme_dir>/Magento_Theme/templates/html/header.phtml.



                          There are several block definitions in Magento 2 that do not have the Vendor_Module prefix to specify which module the template belongs to. In these cases, the block’s class attribute will define what module the template belongs to. For example if you were to find a block definition in the Magento_Checkout module like this you would place your template inside the Magento_Checkout module directory inside your theme.



                          This Magento 2 devdoc on theme-inheritance goes into more detail on how to override a template in a theme.



                          2) Layout Block Argument



                          Module Creator



                          The layout method should be used when building a module. To override a template using layout XML, you only need to override the block’s template argument. Using the template Magento_Wishlist/view/frontend/templates/view.phtml as an example, to override view.phtml with your own template, you first have to create a new layout file. <Vendor>_<Module>/view/frontend/layout/wishlist_index_index.xml



                          wishlist_index_index.xml



                          <?xml version="1.0"?>
                          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                          <body>
                          <referenceBlock name="customer.wishlist">
                          <arguments>
                          <argument name="template" xsi:type="string">Vendor_Module::view.phtml</argument>
                          </arguments>
                          </referenceBlock>
                          </body>
                          </page>


                          Now you have to place your new custom template in the location you specified in your layout file. For this example, that is <Vendor>_<Module>/view/frontend/templates/view.phtml






                          share|improve this answer
























                            0












                            0








                            0






                            One of the most common tasks for a Magento 2 developer is overriding a template.



                            In Magento 2, there are two main methods for overriding a template:



                            Theme file path



                            Layout Block Argument



                            The template path method is used when building a theme and the layout method is used when building a module. They are the simplest, most straightforward, and easiest to understand methods. You will almost always be using one of these two methods. For the very few times, these two methods are not available, you have two other methods to choose from:



                            Class preference



                            Plugin



                            1) Theme File Path



                            In Magento 2, themes can override any module’s or parent theme’s layout, template, or web (css, js, etc.) file simply by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file
                            For example, If you want to override the template located at <theme_dir>/<Vendor>_<Module>/view/html/header.phtml for the Magento_Theme module, you would place your template in <theme_dir>/Magento_Theme/templates/html/header.phtml.



                            There are several block definitions in Magento 2 that do not have the Vendor_Module prefix to specify which module the template belongs to. In these cases, the block’s class attribute will define what module the template belongs to. For example if you were to find a block definition in the Magento_Checkout module like this you would place your template inside the Magento_Checkout module directory inside your theme.



                            This Magento 2 devdoc on theme-inheritance goes into more detail on how to override a template in a theme.



                            2) Layout Block Argument



                            Module Creator



                            The layout method should be used when building a module. To override a template using layout XML, you only need to override the block’s template argument. Using the template Magento_Wishlist/view/frontend/templates/view.phtml as an example, to override view.phtml with your own template, you first have to create a new layout file. <Vendor>_<Module>/view/frontend/layout/wishlist_index_index.xml



                            wishlist_index_index.xml



                            <?xml version="1.0"?>
                            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                            <body>
                            <referenceBlock name="customer.wishlist">
                            <arguments>
                            <argument name="template" xsi:type="string">Vendor_Module::view.phtml</argument>
                            </arguments>
                            </referenceBlock>
                            </body>
                            </page>


                            Now you have to place your new custom template in the location you specified in your layout file. For this example, that is <Vendor>_<Module>/view/frontend/templates/view.phtml






                            share|improve this answer












                            One of the most common tasks for a Magento 2 developer is overriding a template.



                            In Magento 2, there are two main methods for overriding a template:



                            Theme file path



                            Layout Block Argument



                            The template path method is used when building a theme and the layout method is used when building a module. They are the simplest, most straightforward, and easiest to understand methods. You will almost always be using one of these two methods. For the very few times, these two methods are not available, you have two other methods to choose from:



                            Class preference



                            Plugin



                            1) Theme File Path



                            In Magento 2, themes can override any module’s or parent theme’s layout, template, or web (css, js, etc.) file simply by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file
                            For example, If you want to override the template located at <theme_dir>/<Vendor>_<Module>/view/html/header.phtml for the Magento_Theme module, you would place your template in <theme_dir>/Magento_Theme/templates/html/header.phtml.



                            There are several block definitions in Magento 2 that do not have the Vendor_Module prefix to specify which module the template belongs to. In these cases, the block’s class attribute will define what module the template belongs to. For example if you were to find a block definition in the Magento_Checkout module like this you would place your template inside the Magento_Checkout module directory inside your theme.



                            This Magento 2 devdoc on theme-inheritance goes into more detail on how to override a template in a theme.



                            2) Layout Block Argument



                            Module Creator



                            The layout method should be used when building a module. To override a template using layout XML, you only need to override the block’s template argument. Using the template Magento_Wishlist/view/frontend/templates/view.phtml as an example, to override view.phtml with your own template, you first have to create a new layout file. <Vendor>_<Module>/view/frontend/layout/wishlist_index_index.xml



                            wishlist_index_index.xml



                            <?xml version="1.0"?>
                            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                            <body>
                            <referenceBlock name="customer.wishlist">
                            <arguments>
                            <argument name="template" xsi:type="string">Vendor_Module::view.phtml</argument>
                            </arguments>
                            </referenceBlock>
                            </body>
                            </page>


                            Now you have to place your new custom template in the location you specified in your layout file. For this example, that is <Vendor>_<Module>/view/frontend/templates/view.phtml







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered yesterday









                            Sourav

                            1,109413




                            1,109413






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Magento Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f255777%2fbest-way-to-edit-default-files-apply-custom-application-in-magento-2-3%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                1300-talet

                                1300-talet

                                Display a custom attribute below product name in the front-end Magento 1.9.3.8