Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)

Roman Zenner
Roman ZennerIndustry Analyst & Content Writer bei commercetools GmbH um commercetools GmbH
How	
  to	
  write	
  Custom	
  
Modules	
  for	
  PHP-­based	
  E-­
Commerce	
  Systems	
  
Roman	
  Z.	
  
Roman	
  Zenner	
  
•  Working	
  as	
  freelance	
  trainer,	
  author	
  and	
  
consultant	
  since	
  2004	
  
•  Has	
  written	
  three	
  books	
  on	
  Magento	
  and	
  
OXID	
  eShop	
  
•  Is	
  in	
  the	
  process	
  of	
  writing	
  a	
  “cookbook”	
  
on	
  OXID	
  eShop	
  with	
  Joscha	
  Krug	
  
•  Publishes	
  in	
  various	
  magazines	
  
Initial	
  thoughts	
  
•  Modularity	
  a	
  no-­‐brainer	
  in	
  today’s	
  
ecommerce	
  software	
  
•  There	
  must	
  be	
  a	
  way	
  of	
  extending	
  classes	
  
or	
  an	
  event-­‐listener	
  system	
  in	
  order	
  to	
  
integrate	
  custom	
  functionalities	
  
Types	
  of	
  modules	
  
•  Encapsulate	
  graphical	
  (template)	
  
changes	
  
•  Provide	
  additional	
  information	
  (e.g.	
  for	
  
an	
  article	
  
•  Special	
  calculations	
  
•  Payment	
  and	
  shipping	
  
•  Other	
  interfaces	
  (ImpEx,	
  etc.)	
  
Today‘s	
  candidates	
  
•  Magento	
  
•  OXID	
  eShop	
  
•  Shopware	
  
http://www.flickr.com/photos/exey/3815327201
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Brief	
  History	
  
•  First	
  stable	
  version	
  released	
  in	
  spring	
  2008	
  
•  Community	
  Edition	
  under	
  OSL	
  
•  Professional	
  and	
  Enterprise	
  Editions	
  
•  Based	
  on	
  Zend	
  Framework	
  and	
  MySQL	
  
•  Relies	
  heavily	
  on	
  EAV	
  structure	
  
•  XML	
  de^initions	
  
•  Bought	
  by	
  eBay	
  in	
  2011	
  (X.commerce)	
  
•  Current	
  stable	
  version:	
  1.7.0.2	
  
Structure	
  
Templates	
  (1)	
  
Templates	
  (2)	
  
Templates	
  (2)	
  
<block type="page/html“ name="root" output="toHtml“ template="page/3columns.phtml">
<block type="page/html_header" name="header" as="header">
<block type="page/switch" name="store_language" as="store_language"
template="page/switch/languages.phtml"/></block>
</block>
Template: /layout/page.xml
<?php if(count($this->getStores())>1): ?>
<div class="form-language“>
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId())
? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>>
<?php endforeach; ?>
</div>
<?php endif; ?>
Template: /template/page/switch/languages.phtml
Drilling	
  down	
  (1)	
  
Example:
How to get from the article name in
the template to the database field?
Drilling	
  down	
  (2)	
  
1.  Block: <block type="catalog/product_view" name="product.info" template="catalog/
product/view.phtml">
2.  Template: /app/design/frontend/base/default/template/catalog/product/view.phtml
3.  Block class: Mage_Catalog_Block_Product_View
4.  Model: Mage_Catalog_Model_Product:
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId()) {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
return Mage::registry('product');
}
Drilling	
  down	
  (3)	
  
1.  Abstract class: Mage_Core_Model_Abstract
2.  Resource model: Mage_Core_Model_Mysql4_Abstract
public function load($id, $field=null)
{
$this->_beforeLoad($id, $field);
$this->_getResource()->load($this, $id, $field);
$this->_afterLoad();
$this->setOrigData();
$this->_hasDataChanges = false;
return $this;
}
Modules	
  
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Brief	
  History	
  
•  OS-­‐Edition	
  since	
  late	
  2008.	
  
•  Based	
  on	
  own	
  PHP-­‐Framework	
  &	
  MySQL	
  
•  Recent	
  version:	
  4.7.3	
  
Features	
  
•  ADODB	
  database	
  abstraction	
  layer	
  
•  Uses	
  Smarty	
  2	
  (but	
  Template	
  Inheritance	
  by	
  
Smarty	
  3)	
  
•  Block	
  Inheritance	
  
•  Autoloader	
  
Structure	
  
Template	
  Inheritance	
  (1)	
  
Template	
  Inheritance	
  (2)	
  
[{capture append="oxidBlock_content"}]
[{assign var="oFirstArticle" value=$oView->getFirstArticle()}]
[{/capture}]
[{include file="layout/page.tpl" sidebar="Right"}]
/out/azure/tpl/page/shop/start.tpl
Template	
  Inheritance	
  (3)	
  
