Blog

  •  

    Magento Best Practices

    Website Development through magento web development agency is important to have assertive and thematically elevated design. Magento extension and perceptive means to make determination provided as a salient backup to develop site earnings as predicted. If use of extensions comes in the category of modular, flexible and extensible choice in development of websites.

    Get instances of Magento’s complete code and use it to have perceptual programming practice with connections to code in development. Use of modules has one observer class ascertained and is properly executed through certainty in development and promotion. Observing through catalog_product_load_after, and use methods like catalogProductLoadAfter().

    <?php

    class Namespace_Module_Model_Observer {

                public function catalogProductLoadAfter(Varien_Event_Observer $observer) {

                            // catalog_product_load_after

                }

                public function cmsBlockSaveBefore(Varien_Event_Observer $observer) {

                            // cms_block_save_before

                }

    }

    Observer configurations are associated to different observer types:

    The observer types involved include; object, model, singleton and disabled. With specification of a new model, the respective class is involved in:

    The use of newer abstract models new class instantiations include add up with up.

    <global>

        <events>

            <catalog_product_load_after>

                <observers>

                    <namespace_modulename>

                        <type>singleton</type> <!-- use singleton instead of model -->

                        <class>namespace_modulename/observer</class>

                        <method>catalogProductLoadAfter</method>

                    </namespace_modulename>

                </observers>

            </catalog_product_load_after>

        </events>

    </global>

     

    Practices for Programming Magento E-Commerce Stores

    Model nodes have two different abstractions applied. One relates to concrete class and the other is a factory method to rewrite class methods and names. If you use a concrete class name, others will need to rewrite class names:

    <?xml version="1.0"?>

    <config>

        <global>

            <events>

                <catalog_product_load_after>

                    <observers>

                        <namespace_modulename>

                            <type>singleton</type>

                            <!-- NOT Namespace_Module_Model_Observer! -->

                            <class>namespace_module/observer</class>

                            <method>catalogProductLoadAfter</method>

                        </namespace_modulename>

                    </observers>

                </catalog_product_load_after>

            </events>

        </global>

    </config>

    Resolve Conflicts through Dependency

    No two modules rewrite same classes. The last one is always a successor.  Meaning of “in” is that the last one to have their configuration loaded is one you can rewrite as a class. All previous entries overwritten implement in coding.  This has knowledge as rewrite conflict to access in different situation.

    <?xml version="1.0" encoding="UTF-8" ?>

    <config>

        <modules>

            <Namespace_Module1>

                <active>true</active>

                <codePool>local</codePool>

                <depends>

                    <Namespace_Module2 />

                </depends>

            </Namespace_Module1>

        </modules>

    </config>

    Specify the code for rewritten modular:

    <?xml version="1.0"?>

    <config>

        <global>

            <models>

                <catalog>

                    <rewrite>

                        <product>Namespace_Module2_Model_Catalog_Product</product>

                    </rewrite>

                </catalog>

            </models>

        </global>

    </config>

    Programming Best Practices

    Declare Layout Updates

    Plenty of times, your customizations are in models (“M” of MVC) and views (“V” of MVC) throughout Magento. This means you have to create template and layout files. If modules require any sort of manipulation of view layer, declare a layout update in the module’s configuration file.

    <config>

        <frontend>

            <layout>

                <updates>

                    <namespace_module>

                        <file>namspace/module.xml</file>

                    </namespace_module>

                </updates>

            </layout>

        </frontend>

    </config>

    Uninstall Database Changes

    This one is tough one. With truthfulness, hardly anyone does this. If you go to create a sort of database modification, such as creating an attribute, table, adding or creating system configurations, you need to provide a method to rid yourself of these in case someone decides never to implement a module.

    Now before you go looking at the situation with odd thoughts and mention, “Magento does not provide a way to uninstall alterations” or the like, you will think to quit your whining. If you are experienced. You should not use the store at stake by needing modules enabled in order to operate. It is messy coding and you can make a better choice.

    <?php

     include_once 'abstract.php';

     class Namespace_Module_Uninstall extends Mage_Shell_Abstract {

         public function run() {

            $this->removeDirectories();

            $this->removeAttributes();

        }

         /**

         * Remove file system files here.

         */

        public function removeDirectories() {

            $file = new Varien_Io_File();

             $file->rmdir(BP . DS . 'app/code/local/My/', true);

            $file->rm(BP . DS . 'app/etc/modules/My_Module.xml');

        }

         /**

         * Remove any attributes here

         */

        public function removeAttributes() {

            $installer = $this->_getSetup();

             $installer->startSetup();

             // repeat this for any other attributes you wish to uninstall

            $installer->removeAttribute('catalog_product', 'your_attribute');

             $installer->endSetup();

        }

         /**

         * Return catalog/customer/core or whichever resource setup class you need

         *

         * @return Mage_Catalog_Model_Resource_Setup

         */

        protected function _getSetup() {

            return Mage::getResourceSingleton('catalog/setup', 'default_setup');

        }

    }

    $uninstall = new Namespace_Module_Uninstall();

     

    $uninstall->run();

Comments

  • (no comments)

This free website is created and hosted by Website.com's Site Builder.