Wie programmiere Ich ein Modul? Erste Schritte.

2,605 views

Published on

Eine Einführung in die Modulentwicklung mit Magento.

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,605
On SlideShare
0
From Embeds
0
Number of Embeds
994
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Wie programmiere Ich ein Modul? Erste Schritte.

  1. 1. Wie programmiere ich ein Magento-Modul? Erste Schritte. David Fuhr, Flagbit GmbH & Co. KG Leipzig, 05.11.2010
  2. 2. Agenda •  Darstellung: Blocks, Templates und Layout XML •  Internationalisierung / Lokalisierung •  Datenhaltung: Models und Resource-Models •  Konfiguration: Widgets
  3. 3. Verzeichnisse •  app/code/<codepool>/<namespace>/ <modulname> – z.B app/code/community/Flagbit/FeedReader •  app/etc/modules – Zentrale Stelle um Module zu registrieren
  4. 4. app/etc/modules/ Flagbit_FeedReader.xml <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Flagbit_FeedReader> <active>true</active> <codePool>community</codePool> </Flagbit_FeedReader> </modules> </config>
  5. 5. app/code/community/Flagbit/ FeedReader/etc/config.xml <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Flagbit_FeedReader> <version>0.0.1</version> </Flagbit_FeedReader> </modules> </config>
  6. 6. Was bisher geschah...
  7. 7. Blocks...
  8. 8. .../Flagbit/FeedReader/etc/ config.xml <?xml version="1.0" encoding="UTF-8"?> <config> <!-- ... --> <global> <blocks> <flagbit_feedreader> <class>Flagbit_FeedReader_Block</class> </flagbit_feedreader> </blocks> </global> </config>
  9. 9. .../Flagbit/FeedReader/Block/ View.php <?php /** * php doc here */ class Flagbit_FeedReader_Block_View extends Mage_Core_Block_Template { public function getFeed() { /* ... */ } }
  10. 10. Was bisher geschah...
  11. 11. ... und Layout XML •  Erstellen •  Einfügen •  Entfernen •  Verschieben von Blöcken im Layout
  12. 12. .../Flagbit/FeedReader/etc/ config.xml <?xml version="1.0" encoding="UTF-8"?> <config> <!-- ... --> <frontend> <layout> <updates> <flagbit_feedreader> <file>flagbit_feedreader.xml</file> </flagbit_feedreader> </updates> </layout> </frontend> </config>
  13. 13. .../design/frontend/base/default/ layout/flagbit_feedreader.xml <?xml version="1.0" encoding="UTF-8"?> <layout version="0.1.0"> <default> <reference name=“right"> <block type="flagbit_feedreader/view" name=“right.flagbit_feedreader.rightcol" template="flagbit_feedreader/right_col.phtml“ /> </reference> </default> </layout>
  14. 14. .../base/default/template/ flagbit_feedreader/right_col.phtml <?php /* @var $this Flagbit_FeedReader_Block_View */ ?> <div class="block"> <div class="block-title“><strong><span> <?php echo $this->escapeHtml($this->__(‘News from out Feed')); ?> </span></strong></div> <div class="block-content"> <p><?php echo $this->escapeHtml($this->__(‘Hm... what Feed?')); ?></p> </div> </div> <?php endif; ?>
  15. 15. Was bisher geschah...
  16. 16. Awsum!
  17. 17. .../design/frontend/base/default/ layout/flagbit_feedreader.xml <?xml version="1.0" encoding="UTF-8"?> <layout version="0.1.0"> <default> <reference name=“right"> <block type="flagbit_feedreader/view" name=“right.flagbit_feedreader.rightcol" template="flagbit_feedreader/right_col.phtml“ /> </reference> </default> </layout>
  18. 18. Mehr mit Layout XML •  Layout Handles (Beispiele) – catalog_product_view – checkout_cart_index – customer_account – customer_logged_in – PRODUCT_TYPE_configurable – ...
  19. 19. i18n / l10n •  Internationalisation – Schaffen der Vorraussetzungen für die... •  Localisation – Die Umsetzung für eine Ziel-Locale
  20. 20. .../base/default/template/ flagbit_feedreader/right_col.phtml <?php /* @var $this Flagbit_FeedReader_Block_View */ ?> <div class="block"> <div class="block-title“><strong><span> <?php echo $this->escapeHtml($this->__(‘News from out Feed')); ?> </span></strong></div> <div class="block-content"> <p><?php echo $this->escapeHtml($this->__(‘Hm... what Feed?')); ?></p> </div> </div> <?php endif; ?>
  21. 21. .../Flagbit/FeedReader/etc/ config.xml (schon wieder) <?xml version="1.0" encoding="UTF-8"?> <config> <!-- ... --> <frontend> <!-- ... --> <translate> <modules> <Flagbit_FeedReader> <files> <default>Flagbit_FeedReader.csv</default> </files> </Flagbit_FeedReader> </modules> </translate> </frontend> </config>
  22. 22. app/locale/de_DE/ Flagbit_FeedReader.csv "News from our Feed","Letzte Neuigkeiten" "Hm... what Feed?","Hm... welche Neuigkeiten?"
  23. 23. Was bisher geschah...
  24. 24. Awsum!
  25. 25. Models... •  Datenhaltung /-speicherung •  Enthalten Berechnungen, interne Logik, Geschäftslogik, etc. •  z.B. Mage_Catalog_Model_Product, Mage_Sales_Model_Order
  26. 26. .../Flagbit/Faq/etc/config.xml (wieder mal) <?xml version="1.0" encoding="UTF-8"?> <config> <!-- ... --> <global> <!-- ... --> <models> <flagbit_feedreader> <class>Flagbit_FeedReader_Model</class> </flagbit_feedreader> </models> </global> <!-- ... --> </config>
  27. 27. .../Flagbit/FeedReader/Model/ Feed.php <?php class Flagbit_FeedReader_Model_Feed extends Mage_Core_Model_Abstract { public function getFeed() { return Zend_Feed::import($this->getUri()); } }
  28. 28. Was bisher geschah...
  29. 29. Ein bisschen Demo-Voodoo... •  Block/View.php public function getTitle() { return Mage::getModel('flagbit_feedreader/feed') ->setUri('http://feeds.feedburner.com/MageBlog') ->title(); } •  template/flagbit_feedreader/right_col.phtml <?php echo $this->escapeHtml($this->__('News from ') . $this->getTitle()); ?>
  30. 30. Awsum!
  31. 31. Resource-Models... •  Persistenz-Schicht zwischen Models und Datenbank •  DBMS-spezifisch (Oracle und MSSQL-Support sind geplant): Enthalten SQL
  32. 32. Widgets
  33. 33. .../Flagbit/FeedReader/etc/ widget.xml <?xml version="1.0" encoding="UTF-8"?> <widgets> <flagbit_feedreader_sidebar type="flagbit_feedreader/view" translate="name description"> <name>FeedReader: Sidebar</name> <description type="desc">Adds a FeedReader block</description> <parameters> <uri translate="label"> <required>1</required> <visible>1</visible> <label>Feed URI</label> <type>text</type> </uri> </parameters> </flagbit_feedreader_sidebar> </widgets>
  34. 34. Insert Widget...
  35. 35. Was bisher geschah...
  36. 36. Awsum! https://github.com/Flagbit/Magento-FeedReader http://www.mageblog.de/ http://www.flagbit.de/ Fragen?

×