<div id="content">
[{include file="message/errors.tpl"}]
[{foreach from=$oxidBlock_content item="_block"}]
[{$_block}]
[{/foreach}]
</div>
[{include file="layout/footer.tpl"}]
/out/azure/tpl/layout/page.tpl
Drilling	
  down	
  (1)	
  
Example:	
  	
  
How	
  to	
  get	
  from	
  the	
  article	
  name	
  in	
  
the	
  Smarty-­‐Template	
  to	
  the	
  database	
  ^ield?	
  
Drilling	
  down	
  (2)	
  
•  Article	
  detail	
  page:	
  /out/azure/tpl/page/details/inc/productmain.tpl	
  
[{block name="details_productmain_title"}]
<h1 id="productTitle"><span itemprop="name">
[{$oDetailsProduct->oxarticles__oxtitle->value}]
[{$oDetailsProduct->oxarticles__oxvarselect->value}]</span></h1>
[{/block}]
Scheme: [Object name]->[Table name]__[Field name]->value
•  View controller: /application/controller/details.php
Drilling	
  down	
  (3)	
  
public function render()
{
$myConfig = $this->getConfig();
$oProduct = $this->getProduct();
}
public function getProduct()
{
$sOxid = oxConfig::getParameter( 'anid' );
$this->_oProduct = oxNew( 'oxarticle' );
if ( !$this->_oProduct->load( $sOxid ) ) {
...
}
}
Drilling	
  down	
  (4)	
  
public function load( $oxID)
{
$blRet = parent::load( $oxID);
public function load( $sOXID)
{
//getting at least one field before lazy loading the object
$this->_addField('oxid', 0);
$sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID));
return $this->_isLoaded = $this->assignRecord( $sSelect );
}
/application/models/oxarticle.php
/core/oxbase.php
Custom	
  classes	
  (1)	
  
•  Most	
  view-­‐	
  and	
  core	
  classes	
  can	
  be	
  overloaded	
  
•  Module	
  are	
  registered	
  in	
  backend	
  
•  Object	
  instantiation	
  via	
  oxNew():	
  core/oxutilsobject.php	
  
oxArticle
my_oxArticle
our_oxArticle
class my_oxArticle extends oxArticle
class our_oxArticle extends my_oxArticle
Custom	
  classes	
  (2)	
  
•  This	
  procedure	
  becomes	
  problematic	
  when	
  there	
  is	
  more	
  
than	
  one	
  new	
  module	
  wanting	
  to	
  extend	
  a	
  speci^ic	
  class.	
  
•  Solution:	
  oxNew()	
  dynamically	
  creates	
  transparent	
  classes	
  
in	
  the	
  form	
  of:	
  [class-­name]_parent	
  
•  This	
  means	
  that	
  by	
  means	
  of	
  the	
  following	
  structure,	
  module	
  
classes	
  can	
  be	
  chained:	
  
–  oxArticle	
  =>	
  my_oxArticle&our_oxArticle	
  
Plugins	
  (1)	
  
•  Task:	
  Write	
  a	
  module	
  that	
  displays	
  the	
  remaining	
  time	
  until	
  
X	
  mas	
  with	
  each	
  article.	
  
1.  New	
  module	
  directory:	
  /modules/xmas/	
  
2.  Publishing	
  it	
  via	
  metadata.php	
  (used	
  to	
  
be	
  via	
  Admin)	
  
'extend' => array(
'oxarticle' => ‘xmas/xmasArticle'
)
Plugins	
  (2)	
  	
  
class	
  xmasArticle	
  extends	
  xmasArticle_parent	
  
{	
  
	
  	
  	
  	
  public	
  function	
  getDaysLeft()	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  $time	
  =	
  mktime(0,	
  0,	
  0,	
  12,	
  25,	
  2011,	
  1)	
  -­‐	
  time();	
  
	
  	
  	
  	
  	
  	
  	
  	
  $days	
  =	
  ^loor($time/86400);	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  $days;	
  
	
  	
  	
  	
  }	
  
}	
  
<div>Only [{$oDetailsProduct->getDaysLeft()}] days left until Xmas!</div>
/modules/xmas/xmasArticle.php
/out/azure/tpl/page/details/inc/productmain.tpl
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Brief	
  History	
  
•  First	
  stable	
  version	
  released	
  in	
  2007.	
  
•  OS-­‐Edition	
  since	
  October	
  2010.	
  
•  Since	
  v.3.5	
  based	
  on	
  Enlight	
  Framework	
  (based	
  
on	
  ZF)	
  &	
  MySQL	
  
•  MVC-­‐Model	
  
•  Backend	
  based	
  on	
  ExtJS	
  4	
  
•  Templates	
  based	
  on	
  Smarty	
  3	
  
