Sylvain Rayé - Blog about Web Technologies and Magento

The creation of a new website is always a new event for the team or developers who built it. We always expect to provide interest and responses to the needs of the visitors.
Providing good or interesting content is always a challenge and we hope that the visitors will participate. That's the reason I decided to move a part of the content of www.diglin.com website to the new website: http://www.sylvainraye.com.
You will find in this new website the articles that we talked here and new articles about larger topics like developing in a team, mobile, ecommerce, new technologies and so on. It is optimized for Smartphone and Tablets. 
Don't hesitate to visit it and let me a message.

Concerning the content of this website, a part will be kept here for archive and the rest is already moved. But what about diglin.com ?

It is with a pleasure to announce that diglin.com will be moved to a new platform: a Magento Marketplace Modules.

I discovered few weeks ago an interesting tool to develop Magento modules with Eclipse PDT or Zend Studio: the Magento Eclpise plugin. I use it personnaly with Zend Studio 8 and it works pretty well, so we are going to see the different feature you can get from this module. With this module you can:

  • Find two wizards to help you to extend or create Magento modules
  • Code completion for core class or method even when you use Mage::getModel() or Mage::getSingleton() and so on.

Install the plugin


In Zend Studio, click on Help menu > Install Software. A new window will open, click  "Add", set a name like "Magento plugin" then paste the url of the plugin "http://magento-plugin.googlecode.com/svn/update_site" into the location field. After to have submitted the changes, you should see in the list the plugin. Select it and follow the wizard by clicking on "Next".
magento-plugin-install
After the installation process, you will have in the dialog box of the menu New > Other ..., a new directory Magento and you will see the two wizards available to start or extend a module.
For your Magento projects, you will have to enable the plugin features for the code completion. Just show on your project folder in your Navigator or PHP Explorer, the contextual menu. You should see the Magento Plugin menu item and sub-item "Add Magento Nature". Select it to enable the feature for your project.
The code completion seems to work only for core modules of Magento, not for the modules which are in the community or local folder in app/code/ of your Magento installation.
magento-plugin-code-completion magento-plugin-code-completion-expl

Wizard to create module

To create a module in an easy way. Nothing better than the wizard of the Magento plugin for Ecipse. It makes your life easier because you can directly generate the basic structure folders and configuration xml files. Maybe some of you, will prefer to get more generated files like controllers, block grid for the backend, a model and its resource to get access to the database, you can use instead Module Creator from Netz98 at this address http://www.magentocommerce.com/magento-connect/modulecreator.html. The counterpart of this last solution is that it won't feet all of your needs and you should have to remove some part of the codes or files.
Let's come back on the Magento plugin for Eclipse. To start the wizard, choose in the menu New > Other ..., in the new dialog box, search the folder Magento and choose the wizard "Magento Module". The wizard will start with the informaion to fill in about the module:
  • project
  • name
  • code pool
  • version
  • dependencies
  • namespace

After you have clicked on "Finish", your module will have some predefined folder and files in different place in your project. Here is the skeleton:

  • app / code / CODE_POOL / NAMESPACE / MODULE_NAME / Block
  • app / code / CODE_POOL / NAMESPACE / MODULE_NAME / controllers
  • app / code / CODE_POOL / NAMESPACE / MODULE_NAME / Helper / Data.php which is usefull to help you to translate the string of your module
  • app / code / CODE_POOL / NAMESPACE / MODULE_NAME / Model
  • app / code / CODE_POOL / NAMESPACE / MODULE_NAME / sql and a sub-folder to set your database script for installation and upgrade
  • app / etc / modules / MODULE_NAME.xml which is the file to enable or not your module and define the dependencies
Magento-plugin-WizardMagento-plugin-Wizard-step2Magento-plugin-Creation-Module

 

Wizard to extend module

The wizard is very similar to the one of the creation module. The difference is that after to have fill in your module information, you will have an additional step to select the module to overwrite and select the classes to overwrite. I could not see completely the result because there were a bug while finishing the wizard. The module was correctly created but didn't create neither the overwritten class nor updated the config.xml. An issue has been submitted. I will update this article when it will be resolved.

It is with a great pleasure that the Magento Core Team published a public version of the development Magento 2 and information about it. This new version is still in development and will be available when stability, code quality, features and documentation will be finished. It is expected in one year (end 2012). Lots of lack blamed for version < Magento 2 are going to be history (we hope).

The target of this new version is to provide a better documentation (a complete wiki for store owner, developer, system administrator or designer target public is available and still in progress), an improvement of the performance / security / scalability (EAV still exists), PHPUnit Tests and Automatic Static Code Analysis Tests (including PHP Detector Copy/Paste, PHP Code Sniffer, PHP Mess Detector), easier and better support of multilanguage, etc.

