March 29, 2009

Ajax in Zenmagick

Tags: , , , , ,
Filed under: ZenMagick — DerManoMann @ 11:15 pm

ZenMagick comes with a basic set of Ajax support and tools. This includes both storefront and admin.
Here is a quick overview about what is currently possible and how it is done.

1) storefront
Ajax requests are handled by controllers, just like any other request. The point is that this allows the same theme specific customization like any other page/request. it also means that security settings, enforcing HTTPS, etc. are all available.

There is a difference, though, in that Ajax controller inherit from a different controller base class ZMAjaxController. To avoid having to write a new controller for each Ajax request things are organized a little different, though. Typically, each Ajax request maps to a single method call on the server side (or at least a single operation). This is reflected in the way controller are organized.

Each controller may have multiple methods to handle different requests. Currently, there are 3 Ajax controller:

Consequently, each Ajax URL needs two parts: the controller name and the method to be called. The net component of the toolbox has a helper method to simplify generating those URLs:

$net->ajax('shopping_cart', addProduct');

Obviously, you’d need to add at least a productId to the URL (and optionally the quantity). The demo store includes an Ajax demo page that shows most available features.

2) admin
As with all admin stuff, things are a bit improvised. There is a file zmAjaxHandler.php that acts as central entry point for admin ajax requests. All it does is to find a matching controller for the request and execute that. Again, URLs are created using the toolbox with the same method.

That means all Ajax requests are available to both storefront and admin.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.