•  Recent	
  version:	
  4.0.7	
  
Enlight-­‐Framework	
  
•  Basis	
  functionalities	
  are	
  inherited	
  from	
  Zend	
  
Framework:	
  	
  
•  Syntax	
  and	
  Work^low	
  
•  Request-­‐	
  and	
  Response-­‐Objects 	
  	
  
•  Action-­‐Controller	
  Design	
  
•  Rewritten	
  Router	
  /	
  Dispatcher	
  and	
  View-­‐
Object	
  optimised	
  for	
  performance	
  and	
  
expandability	
  	
  
•  Own	
  plugin	
  system	
  based	
  on	
  events	
  and	
  hooks	
  
Template-­‐Structure	
  
index.tpl	
  
{* Content section *}
<div id="content">
<div class="inner”>
{* Content top container *}
{block name="frontend_index_content_top"}{/block}
{* Sidebar left *}
{block name='frontend_index_content_left'}
{include file='frontend/index/left.tpl'}
{/block}
{* Main content *}
{block name='frontend_index_content'}{/block}
{* Sidebar right *}
{block name='frontend_index_content_right'}{/block}
<div class="clear">&nbsp;</div>
</div>
</div>
Template-­‐Inheritance	
  
{extends file=”../_default/frontend/home/index.tpl}
{block name=’frontend_index_content’ prepend}
<h1>Hallo Welt</h1>
{/block}
SMARTY:
Append – Prepend - Replace
Plugin-­‐Directory	
  Structure	
  
Drilling	
  down	
  
Example:	
  	
  
How	
  to	
  get	
  from	
  the	
  article	
  name	
  in	
  
the	
  Smarty-­‐Template	
  to	
  the	
  database	
  ^ield?	
  
Drilling	
  down	
  (2)	
  
•  Article	
  detail	
  page:	
  templates_defaultfrontenddetailindex.tpl	
  
•  Part	
  that	
  displays	
  article	
  name	
  in	
  frontend	
  
•  Template-­‐Path	
  (frontend/detail/index.tpl)	
  tells	
  us	
  where	
  to	
  ^ind	
  the	
  
corresponding	
  controller.	
  In	
  this	
  case:	
  Shopware/Controllers/
Frontend/Detail.php	
  –	
  indexAction.	
  
•  Get	
  article	
  information	
  from	
  Model	
  and	
  assign	
  to	
  template	
  
•  Shopware()-­>Modules()-­>Articles()	
  is	
  a	
  service	
  locator	
  to	
  access	
  the	
  
main	
  article	
  object	
  that	
  could	
  be	
  found	
  at	
  /engine/core/class/
sArticles.php	
  	
  
•  sGetArticleById	
  fetches	
  a	
  certain	
  article	
  by	
  id	
  from	
  database	
  and	
  returns	
  
the	
  result	
  as	
  an	
  array	
  for	
  further	
  processing	
  
Plugins:	
  Bootstrap	
  
<?php
class Shopware_Plugins_Frontend_IPCDEMO_Bootstrap
extends Shopware_Components_Plugin_Bootstrap
{
public function install()
{
//
return true;
}
public static function onPostDispatch(Enlight_Event_EventArgs $args)
{
// Still empty
}
}
Plugins:	
  Event	
  