But don't worry dear Magento 1.x developers, not everything has been changed. At the program,  refactoring of some classes, naming convention and templating and skin folders restructuration have been done at the moment. We will see some changes in this first article and how to handle it to upgrade your extensions. Remember, it's still in development, so the information are there just to keep you informed. I will try to prvovide you up to date information until the official release on this website.

If you are a third party developer, you should follow the recommandations and best practises based on Zend Framework Best Practises and Magento Best Practises (Licenses and category/package/author tags in the docblock of class' header) to migrate your extensions.

You will find all necessary links about the Magento 2 development version (documentation, svn, tools) at the bottom of this article. But first, I did for you, a resume of the significant changes done between Magento 1.x and 2.x based on the documenation available in the Magento 2 Wiki.

FILE STRUCTURE CHANGES FROM 1.X TO 2.X

New folders:

/dev internal tools and tests. Previously: /shell, /tests, /tools to /dev/shell, /dev/tests, /dev/tools
/pub All public content: /pub/images, /pub/jslib, /pub/skin, /pub/error - Fallback/Materialized files are stored in this folder

Removed folders:

/includes Compiler feature is removed
/downloader Folder removed but the Magento Connect feature is moved to /app/code/core/Mage/Connect/

Template / Layout folders

One of the main changes is that base theme files and folders (layout, template) are moved to each module folder in a folder named "view". It means you will get for your module the following structure app / code / <code_pool> / <Namespace> / <Module> / view / <area> / *

  • Namespace = your company name or else
  • Module = module name ;-)
  • code pool = core, local or community
  • area = frontend or backend
  • package
  • theme

