CODEgrunt blog

Commentary and insight on web development and the Internet at large written with a wry smile and a hungry look.

sorting carriers in Prestashop - Mon Oct 10, 2011

Prestashop 1.4 has some very customization friendly features. In particular the new concept of class overrides adds an immense amount of flexibility to the system without compromising the integrity of the core codebase.

As of this writing, Prestashop does not sort shipping carriers before displaying them to the customer . . . they will show up in the order they have been added to the system which may not be ideal. Changing this behaviour used to mean modifying core files but thanks to the override system, this is now possible without breaking upgradeability.

The following override class changes the default behaviour to instead sort the carriers by ascending price. To use it, save the file as "/overrides/classes/Carrier.php" in the root folder of your Prestashop install.

<?php class Carrier extends CarrierCore { public static function getCarriersForOrder($id_zone, $groups = NULL) { $carriers=array(); $result=parent::getCarriersForOrder($id_zone, $groups); if($result) { if(count($result)>0) { $sort=array(); foreach($result AS $k=>$v) { $sort['_'.$k]=$v['price']; } asort($sort,SORT_NUMERIC); foreach(array_keys($sort) AS $k) { $carriers[]=$result[(substr($k,1))]; } } } return $carriers; } } ?>

topics: PHP, Prestashop

CMS Made Simple - a web developer's review - Wed Feb 16, 2011

When starting on a new project one of the choices to be made is whether to start from scratch or to go with an existing platform. Starting from scratch means more flexibility but this comes at the expense of requiring more development time. These days I will almost always try to find an existing solution that can be extended so that the client's budget can be spent on customization instead of on re-inventing the wheel. For content management, the recursively named CMS Made Simple is one such option.

When working with a CMS I feel that the single most important criteria is the difficulty of integrating a client's design within the CMS's framework. Many CMS systems fail this requirement right from the get go by either embedding layout into difficult to work with PHP functions (commonly seen with legacy table based layouts) or using a confusingly laid out and / or poorly documented MVC approach (which leads to head scratching situations of having no idea where the layout is coming from).

Note: this is not a knock against the MCV paradigm, just some unnecessarily convoluted implementations of it

The most common workflow is to start with a pure HTML / CSS mockup and then integrate that into the CMS. This means that at the very least any potential CMS application needs to provide:

true template support
Layout needs to be removed as much as possible from program logic for both flexibility and ease of updates.
an approach to page rendering that is not utterly arcane or inflexible
If the flow from template to rendered output is confusing, it will be both time consuming and difficult to make changes. If inflexible, the client will have to conform to what the CMS wants instead of what they want.
readable object oriented code
If the codebase is a legacy one (especially with embedded layout), it will be harder to maintain, more difficult to learn and more prone to code rot issues (bugs, security problems, etc.).

While not the solution for all cases, CMS Made Simple is one of the most straight forward solutions I have come across. To start with, it nails my requirements for true template support and a straight forward rendering pipeline. Template support is handled via the competent 3rd party library Smarty. Smarty is well documented and by using its built in "{debug}" command, it is for the most part trivial to reverse engineer what is available to the template at rendering time. Smarty also covers all common escaping and conditional layout flow without having to resort to inline PHP.

Within CMS Made Simple, Smarty's built in functionality is extended via a "custom tag" mechanism. Custom tags are a way of creating special use logic which can then be referenced within templates without having to rely on gross and kludgy inline PHP or hacking in new functions to the codebase itself. An example would be a custom tag I created for a client which sets up an array of PDF filenames pulled from an arbitrary directory on the web host based on the page alias of the current CMS document. This mechanism is very handy as it allows for quick and re-usable extension of site functionality without having to delve too far into codebase's internals or modifying core files.

The rendering flow in CMS Made Simple is also reasonably obvious and flat:

template -> page

At the top level you have templates and style sheets. Each template can have one or more style sheets associated with it and can via Smarty tags can also include sub-templates and / or other dynamic content. Templates will normally include one or more "{content}" placeholders which represent editable sections of layout under the user's control (there are other placeholders that provide similar functions for images and other content types). Once a template has been setup and associated with any desired CSS files, the next step is to create a "page".