public function install()
{
$event = $this->createEvent('Enlight_Controller_Action_PostDispatch','onPostDispatch');
$this-> subscribeEvent($event);
$form = $this->Form();
$form->setElement('textarea', ’yourtext',
array('label'=>’Text for left column’,'value'=>’Hello World'));
$form->save();
return true;
}
Plugins:	
  Listener	
  
!public static function onPostDispatch(Enlight_Event_EventArgs $args)
{
$view = $args->getSubject()->View();
$config = Shopware()->Plugins()->Frontend()->IPCDEMO()->Config();
$view->pluginText = $config->yourtext;
$view->addTemplateDir(dirname(__FILE__)."/Views/");
$view->extendsTemplate('plugin.tpl');
}
Plugins:	
  Hooks	
  
<?php
class Shopware_Plugins_Frontend_myHook_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
public function install()
{
$hook = $this->createHook(
'sArticles',
'sGetArticleById',
'onArticle',
Enlight_Hook_HookHandler::TypeAfter,
0
);
$this->subscribeHook($hook);
return true;
}
static function onArticle(Enlight_Hook_HookArgs $args)
{
}
}
Summary	
  
• 	
  Each	
  system	
  employs	
  a	
  slightly	
  different	
  method	
  of	
  	
  
	
  	
  	
  inserting	
  custom	
  functionalities	
  
• 	
  Layout	
  and	
  functional	
  ^iles	
  are	
  more	
  or	
  less	
  
encapsulated	
  
• 	
  No	
  core-­‐hacking	
  required	
  –	
  still	
  a	
  need	
  for	
  testing!	
  
Thank	
  you!	
  
Blog:	
  romanzenner.com	
  
Skype:	
  roman_zenner	
  
XING:	
  xing.com/pro^ile/Roman_Zenner	
  
Twitter:	
  twitter.com/rzenner	
  
MVC-­‐Model	
  (extended)	
  
1 von 47

Recomendados

How to Write Custom Modules for PHP-based E-Commerce Systems (2011) von
How to Write Custom Modules for PHP-based E-Commerce Systems (2011)How to Write Custom Modules for PHP-based E-Commerce Systems (2011)
How to Write Custom Modules for PHP-based E-Commerce Systems (2011)Roman Zenner
223 views50 Folien
[2015/2016] Local data storage for web-based mobile apps von
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile appsIvano Malavolta
512 views40 Folien
In memory OLAP engine von
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
2.9K views22 Folien
D2W Stateful Controllers von
D2W Stateful ControllersD2W Stateful Controllers
D2W Stateful ControllersWO Community
1K views25 Folien
Life outside WO von
Life outside WOLife outside WO
Life outside WOWO Community
1.1K views45 Folien
Staying Sane with Drupal NEPHP von
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
603 views51 Folien

Más contenido relacionado

Was ist angesagt?

Presenting Data Effectively in XPages - ATLUG May 2013 von
Presenting Data Effectively in XPages - ATLUG May 2013Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013balassaitis
6K views75 Folien
Rich Internet Applications con JavaFX e NetBeans von
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans Fabrizio Giudici
1.2K views31 Folien
Paris Tech Meetup talk : Troubles start at version 1.0 von
Paris Tech Meetup talk : Troubles start at version 1.0Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0Laurent Cerveau
1.4K views25 Folien
JSP - Part 1 von
JSP - Part 1JSP - Part 1
JSP - Part 1Hitesh-Java
188 views30 Folien
Hibernate - Part 2 von
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2 Hitesh-Java
280 views54 Folien
MVC & SQL_In_1_Hour von
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
311 views97 Folien

Was ist angesagt?(18)

Presenting Data Effectively in XPages - ATLUG May 2013 von balassaitis
Presenting Data Effectively in XPages - ATLUG May 2013Presenting Data Effectively in XPages - ATLUG May 2013
Presenting Data Effectively in XPages - ATLUG May 2013
balassaitis6K views
Rich Internet Applications con JavaFX e NetBeans von Fabrizio Giudici
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
Fabrizio Giudici1.2K views
Paris Tech Meetup talk : Troubles start at version 1.0 von Laurent Cerveau
Paris Tech Meetup talk : Troubles start at version 1.0Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0
Laurent Cerveau1.4K views
Hibernate - Part 2 von Hitesh-Java
Hibernate - Part 2 Hibernate - Part 2
Hibernate - Part 2
Hitesh-Java280 views
MVC & SQL_In_1_Hour von Dilip Patel
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel311 views
Deploying Schemas and XMetaL Customization Files von XMetaL
Deploying Schemas and XMetaL Customization FilesDeploying Schemas and XMetaL Customization Files
Deploying Schemas and XMetaL Customization Files
XMetaL4K views
JAVA EE DEVELOPMENT (JSP and Servlets) von Talha Ocakçı
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı4.3K views
Angular - Chapter 6 - Firebase Integration von WebStackAcademy
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
WebStackAcademy255 views
Jdom how it works & how it opened the java process von Hicham QAISSI
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java process
Hicham QAISSI1.2K views
Internet Explorer 8 von David Chou
Internet Explorer 8Internet Explorer 8
Internet Explorer 8
David Chou3.2K views

Similar a Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)

CodeIgniter & MVC von
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVCJamshid Hashimi
3.3K views47 Folien
Magento mega menu extension von
Magento mega menu extensionMagento mega menu extension
Magento mega menu extensionBun Danny
418 views44 Folien
Codeinator von
CodeinatorCodeinator
CodeinatorMuhammed Thanveer M
388 views23 Folien
Magento 2.0: Prepare yourself for a new way of module development von
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentIvan Chepurnyi
5.8K views44 Folien
Social Connections VI — IBM Connections Extensions and Themes Demystified von
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes DemystifiedClaudio Procida
2.3K views31 Folien
ExtBase workshop von
ExtBase workshop ExtBase workshop
ExtBase workshop schmutt
1.2K views29 Folien

Similar a Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)(20)

