Archive for 2009

Magento Header and Footer Integration, Via Ajax

Thursday, October 29th, 2009 by

magento header and footer
Often, we need to integrate other platforms (for example WordPress, phpBB, etc) with Magento. This usually begins with unifying the design and then synchronizing the user account. Towards the end if the cross-talk becomes too complicated, it would be easier to build some specific APIs to tackle this.

Here we are going to walk through a quick and neat way to extract the Magento header and footer, and the inject them into another platform, in the following steps:

  • Create a blank Magento CMS page for the extraction
  • Build Ajax code to retrieve the header and footer
  • Update the HTML page

(more…)

Magento Onepage Checkout – down the rabbit hole, and what about the JavaScript?

Thursday, September 3rd, 2009 by

The Magento Onepage Checkout is quite a tricky component. For simple tasks, it is quite possible to change the PHP code with surgical precision without messing around with the JavaScript part. But unfortunately, in many complicated tasks, like adding a new step with a bunch of new functions, would inevitably involve JavaScript handling.

Here come a couple of useful tips:

Our final target is the opcheckout.js, located at: skin/frontend/default/default/js/opcheckout.js

Before we jump into hundreds of lines of JS codes, our first stop should be the template files for the Onepage Checkout. At the end of those files, you will see something like:

[codesyntax lang="javascript" lines="fancy"]
<script type=”text/javascript”>
//<![CDATA[
var billing = new Billing('co-billing-form', ...);
//]]>
</script>
[/codesyntax]

Yes, this is the critical link between our PHP part and JS part.

(more…)

Unleash the Power of Magento EAV Database Structure, Generic EAV Object

Tuesday, August 11th, 2009 by

One of the major features of Magento is the Entity-Attribute-Value (Magento EAV) data model.

This is indeed quite a block to play with. However with the right leverage, it can become rather handy.

To some extent, using EAV is, arguably, an improvement. The major advantage of the Magento EAV is: there won’t be endless ad hoc attributes inserted to the table, which is one of the critical flaw for older platforms, say OS-commerce, where table columns rapidly grow to an unmanageable size.

On the other hand, EAV basically means no raw queries of the database, or at least very challenging if you are really determined to query directly into the database, not to mention that an upgrade will easily break your code. This is, indeed, very clumsy for simple things like selecting a group of products or customers. In addition, there is quite an efficiency trade-off since there would be quite a few table joint to load an EAV object. Also, quite a lot of data a duplicated throughout different tables, a small price we have to pay.

Despite all these, personally, I find the Magento EAV quite okay. I guess the decision making factor for the Magento team to choose EAV tables against flat table is that EAV is generically more flexible. It’s relatively easy to maintain given the fact more than often multiple developers/teams are involved in the same project.

(more…)

Magento Adminhtml – Using the Same Backend to Frontend Structure

Thursday, July 30th, 2009 by

The Magento adminhtml (or admin panel) is quite different from other modules for the frontend. The Adminhtml module has a distinct implementation of the Model-Controller-View scheme. In fact, forms, tables, graphs and etc. are usually stereotypical and highly repetitive comparing to the large varieties in the frondend. As a result, in Adminhtml page, such elements are generalized into block ‘widgets’ to boost coding efficiency.

However, when building a new module, we often need to modify the frontend and the backend together. And in many cases, since the we already build the functions in frontend module, it’s really a waste of energy if we have to rewrite everything in terms of ‘widget’ in the backend. Simply, we would like to migrate the controller and view to the backend and reuse the code.

Here, I’m going to go through the basic steps the Mage_Adminhtml_Block_Template rather than widgets.

(This is a developer’s guide.)

Let’s begin with creating a new menu in the Admin panel. We added to the config.xml to our new module:

[codesyntax lang="xml" lines="fancy"]

<adminhtml>
  <menu>
    <new_module translate="title" module="new_module">
      <title>New Module Name</title>
      <sort_order>50</sort_order>
      <action>new_module/new_controller</action>
    </new_module>
  </menu>
</adminhtml>

[/codesyntax]

(more…)

Create a new Magento attribute and attribute group using the sql setup file

Wednesday, July 8th, 2009 by

More than often, we need to create a new Magento attribute to extend some Magento functions, or even a new attribute group to serve our own module.  Here is how we do it using the sql setup file.

First, a few words about the sql setup file.

If this is the first time building the module or fresh installation, create a php file, say “mysql4-install-0.1.0.php”, in [company]/[module]/sql/[module]/[module]_setup/ folder, where the version 0.1.0 is defined the the config.xml file.

In case of module upgrade, try something like “mysql4-upgrade-0.1.0-0.2.0.php”, again, verify your upgrade version in the config.xml file.

Inside this file, first we need to initiate:

[codesyntax lang="php" lines="fancy"]

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

[/codesyntax]

(more…)