how to develop a basic magento extension tutorial

27
Tutorial: How to Develop A Basic Magento Extension How to create your own blocks and templates in Magento Commerce using Extensions. Hendy Irawan @hendyirawan - magentoadmin.blogspot.com CTO, Bippo

Upload: hendy-irawan

Post on 22-Nov-2014

30.538 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: How to Develop a Basic Magento Extension Tutorial

Tutorial: How to DevelopA Basic Magento Extension

How to create your own blocks and templates in Magento Commerce using Extensions.

Hendy Irawan@hendyirawan ­ magentoadmin.blogspot.comCTO, Bippo

Page 4: How to Develop a Basic Magento Extension Tutorial

Filename Mapping Conventions

code/{Company}/{Module}-> app/code/community/{Company}/{Module}

design/frontend/base/default/...-> app/design/frontend/base/default/...

skin/frontend/base/default/...-> skin/frontend/base/default/...

{Company}_{Module}.xml-> app/etc/modules/{Company}_{Module}.xml

Page 6: How to Develop a Basic Magento Extension Tutorial

Module etc/config.xml (Basic)

<?xml version="1.0" encoding="UTF-8"?><config> <modules> <Bippo_Twitter> <version>1.0.0</version> </Bippo_Twitter> </modules></config>

code/Bippo/Twitter/etc/config.xml

Page 7: How to Develop a Basic Magento Extension Tutorial

Block & Helper config.xml

<config>... <global> <models/> <blocks> <bippotwitter> <class>Bippo_Twitter_Block</class> </bippotwitter> </blocks> <helpers> <bippotwitter> <class>Bippo_Twitter_Helper</class> </bippotwitter> </helpers> </global></config>

code/Bippo/Twitter/etc/config.xml

Page 8: How to Develop a Basic Magento Extension Tutorial

Helper class

<?php

class Bippo_Twitter_Helper_Data extends Mage_Core_Helper_Abstract{ }

code/Bippo/Twitter/Helper/Data.php

Page 9: How to Develop a Basic Magento Extension Tutorial

Block Class Skeleton

<?php/** * Twitter Profile Stream. * * @category Bippo * @package Bippo_Twitter * @author Rully Lukman <[email protected]> */class Bippo_Twitter_Block_Profilestream extends Mage_Core_Block_Template{}

code/Bippo/Twitter/Block/Profilestream.php

Page 10: How to Develop a Basic Magento Extension Tutorial

Block Class Implementation

class Bippo_Twitter_Block_Profilestream extends Mage_Core_Block_Template {

public function __construct() { parent::__construct(); // template $this->setTemplate('bippotwitter/twitter-box.phtml');}

}

code/Bippo/Twitter/Block/Profilestream.php

Page 11: How to Develop a Basic Magento Extension Tutorial

Template File

<div class="twitterbox"><script src="http://widgets.twimg.com/j/2/widget.js"></script><script>new TWTR.Widget({ version: 2, type: 'profile',... }}).render().setUser('bippoindonesia').start();</script></div>

design/frontend/base/default/ template/bippotwitter/twitter-box.phtml

Page 12: How to Develop a Basic Magento Extension Tutorial

How to Use

Usage in CMS Content Editor{{block type="bippotwitter/profilestream"}}

Usage in CMS Design tab / Layout XML<reference name="content"> <block type="bippotwitter/profilestream" name="twitterbox1"/></reference>

Page 14: How to Develop a Basic Magento Extension Tutorial

Adding Properties

private $twitterUsername;

public function __construct() { parent::__construct(); // property default values $this->twitterUsername = 'bippoindonesia'; // template $this->setTemplate('bippotwitter/twitter-box.phtml');}

public function getTwitterUsername() { return $this->twitterUsername;}

public function setTwitterUsername($twitterUsername) { $this->twitterUsername = $twitterUsername;}

code/Bippo/Twitter/Block/Profilestream.php

Page 15: How to Develop a Basic Magento Extension Tutorial

Using Properties

<div class="twitterbox"><script src="http://widgets.twimg.com/j/2/widget.js"></script><script>new TWTR.Widget({ version: 2, type: 'profile',... }}).render() .setUser('<?php echo $this->getTwitterUsername() ?>') .start();</script></div>