Magento mega menu extension von Bun Danny
Magento mega menu extensionMagento mega menu extension
Magento mega menu extension
Bun Danny418 views
Magento 2.0: Prepare yourself for a new way of module development von Ivan Chepurnyi
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
Ivan Chepurnyi5.8K views
Social Connections VI — IBM Connections Extensions and Themes Demystified von Claudio Procida
Social Connections VI — IBM Connections Extensions and Themes DemystifiedSocial Connections VI — IBM Connections Extensions and Themes Demystified
Social Connections VI — IBM Connections Extensions and Themes Demystified
Claudio Procida2.3K views
ExtBase workshop von schmutt
ExtBase workshop ExtBase workshop
ExtBase workshop
schmutt1.2K views
Intro to Drupal Module Developement von Matt Mendonca
Intro to Drupal Module DevelopementIntro to Drupal Module Developement
Intro to Drupal Module Developement
Matt Mendonca814 views
AngularJS von Yogesh L
AngularJSAngularJS
AngularJS
Yogesh L695 views
Dexterity in the Wild von David Glick
Dexterity in the WildDexterity in the Wild
Dexterity in the Wild
David Glick1.3K views
Backbone.js von VO Tho
Backbone.jsBackbone.js
Backbone.js
VO Tho6.7K views
Math-Bridge Architecture von metamath
Math-Bridge ArchitectureMath-Bridge Architecture
Math-Bridge Architecture
metamath326 views
Andrii Sliusar "Module Architecture of React-Redux Applications" von LogeekNightUkraine
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
LogeekNightUkraine252 views
Drupal module development von Rachit Gupta
Drupal module developmentDrupal module development
Drupal module development
Rachit Gupta755 views
Apache Cayenne for WO Devs von WO Community
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community3.5K views

Más de Roman Zenner

Daten in Online-Shops: Personalisierung & die Freaky Line (2014) von
Daten in Online-Shops: Personalisierung & die Freaky Line (2014)Daten in Online-Shops: Personalisierung & die Freaky Line (2014)
Daten in Online-Shops: Personalisierung & die Freaky Line (2014)Roman Zenner
208 views20 Folien
KPIs für den E-Commerce (2014) von
KPIs für den E-Commerce (2014)KPIs für den E-Commerce (2014)
KPIs für den E-Commerce (2014)Roman Zenner
154 views21 Folien
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013) von
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)Roman Zenner
205 views22 Folien
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ... von
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...Roman Zenner
131 views30 Folien
Curated Commerce (2014) von
Curated Commerce (2014)Curated Commerce (2014)
Curated Commerce (2014)Roman Zenner
106 views27 Folien
... das muss doch einfacher gehen (2013) von
... das muss doch einfacher gehen (2013)... das muss doch einfacher gehen (2013)
... das muss doch einfacher gehen (2013)Roman Zenner
113 views27 Folien

Más de Roman Zenner(12)

Daten in Online-Shops: Personalisierung & die Freaky Line (2014) von Roman Zenner
Daten in Online-Shops: Personalisierung & die Freaky Line (2014)Daten in Online-Shops: Personalisierung & die Freaky Line (2014)
Daten in Online-Shops: Personalisierung & die Freaky Line (2014)
Roman Zenner208 views
KPIs für den E-Commerce (2014) von Roman Zenner
KPIs für den E-Commerce (2014)KPIs für den E-Commerce (2014)
KPIs für den E-Commerce (2014)
Roman Zenner154 views
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013) von Roman Zenner
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)
E-Commerce: Wachstumspotentiale erkennen und nutzen (2013)
Roman Zenner205 views
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ... von Roman Zenner
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...
Die Herausforderung der Einführung einer Multi-Channel-Strategie am Beispiel ...
Roman Zenner131 views
Curated Commerce (2014) von Roman Zenner
Curated Commerce (2014)Curated Commerce (2014)
Curated Commerce (2014)
Roman Zenner106 views
... das muss doch einfacher gehen (2013) von Roman Zenner
... das muss doch einfacher gehen (2013)... das muss doch einfacher gehen (2013)
... das muss doch einfacher gehen (2013)
Roman Zenner113 views
Neue Trends im E-Commerce (2011) von Roman Zenner
Neue Trends im E-Commerce (2011)Neue Trends im E-Commerce (2011)
Neue Trends im E-Commerce (2011)
Roman Zenner101 views
Wie wählt man das richtige Shopsystem? (2012) von Roman Zenner
Wie wählt man das richtige Shopsystem? (2012)Wie wählt man das richtige Shopsystem? (2012)
Wie wählt man das richtige Shopsystem? (2012)
Roman Zenner127 views
Github is from Venus, Excel is from Mars: Wie sich Entwickler und Business-En... von Roman Zenner
Github is from Venus, Excel is from Mars: Wie sich Entwickler und Business-En...Github is from Venus, Excel is from Mars: Wie sich Entwickler und Business-En...
Github is from Venus, Excel is from Mars: Wie sich Entwickler und Business-En...
Roman Zenner1.8K views
Commerce im Wandel: Steine, Schweine - und immer an die Leser denken! von Roman Zenner
Commerce im Wandel: Steine, Schweine - und immer an die Leser denken!Commerce im Wandel: Steine, Schweine - und immer an die Leser denken!
Commerce im Wandel: Steine, Schweine - und immer an die Leser denken!
Roman Zenner841 views
Mobile Commerce (Meet-Magento 04.10) von Roman Zenner
Mobile Commerce (Meet-Magento 04.10)Mobile Commerce (Meet-Magento 04.10)
Mobile Commerce (Meet-Magento 04.10)
Roman Zenner2.8K views
Magento-Schnittstellen von Roman Zenner
Magento-SchnittstellenMagento-Schnittstellen
Magento-Schnittstellen
Roman Zenner1.1K views