A page represents an accessible spot on your website, most commonly a page containing content ("About us" or "Our Homepage"). Each page will have a spot in the global menu hierarchy and will have a template associated with it. The template dictates what the editing process looks like - you might have multiple content sections for example or your template may call in an external module (a web calendar for example). It is fairly simple for the designer to create a relatively safe environment for the client to be able to edit content without completely messing up unrelated layout. Since the stacking of the layout generation is relatively flat, it is also quick to get from mockup to finished page and easy to track down the source of any problems encountered.

For the basic requirement of creating a website which a client can update themselves relatively safely, CMS Made Simple does exactly what its name claims. So far I have yet to find a comparable codebase that is as easy to work with. For more advanced functionality however the situation is a bit murkier.

How CMS Made Simple deals with anything outside of the core functionality is via modules. If you want to do anything beyond basic content management (static pages) or posting date based articles (news), you will need to use a 3rd party module. For example, the stock system provides a permissions based account system designed around content control which is not intended for public facing functions like adding comments to articles. If you want to setup a blog with CMS Made Simple, you will need to use 3rd party modules to implement everything beyond the basic date based article listing.

On the plus side, there are a wide range of modules available from the platform ranging from "front end users" (unprivileged accounts which can be used for allow comments on articles) to an event calendar to image galleries. On the negative side, this means that some functions that one might consider central to a CMS are not part of the core codebase. The most significant fallout from this design decision is that the modules are not guaranteed to work with future updates and also vary in quality and integration. Personally I see this offloading of maintenance to module developers a significant limitation of CMS Made Simple which reduces its viability for use with community centric websites.

It should also be noted that CMS Made Simple has fairly light server requirements. Unlike huge sprawling systems like Movable Type, CMS Made Simple should function fine on the majority of LAMP web hosts.

Alternatives to CMS Made Simple

I have looked around a fair bit and there are surprisingly few current codebases out there which meet my primary requirement of straight forward templates. One possible alternative is Concrete5. Concrete5's approach to design is to use an inline AJAX heavy editor which allows the user to modify content by browsing the site the same way any regular web user would. It does have a reasonably flexible template system though the granularity is definitely increased and some may find it overly convoluted to get from mockup to usable template. On the plus side it is less dependent on modules for what is arguably core functionality these days. On the negative side, the inline editing scheme can be complex at times and may simply be too time consuming to use in some environments.

While not a content management system, for e-commerce focussed sites Prestashop does include rudimentary CMS function which may be enough to suffice if the majority of your site is dedicated to store functionality. It also uses Smarty as its template engine and is comparatively easy to theme. The codebase is current, actively updated and in general well written and easy to follow.

In Conclusion

I have spent about 30 hours working with CMS Made Simple and so far have been able to solve any issues I have come across. It will not be ideal for all situations but for simpler cases where a client needs to manage content on an informational website it is definitely worth a look.

MonerisHPP payment module for Prestashop (Canada only) - Fri Sep 03, 2010

For those looking for a potential shopping cart Prestashop is a cleanly written and actively supported codebase which is a compelling alternative to the other FOSS cart options. From this programmer's point of view it is the nicest internally and generally much easier to modify than other aging systems like osCommerce or Zen-Cart. However, being newer and originating from Europe means that Canadian merchant processors like Moneris are not supported out of the box either as a free or paid module.

To help with this situation I am making available the Moneris HPP (Hosted PayPage) module that I have written. This module allows shops to accept of payments using Merchant Processor Moneris' "Hosted PayPage" service. This module has been confirmed to work with Moneris Canada. The module is available free of charge but donations are also welcome if you feel like the module has helped you out.

Please note that this module DOES NOT WORK WITH THE US MONERIS service. For whatever silly reason, the US Moneris uses a different API which is similar functionally but requires different variables and only supports a single return URL. If you would like me to write a payment module for the US service, drop me a note for a quote.

The module also will work with Prestashop 1.4 if you add an include for "init.php" to the top of "order-confirmation.php". Remove the two existing include lines and replace them with:

require(dirname(__FILE__).'/../../config/config.inc.php');
require (_PS_ROOT_DIR_.'/init.php');
require(dirname(__FILE__).'/monerishpp.php');

If you require support or want assistance with integration then my normal consultation rates apply (contact me for a quote).

Download Moneris HPP Payment Module For Prestashop (tested with Prestashop 1.3.1)