design/frontend/base/default/ template/bippotwitter/twitter-box.phtml

Page 16: How to Develop a Basic Magento Extension Tutorial

Usage in CMS Content

{{block type="bippotwitter/profilestream" twitterUsername="hendyirawan"}}

Page 17: How to Develop a Basic Magento Extension Tutorial

Usage in CMS Design tab / Layout XML

<reference name="content"> <block type="bippotwitter/profilestream" name="twitterbox2"> <action method="setTwitterUsername"> <twitterUsername> soluvas </twitterUsername> </action> </block></reference>

Page 20: How to Develop a Basic Magento Extension Tutorial

Adminhtml Input Fields<?xml version="1.0"?><!--/** * Bippo Twitter * * @category Bippo * @package Bippo_Twitter * @copyright Copyright (c) 2011 Bippo.co.id */--><config> <tabs> <bippo> <label>Bippo</label> <sort_order>196</sort_order> </bippo> </tabs>...

code/Bippo/Twitter/etc/system.xml

Page 21: How to Develop a Basic Magento Extension Tutorial

Tabs in Configuration Page<?xml version="1.0"?><!--/** * Bippo Twitter * * @category Bippo * @package Bippo_Twitter * @copyright Copyright (c) 2011 Bippo.co.id */--><config> <tabs> <bippo> <label>Bippo</label> <sort_order>196</sort_order> </bippo> </tabs>...

code/Bippo/Twitter/etc/system.xml

Page 22: How to Develop a Basic Magento Extension Tutorial

Sections

<config> ... <sections> <bippotwitter translate="title" module="bippotwitter"> <label>Twitter</label> <tab>bippo</tab> <frontend_type>text</frontend_type> <sort_order>73</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <groups> ...

code/Bippo/Twitter/etc/system.xml

Page 23: How to Develop a Basic Magento Extension Tutorial

Groups

<config>... <sections> <bippotwitter translate="title" module="bippotwitter"> ... <groups> <general translate="label"> <label>General</label> <sort_order>100</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> ...

code/Bippo/Twitter/etc/system.xml

Page 24: How to Develop a Basic Magento Extension Tutorial

Fields

<config> ... <sections> <bippotwitter ...> ... <groups> <general ...> ... <fields> <custom_twitter_id translate="label"> <label>Twitter ID</label> <comment><![CDATA[Twitter username]]></comment> <frontend_type>text</frontend_type> <sort_order>20</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </custom_twitter_id> <number_of_tweets translate="label"> ...

code/Bippo/Twitter/etc/system.xml

Page 25: How to Develop a Basic Magento Extension Tutorial

Access Control<?xml version="1.0"?><config><acl> <resources> <admin> <children> <system> <children> <config> <children> <bippotwitter translate="title" module="bippotwitter"> <title>Twitter</title> </bippotwitter> </children> </config> </children> </system> </children> </admin> </resources></acl></config>

code/Bippo/Twitter/etc/adminhtml.xml

Page 26: How to Develop a Basic Magento Extension Tutorial

Default Configuration Values

<config>... <default> <bippotwitter> <general> <custom_twitter_id>bippoindonesia</custom_twitter_id> <number_of_tweets>5</number_of_tweets> <live>1</live> </general> </bippotwitter> </default>...</config>

code/Bippo/Twitter/etc/config.xml

Page 27: How to Develop a Basic Magento Extension Tutorial

Need More Resources?

Magento eCommerce Development Blogmagentoadmin.blogspot.com

Follow @hendyirawan on Twitter

Follow ceefour on Slidesharewww.slideshare.net/ceefour

Hendy Irawan