Here are some examples of the migrated folders:

  • for emails template, FROM app / locale / en_US / emails / * .html TO app / code / <code pool> / <Namespace> / <Module> / view / *.html
  • for skin files of a specific module in adminhtml area (js, css, skin images), FROM skin / adminhtml / default / default / * TO app / code / <code pool> / <Namespace> / <Module> / skin / adminhtml / *
  • for skin files of a specific module in frontend area (js, css, skin images), FROM skin / frontend / default / default / * TO app / code / <code pool> / <Namespace> / <Module> / skin / frontend / *
  • for layout and template files (*.phtml), FROM app / design / frontend / default / default / layout (or template) / * TO app / code / <code pool> / <Namespace> / <Module> / view / layout.xml as a convention (or path/to/file/*.phtml)

And non-base theme files (confer Magento wiki: theme files that overlap base files in modules) are structured as follow:

  • An overwritten template file, FROM app / design / frontend / <package> / <theme> / template / <module_alias> / path / to / template.phtml TO app / design / frontend / <package> / <theme> / <Namespace_Module> / path / to / template.phtml

A Module directory structure will lookt at this:

__/app/code/<Pool>/<Namespace>
|__/<Module>
|__/Block
| |-- Sample.php
|__/view
| |__/adminhtml
| |__/frontend
| | |-- layout.xml
| | |-- sample.phtml
| |__/install
| |-- contact_email.html
|__/skin
|__/adminhtml
|__/frontend
|__/images
| |-- image.jpg
|-- favicon.ico
Source Magento Wiki Module View

Fallback/Materialization mechanism

The fallback mechanism still exists and if you want to overwrite a template or layout file, you still need to use the folder structure app / design / <area> / <package> / <theme> / <Namespace_Module> / layout.xml (or path / to / template.phtml). Layout and template folders doesn't anymore exist but you will notice that you need to use the combination Namespace and Module as a folder name for the layout and template files.
All public content are stored in the folder /pub, it contains static files like images, javascript or css and are copied from the module skin folder. They will be automatically redundantly saved once or after an update, following its folder structure in the module view folder, to the /pub folder to keep only this folder visible to public and make skin modular too.

You will get the following structure for the static files:

  • / pub / skin / <area> / <package> / <theme> /  *
  • / pub / skin / <area> / <package> / <theme> / <Namespace_Module> / *
For the fallback mechanism, you can still use a design package folder structure:
__/design
|__/frontend
|__/<packageName>
|__/<themeName>
|__/layout
|__/skin
| |__/<skinName>
|   |__/css
|   |__/images
|   | |--image.jpg
|   |__/locale
|     |__/<localeCode>
|       |--translate.csv
|
|__/<Namespace_Module>
|--layout.xml
|--sample_template.phtml
For a more information about module view, you can check the Magento Wiki Module View

Skin File Duplication Option

This option, if enabled, creates automatically a copy of static files which is not locale dependant to all other locale store View. For example, you have a file logo.png for the locale en_US, the file be copied automatically to the fr_FR locale folder of the / pub / skin / <area> / <package> / <theme> / default / locale folder.
To enabled it, you have to edit the file app / code / <code_pool> / <Namespace> / <Module> / etc / config.xml and provide this xml code:

<default>
        <design>
            <theme>
                <allow_skin_files_duplication>1</allow_skin_files_duplication>
            </theme>
	</design>
</default>

Conclusion

Here were some few examples of the new features and way how will go our preferred open source commerce. And it will stay like that, Open Source, even if Magento has been bought by eBay. I don't know yet what will be exactly the next steps but I make a new article about the framework and his new behaviour and coding practises. If your impatient, well, you can still visit the links below to show you more information and detailed explanation of what we see here.

Magento 2 links (some are working in progress):

New modules version for Magento 1.6
All modules I did has been rewritten to improve and set it compatible with MAgento 1.6 if necessary. As reminder, you will find a list of the modules with a short description:
  • Add Information to Sales Email : you can add in the sales email (invoice, order, credit memo) complementary information about the products which are ordered by your customers.
  • Zopim Chat: display and customize per Store View the Chat service from Zopim. It's not an official module of Zopim.
  • Joomla Integration: it helps you to integrate Joomla modules into Magento, you will need Jfusion. Documentation is available on this website.
  • JS/CSS Compression & Minify (UIOptimization): compress and monify your css et javascript files to improve Magento performance. Several methods are available to suit your system.
  • Username support: accept your customer to login or create an account thanks to an email and a username

The Zopim Chat (unofficial) module for Magento has been updated and it's free. This update should improve the performance of Zopim calls and add some new small feature. It follows the available API from the zopim.com website. The Core Team has changed the javascript code.

Please, feel free to download it at the Magento Connect.

Profiling

As promised, I provide you below the statistic of compression and ratio by using the different libraries with the help of my UI Optimization module that you can find into Magento Connect

Compressed/Minified file statistic and comparison by using default Magento template, sample data, configuration for Rissp User Interface Optimization module is for all by default. Only the method to compress/minify is changed. 
Merging file has no influence on compression but has influence on number of HTTP requests which is also an important point.

**** JS compression (analyzed with YSlow):

- no compression, no miniying, no merging:  329.8 Kb

- JSMin (unmerged, no gzip): total 230.4Kb (31% of compression)
- JSMin (merged, no gzip): total 230.4Kb
- JSMin (merged, gzip): total 56.8Kb (compression 83%)

- YUI compressor (unmerged, no gzip): total 193.6 Kb (compression 41%)
- YUI compressor (merged, no gzip): total 193.6 Kb
- YUI compressor (merged, gzip): total 52.6 Kb (compression 84%)

- Packed (unmerged, no gzip): total 133.5 Kb (compression 59%)
- Packed (merged, no gzip): total 133.5 Kb
- Packed (merged, gzip): total 44.5 Kb (compression 86.5%)

**** CSS compression (analyzed with YSlow):

- no compression, no miniying, no merging, no gzip: 95.9 kb

- CSS Tidy (unmerged, no gzip): total 79.8 Kb (compression 17%)
- CSS Tidy (merged, no gzip): total 79.8 Kb
- CSS Tidy (merged, gzip): total 14.7 Kb (compression 85%)

- YUI compressor (unmerged, no gzip): total 82.7 Kb (compression 14%)
- YUI compressor (merged, no gzip): total 82.7 Kb
- YUI compressor (merged, gzip): total 14.5 Kb (compression 85%)

- Google Minify (unmerged, no gzip): total 79.9 Kb (compression 17%)
- Google Minify (merged, no gzip): total 79.9 Kb
- Google Minify (merged, gzip): total 14.9 Kb (compression 84.5%)

CONCLUSION:
- for JS: 1) YUICompressor 2) JSMin 3) Packed (for compatibility problem with Magento)
- for CSS: 1) CSSTidy 2) Google Minify (almost good as CSSTidy) 3) YUICompressor

In next release of this module, I will offer HTML minifying

For the magento community edition (and maybe the Enterprise edition too), the CMS included could be a little bit too short for some needs.If you need the first free open source CMS, with the availability of lots of extensions and a big community and you would like to integrate with the first open source shop, you probably need this free extension.

It allows you to:

  • integrate module from Joomla into Magento like poll, menus, latest news, popular news and most every modules available in the joomla community. It takes the template from the Joomla module.
  • put in Magento cache, the integrated module to optimize the speed of the display.
  • automatically synchronize the language with Joomla if you have Joomfish installed in it.
  • deactivate temporary customer account from Customer Management page (bonus functionnality).
  • get access to Joomla Backend from Magento backend (no backend Single Sign On for the moment)
  • content Url rewriting (secure/unsecure depending on the Magento context)

Required:

  • JFusion components version > 1.5.x for Joomla 1.5.x
  • Magento 1.3.x & 1.4.x compatible
  • Joomla 1.5.x compatible
  • Cache activated in Magento (e.g. APC) to optimize if wished (optional)
  • Joomfish in Joomla for multilanguage stores (optional)

Not compatible:

  • With Joomla modules using JQuery or Mootools javascript framework, there is problem cause of Prototype framework used in Magento

See www.jfusion.org and www.diglin.com website for more informations, documentation and other available modules about integration between Joomla and Magento.
You can find modules in Joomla to integrate Joomla user, Modules from Magento into Joomla.

Diglin.com is more specialised for information about Joomla / Magento integration: documentation, modules about this subject
Jfusion.org provide the basic component of all of this and even more. You can integrate other kind of web application (phpbb, gallery, moodle, smf)

thumb_demo_joomla_module_integration_menus thumb_jfusion_joomla_module

I published a new module for Magento to integrate the Zopim Chat into your Magento Shop installation. This is an unofficial version of the moduel and not supported by Zopim but only by diglin.

This module has for advantage:

  • to allow to create a configuration for each store view
  • to configure some options of the Chat: window, buble, button (color, position, text, language synchronisation mode ...) for all store views or for a specific one.
  • to get access to the Zopim dashboard directly from your Magento backend and chat directly with your visitors.

An official version exists but don't take in charge the configuration per store view and doesn't allow to define the chat for specific Magento page.

You can visit the Magento Connect page to get this module. Clic on the pictures below to zoom in and get a preview of the module. You can click on the button "Read more" to get more information about Zopim Chat.

thumb_Zopim_Chat_Diglin01 Zopim Chat configuration Zopim Chat Backend Integration in Magento

Read more...

@Note: the solution below is not for the moment 100% compatible with third party modules like GoogleBase. I will try to find an improved way. There is a note below for developer to help to find a better way. Thx for your feedback.

Note: a functionnal solution is provided at the end of this article thanks to Frank in the comments.

For those who meet a problem with their Magento backend after to have customized the url access (e.g. http://www.magento.com/backend/) thanks to the file /app/etc/local.xml. They can get an error page 404 - Page Not Found after to be logged. This situation exists only if you have activated the configuration Store Code into URL ( System > Configuration > Web > Url Options > Add Store Code to Urls - YES).

The solution is to tell to Magento to not use Store Code in url for our customized url backend. You just need to edit the file local.xml in the following way: {backend_customized_name} = backend in our exemple http://www.magento.com/backend/

Below an exemple of local.xml file:

<config>
<global>
...
<request>
<direct_front_name>
<{backend_customized_name} />
</direct_front_name>
</request>
</global>
<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[{backend_customized_name}]]></frontName>
</args>
</adminhtml>
</routers>
</admin>
</config>

Note the Tags <request><direct_front_name>< {backend_customized_name} /> </direct_front_name></request>.
< {backend_customized_name} /> is a tag and not the content of an XML element.
Replace only {backend_customized_name} by backend (in our example) or else.

Then you won't get anymore this 404 error for adminhtml modules.

@developers:
If you want to deep more about this subject, take a look in the file /app/code/core/Mage/Core/Controller/request/Http.php line 148. The problem comes from here.

 

if ($this->_canBeStoreCodeInUrl()) {
$pathParts = explode('/', ltrim($pathInfo, '/'), 2);
$storeCode = $pathParts[0];
 
if (!$this->isDirectAccessFrontendName($storeCode)) {
$stores = Mage::app()->getStores(true, true);
if ($storeCode!=='' && isset($stores[$storeCode])) {
Mage::app()->setCurrentStore($storeCode);
$pathInfo = '/'.(isset($pathParts[1]) ? $pathParts[1] : '');
}
elseif ($storeCode !== '') {
$this->setActionName('noRoute');
}
}
}

 

Solution from Frank: A solution for this problem is to change the action of the login form.
File is in app/design/adminhtml/default/default/template/login.phtml.
Replace the line [code]<form method="post" action="" id="loginForm">[/code] with [code]<form method="post" action="getUrl('adminhtml') ?>" id="loginForm">[/code] and the problems is fixed.


On Sunday 21th March at the Palais des Congrès of Bordeaux will take place the JoomlaDay, a conference about Joomla with presentations and ateliers on different extensions and techniques to use Joomla and improve or raise its capacities.

Diglin will be there as a presenter between 14h45 and 16h15 to present the oppurtunities provided by JFusion and its plugins to integrate Joomla and Magento. A case study will be shown thanks to the elearning platfrom rissip.com.

More info on the website JoomlaDay.fr