As an aside, this module has also been submitted to the Prestastore site but as the approval process is taking inordinately long, I am posting locally here in case anyone needs to get a Moneris site rolling and cannot wait.

the joys of disabling Javascript - Mon May 31, 2010

I suppose that I am paranoid by nature, at least with respects to web technologies. Javascript for example is obviously a powerful, feature friendly way of creating dynamic content but the idea of client side scripting that is not under the user's control has always made me a little nervous (the vast majority of browser exploits rely on it for example). So my default browsing environment is with ads blocked and Javascript disabled.

More and more these days I am seeing artifacts of new school web designers either confusing or forgetting that client side is not under their control and that not everyone (or every thing such as the plethora of bots out there) sees the world through rosy Javascript coloured glasses. Take the NHL's web designers for a Javascript-less ride and we get this:

nhl.com with Javascript disabled

What's in the red circle? Let us take a look:

nhl.com with Javascript disabled says "values were inserted here in example"
//values were inserted here in example

It is hard to tell whether someone was taking "copy and paste" too literally or whether a 3rd party is injecting content they should not be but none the less, it makes for an amusing and informative Google search.

The obvious lesson is do not forget to test your code with Javascript disabled because at the very least Google will.

The hunt for a Linux friendly MP3 player: Philips GoGear Muse - Tue Jan 05, 2010

Linux has been my primary desktop OS now for close to a decade, originally via Gentoo but for the last while now I have been sticking with the less attention demanding Kubuntu. As pleasant as the Linux experience generally is, one unfortunate downside is that the two most prevalent MP3 players out there require proprietary software to use - there is no iTunes or Windows Media Player available for Linux. This forced vendor lock-in immediately takes the iPod and Zune out the running when looking for a new device to help you rock some tracks while out and about.

When looking for cross platform media players, the magic acronym you want to hear is "MSC" (Mass Storage Class) which means that the drive will be mountable as a standard removable drive. "MTP" (Media Transfer Protocol) can be hit or miss due to lack of standardization so has less chance of working. An article over at the venerable British tech rag The Register suggested that the Philips GoGear Muse had decent support for MSC mode and should be a suitable option for those running Linux.

Now I was fairly late to the PMP (portable media player) party so my first device was a 16GB Sansa View. Forgotten and unsupported by the manufacturer with terribly written firmware (OS crashes, bugs, poor power management, you name it), the View should be the textbook example of how not to implement an MP3 player. I cannot speak for Sansa's other products but I for one will never buy another MP3 player from them. But hey, at least I now have a low water mark to compare against.

With my frustration with the View finally bubbling over and a need for a reliable player, I wandered down to the local Future Shop outlet and picked up a 16GB Muse for $100 CAN (plus taxes).

Note: this review is an ongoing project.

My main uses for the Muse are feeding music to a PA for in between performances, fuelling a small portable PA for group bike rides and for listening to music before going to sleep via the RCA ins of a small ghetto blaster. For these uses this player has performed well enough that I am not seeking a replacement.

For a hundred clams (at least in my town) your MP3 options are often fairly limited. The Muse is not perfect but for that price of entry I can recommend it to those looking for a Linux friendly player who do not require a loud audio output. If the Muse could generate a better volume level and if the random play was less prone to repetition my prognosis would be glowing. As it stands, this player has given me my money's worth and I will definitely consider Philips when I need a replacement.

Pros

  • on device playlist support
  • good format support including OGGbattery life is usable
  • nice display
  • standard mini USB connector
  • on device database generation handles missing ID3 tags gracefully
  • mounts in MSC mode with Kubuntu 9.* and 10.*
  • sleep timer

Cons

  • "random" play is not as random as it should be
  • rather anemic output level (volume much too low)
  • lack of a compressor (volume limit helps but aggravates the already low output volume
  • occasionally does not seem to shut down properly
  • long boot up time
  • device does not currently work with Amaraok 2.*
  • sleep timer rudely cuts off which can cause audible glitching instead of fading out gracefully

topics: review

blog

CODEgrunt consulting

Experienced PHP web developer.

$35 an hour, no job too small.

There is no replacement for integrity and experience.

Contact me for more information.

calendar

May 2012

Sun
Mon
Tue
Wed
Thu
Fri
Sat
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2