Writing a Magento Extension

Magento Extensions Development Tips and Tricks

  • Allowing permissions for a customized Magento extension

    Posted on October 13, 2012 by Nimrod Techn

    Assuming we have developed the following extension to Magento admin panel:

    app/code/local/Engineering/Custommodule/

    And we can actually use it in the admin panel, but when we would like to set the permissions - we go to System -> Permissions -> Users, and try to give the right permissions to our users.

    However, it doesn't seem to work, and the non-administrator users will not be able to view the extension (lack of permissions).

     

    To solve this, we would create a new adminhtml.xml file in app/code/local/Engineering/Custommodule/etc/

     

    Inside the file, we will have the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
    	<menu>
    		<cms> //change to whatever tab you want
    			<children>
    				<custommodule translate="title" module="custommodule">
    					<title>Custom Module</title>
    					<action>custommodule/adminhtml_custommodule</action>
    				</custommodule>
    			</children>
    		</cms>
    	</menu>
    	<acl>
    		<resources>
    			<admin>
    				<children>
    					<cms>
    						<children>
    							<custommodule translate="title">
    								<title>Custom Module</title>
    								<sort_order>0</sort_order>
    							</custommodule>
    						</children>
    					</cms>
    				</children>
    			</admin>
    		</resources>
    	</acl>
    </config>

    This post was posted in Writing a Magento Extension

  • Overriding a core model in Magento

    Posted on October 12, 2012 by Nimrod Techn

    Overriding a core model in Magento can be done by creating a Magento extension:

    Let's say we would like to override app/code/core/Mage/Newsletter/Model/Subscriber.php

    1. Create the company directory in local (app/code/local/Engineering).

    2. Create the extension directory inside (app/code/local/Engineering/Newsletter)

    3. Create model & etc directories inside (app/code/local/Engineering/Newsletter/model & app/code/local/Engineering/Newsletter/etc).

    model - what we would like to rewrite

    etc - the necessary configuration to tell Magento we're overriding a core model

    4. Copy the model there (Subscriber.php).

    5. Change the copied-model's class name to the following:  class Engineering_Newsletter_Model_Subscriber extends Mage_Newsletter_Model_Subscriber

    6. Create a config.xml file in app/code/local/Engineering/Newsletter/etc

    7. Place the following inside the config.xml:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Engineering_Newsletter>
                <version>0.1.0</version>
            </Engineering_Newsletter>
        </modules>
        <frontend>
            <routers>
                <newsletter>
                    <args>
                        <modules>
                          <Engineering_Newsletter before="Mage_Newsletter">
                             Engineering_Newsletter
                          </Engineering_Newsletter>
                       </modules>
                    </args>
                </newsletter>
            </routers>
        </frontend>
        <global>
            <models>
                <newsletter>
                    <rewrite>
                        <subscriber>Engineering_Newsletter_Model_Subscriber</subscriber>
                    </rewrite>
                </newsletter>
            </models>
       </global>
    </config>

    * Bear in mind: the xml file is case-sensitive, and you'd better stick to the conventions (capitals wherever needed) - that's where alot of beginners waste hours of debugging, trying to understand where their mistake is.


    This post was posted in Writing a Magento Extension

  • Overriding Magento core

    Posted on October 12, 2012 by Nimrod Techn

    Repeat after me. we never, ever, ever, ever - change Magento's core files (app/code/core).

    Why? lots of reasons. the most important one is, we would like to upgrade our Magento system at some point.

    The best of practices would be to create a directory in app/code/local named Mage (app/code/local/Mage).

    Now copy the core file to the exact same directory hierarchy (create the same hierarchy), on local.

     

    Which means, if the file we would like to copy is at app/code/core/Mage/catalog/controllers/IndexController.php, we would copy it to app/code/local/Mage/catalog/controllers/IndexController.php.

    Blocks, controllers, helpers - can be copied like this without a problem.

    Models, however, require you to develop a Magento extension with slight modifications.

     

     


    This post was posted in Writing a Magento Extension

Items 4 to 6 of 8 total

Page:
  1. 1
  2. 2
  3. 3
Magento is a well-engineered eCommerce platform designed to help engineers develop customized eCommerce online stores. Due to lack of proper coding documentation, Engineer-ing.com was created with the sole purpose of instructing Magento developers to-be with the "how-to-do" know-how. In the event of unresolved issues, you are more than welcome to contact me for consultation. However, please do so only if you possess a Software Engineering background and you're able to specify your question.