Último

Marketing and Community Building in Web3 von
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3Federico Ast
12 views64 Folien
PORTFOLIO 1 (Bret Michael Pepito).pdf von
PORTFOLIO 1 (Bret Michael Pepito).pdfPORTFOLIO 1 (Bret Michael Pepito).pdf
PORTFOLIO 1 (Bret Michael Pepito).pdfbrejess0410
8 views6 Folien
Is Entireweb better than Google von
Is Entireweb better than GoogleIs Entireweb better than Google
Is Entireweb better than Googlesebastianthomasbejan
12 views1 Folie
How to think like a threat actor for Kubernetes.pptx von
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptxLibbySchulze1
5 views33 Folien
DU Series - Day 4.pptx von
DU Series - Day 4.pptxDU Series - Day 4.pptx
DU Series - Day 4.pptxUiPathCommunity
106 views28 Folien
UiPath Document Understanding_Day 3.pptx von
UiPath Document Understanding_Day 3.pptxUiPath Document Understanding_Day 3.pptx
UiPath Document Understanding_Day 3.pptxUiPathCommunity
105 views25 Folien

Último(10)

Marketing and Community Building in Web3 von Federico Ast
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3
Federico Ast12 views
PORTFOLIO 1 (Bret Michael Pepito).pdf von brejess0410
PORTFOLIO 1 (Bret Michael Pepito).pdfPORTFOLIO 1 (Bret Michael Pepito).pdf
PORTFOLIO 1 (Bret Michael Pepito).pdf
brejess04108 views
How to think like a threat actor for Kubernetes.pptx von LibbySchulze1
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptx
LibbySchulze15 views
UiPath Document Understanding_Day 3.pptx von UiPathCommunity
UiPath Document Understanding_Day 3.pptxUiPath Document Understanding_Day 3.pptx
UiPath Document Understanding_Day 3.pptx
UiPathCommunity105 views
IETF 118: Starlink Protocol Performance von APNIC
IETF 118: Starlink Protocol PerformanceIETF 118: Starlink Protocol Performance
IETF 118: Starlink Protocol Performance
APNIC297 views
Building trust in our information ecosystem: who do we trust in an emergency von Tina Purnat
Building trust in our information ecosystem: who do we trust in an emergencyBuilding trust in our information ecosystem: who do we trust in an emergency
Building trust in our information ecosystem: who do we trust in an emergency
Tina Purnat100 views

Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)

  • 1. How  to  write  Custom   Modules  for  PHP-­based  E-­ Commerce  Systems   Roman  Z.  
  • 2. Roman  Zenner   •  Working  as  freelance  trainer,  author  and   consultant  since  2004   •  Has  written  three  books  on  Magento  and   OXID  eShop   •  Is  in  the  process  of  writing  a  “cookbook”   on  OXID  eShop  with  Joscha  Krug   •  Publishes  in  various  magazines  
  • 3. Initial  thoughts   •  Modularity  a  no-­‐brainer  in  today’s   ecommerce  software   •  There  must  be  a  way  of  extending  classes   or  an  event-­‐listener  system  in  order  to   integrate  custom  functionalities  
  • 4. Types  of  modules   •  Encapsulate  graphical  (template)   changes   •  Provide  additional  information  (e.g.  for   an  article   •  Special  calculations   •  Payment  and  shipping   •  Other  interfaces  (ImpEx,  etc.)  
  • 5. Today‘s  candidates   •  Magento   •  OXID  eShop   •  Shopware  
  • 8. Brief  History   •  First  stable  version  released  in  spring  2008   •  Community  Edition  under  OSL   •  Professional  and  Enterprise  Editions   •  Based  on  Zend  Framework  and  MySQL   •  Relies  heavily  on  EAV  structure   •  XML  de^initions   •  Bought  by  eBay  in  2011  (X.commerce)   •  Current  stable  version:  1.7.0.2  
  • 12. Templates  (2)   <block type="page/html“ name="root" output="toHtml“ template="page/3columns.phtml"> <block type="page/html_header" name="header" as="header"> <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/></block> </block> Template: /layout/page.xml <?php if(count($this->getStores())>1): ?> <div class="form-language“> <?php foreach ($this->getStores() as $_lang): ?> <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?> <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>> <?php endforeach; ?> </div> <?php endif; ?> Template: /template/page/switch/languages.phtml
  • 13. Drilling  down  (1)   Example: How to get from the article name in the template to the database field?
  • 14. Drilling  down  (2)   1.  Block: <block type="catalog/product_view" name="product.info" template="catalog/ product/view.phtml"> 2.  Template: /app/design/frontend/base/default/template/catalog/product/view.phtml 3.  Block class: Mage_Catalog_Block_Product_View 4.  Model: Mage_Catalog_Model_Product: public function getProduct() { if (!Mage::registry('product') && $this->getProductId()) { $product = Mage::getModel('catalog/product')->load($this->getProductId()); Mage::register('product', $product); } return Mage::registry('product'); }
  • 15. Drilling  down  (3)   1.  Abstract class: Mage_Core_Model_Abstract 2.  Resource model: Mage_Core_Model_Mysql4_Abstract public function load($id, $field=null) { $this->_beforeLoad($id, $field); $this->_getResource()->load($this, $id, $field); $this->_afterLoad(); $this->setOrigData(); $this->_hasDataChanges = false; return $this; }
  • 18. Brief  History   •  OS-­‐Edition  since  late  2008.   •  Based  on  own  PHP-­‐Framework  &  MySQL   •  Recent  version:  4.7.3  
  • 19. Features   •  ADODB  database  abstraction  layer   •  Uses  Smarty  2  (but  Template  Inheritance  by   Smarty  3)   •  Block  Inheritance   •  Autoloader  
  • 22. Template  Inheritance  (2)   [{capture append="oxidBlock_content"}] [{assign var="oFirstArticle" value=$oView->getFirstArticle()}] [{/capture}] [{include file="layout/page.tpl" sidebar="Right"}] /out/azure/tpl/page/shop/start.tpl
  • 23. Template  Inheritance  (3)   <div id="content"> [{include file="message/errors.tpl"}] [{foreach from=$oxidBlock_content item="_block"}] [{$_block}] [{/foreach}] </div> [{include file="layout/footer.tpl"}] /out/azure/tpl/layout/page.tpl
  • 24. Drilling  down  (1)   Example:     How  to  get  from  the  article  name  in   the  Smarty-­‐Template  to  the  database  ^ield?  
  • 25. Drilling  down  (2)   •  Article  detail  page:  /out/azure/tpl/page/details/inc/productmain.tpl   [{block name="details_productmain_title"}] <h1 id="productTitle"><span itemprop="name"> [{$oDetailsProduct->oxarticles__oxtitle->value}] [{$oDetailsProduct->oxarticles__oxvarselect->value}]</span></h1> [{/block}] Scheme: [Object name]->[Table name]__[Field name]->value •  View controller: /application/controller/details.php
  • 26. Drilling  down  (3)   public function render() { $myConfig = $this->getConfig(); $oProduct = $this->getProduct(); } public function getProduct() { $sOxid = oxConfig::getParameter( 'anid' ); $this->_oProduct = oxNew( 'oxarticle' ); if ( !$this->_oProduct->load( $sOxid ) ) { ... } }
  • 27. Drilling  down  (4)   public function load( $oxID) { $blRet = parent::load( $oxID); public function load( $sOXID) { //getting at least one field before lazy loading the object $this->_addField('oxid', 0); $sSelect = $this->buildSelectString( array( $this->getViewName().".oxid" => $sOXID)); return $this->_isLoaded = $this->assignRecord( $sSelect ); } /application/models/oxarticle.php /core/oxbase.php
  • 28. Custom  classes  (1)   •  Most  view-­‐  and  core  classes  can  be  overloaded   •  Module  are  registered  in  backend   •  Object  instantiation  via  oxNew():  core/oxutilsobject.php   oxArticle my_oxArticle our_oxArticle class my_oxArticle extends oxArticle class our_oxArticle extends my_oxArticle
  • 29. Custom  classes  (2)   •  This  procedure  becomes  problematic  when  there  is  more   than  one  new  module  wanting  to  extend  a  speci^ic  class.   •  Solution:  oxNew()  dynamically  creates  transparent  classes   in  the  form  of:  [class-­name]_parent   •  This  means  that  by  means  of  the  following  structure,  module   classes  can  be  chained:   –  oxArticle  =>  my_oxArticle&our_oxArticle  
  • 30. Plugins  (1)   •  Task:  Write  a  module  that  displays  the  remaining  time  until   X  mas  with  each  article.   1.  New  module  directory:  /modules/xmas/   2.  Publishing  it  via  metadata.php  (used  to   be  via  Admin)   'extend' => array( 'oxarticle' => ‘xmas/xmasArticle' )
  • 31. Plugins  (2)     class  xmasArticle  extends  xmasArticle_parent   {          public  function  getDaysLeft()          {                  $time  =  mktime(0,  0,  0,  12,  25,  2011,  1)  -­‐  time();                  $days  =  ^loor($time/86400);                  return  $days;          }   }   <div>Only [{$oDetailsProduct->getDaysLeft()}] days left until Xmas!</div> /modules/xmas/xmasArticle.php /out/azure/tpl/page/details/inc/productmain.tpl
  • 33. Brief  History   •  First  stable  version  released  in  2007.   •  OS-­‐Edition  since  October  2010.   •  Since  v.3.5  based  on  Enlight  Framework  (based   on  ZF)  &  MySQL   •  MVC-­‐Model   •  Backend  based  on  ExtJS  4   •  Templates  based  on  Smarty  3   •  Recent  version:  4.0.7  
  • 34. Enlight-­‐Framework   •  Basis  functionalities  are  inherited  from  Zend   Framework:     •  Syntax  and  Work^low   •  Request-­‐  and  Response-­‐Objects     •  Action-­‐Controller  Design   •  Rewritten  Router  /  Dispatcher  and  View-­‐ Object  optimised  for  performance  and   expandability     •  Own  plugin  system  based  on  events  and  hooks  
  • 36. index.tpl   {* Content section *} <div id="content"> <div class="inner”> {* Content top container *} {block name="frontend_index_content_top"}{/block} {* Sidebar left *} {block name='frontend_index_content_left'} {include file='frontend/index/left.tpl'} {/block} {* Main content *} {block name='frontend_index_content'}{/block} {* Sidebar right *} {block name='frontend_index_content_right'}{/block} <div class="clear">&nbsp;</div> </div> </div>
  • 37. Template-­‐Inheritance   {extends file=”../_default/frontend/home/index.tpl} {block name=’frontend_index_content’ prepend} <h1>Hallo Welt</h1> {/block} SMARTY: Append – Prepend - Replace
  • 39. Drilling  down   Example:     How  to  get  from  the  article  name  in   the  Smarty-­‐Template  to  the  database  ^ield?  
  • 40. Drilling  down  (2)   •  Article  detail  page:  templates_defaultfrontenddetailindex.tpl   •  Part  that  displays  article  name  in  frontend   •  Template-­‐Path  (frontend/detail/index.tpl)  tells  us  where  to  ^ind  the   corresponding  controller.  In  this  case:  Shopware/Controllers/ Frontend/Detail.php  –  indexAction.   •  Get  article  information  from  Model  and  assign  to  template   •  Shopware()-­>Modules()-­>Articles()  is  a  service  locator  to  access  the   main  article  object  that  could  be  found  at  /engine/core/class/ sArticles.php     •  sGetArticleById  fetches  a  certain  article  by  id  from  database  and  returns   the  result  as  an  array  for  further  processing  
  • 41. Plugins:  Bootstrap   <?php class Shopware_Plugins_Frontend_IPCDEMO_Bootstrap extends Shopware_Components_Plugin_Bootstrap { public function install() { // return true; } public static function onPostDispatch(Enlight_Event_EventArgs $args) { // Still empty } }
  • 42. Plugins:  Event   public function install() { $event = $this->createEvent('Enlight_Controller_Action_PostDispatch','onPostDispatch'); $this-> subscribeEvent($event); $form = $this->Form(); $form->setElement('textarea', ’yourtext', array('label'=>’Text for left column’,'value'=>’Hello World')); $form->save(); return true; }
  • 43. Plugins:  Listener   !public static function onPostDispatch(Enlight_Event_EventArgs $args) { $view = $args->getSubject()->View(); $config = Shopware()->Plugins()->Frontend()->IPCDEMO()->Config(); $view->pluginText = $config->yourtext; $view->addTemplateDir(dirname(__FILE__)."/Views/"); $view->extendsTemplate('plugin.tpl'); }
  • 44. Plugins:  Hooks   <?php class Shopware_Plugins_Frontend_myHook_Bootstrap extends Shopware_Components_Plugin_Bootstrap { public function install() { $hook = $this->createHook( 'sArticles', 'sGetArticleById', 'onArticle', Enlight_Hook_HookHandler::TypeAfter, 0 ); $this->subscribeHook($hook); return true; } static function onArticle(Enlight_Hook_HookArgs $args) { } }
  • 45. Summary   •   Each  system  employs  a  slightly  different  method  of          inserting  custom  functionalities   •   Layout  and  functional  ^iles  are  more  or  less   encapsulated   •   No  core-­‐hacking  required  –  still  a  need  for  testing!  
  • 46. Thank  you!   Blog:  romanzenner.com   Skype:  roman_zenner   XING:  xing.com/pro^ile/Roman_Zenner   Twitter:  twitter.com/rzenner