Crud for code igniter

Code igniter is a popular php development framework that comes with basic functions for database management and is the basis foundation for a few projects that perform database records CRUD (create Read update Delete) functions

  • is a lightweight but efficient database CRUD solution, that offers a lot of useful implementations straight out of the box : 
    • flexi grid tables
    • automatic wysiwyg editor
    • ajax enabled swf file upload field
    • 1 to n and n to  n  relation ship
    • callback enables you to define extra behaviour for a lot of events : add record, modify, delete..

Magento : programmatically add custom options for products

I've found plenty of places on magento forums and websites that mention adding custom options to products : none of them seemed to work on my installation (1.5) so I suppose each version has its own tweaks. The technique below catches a specific event that is fired when the product is being saved from the admin. A good tutorial on Magento events can be found here, pseudo official list of events can also be found on Magento's wiki, probably outdated though. What I need now is to find the appropriate code to delete options from a product. not simple either... Anyone tried?

The way I did is the following

  • create a custom module PoleOuest_CustomOptions_Model_Observer 

     class PoleOuest_CustomOptions_Model_Observer
          public function Add_CustomOptions_Automatically($observer) {
                $event = $observer->getEvent();
        $product = $event->getProduct();
       // if ($product->getDecodirect())
         //   {
            $optionData = array(
      'is_delete'         => 0,
        'is_require'        => false,
        'previous_group'    => '',
        'title'             => 'want to preorder ? ',
        'type'              => 'checkbox',
        'price_type'        => 'fixed',
        'price'             => '20.0000',
        'sort_order'        => 0,
               'values'            => array(
                'is_delete'     => 0,
                'title'         => 'preorder',
                'price_type'    => 'percent',
                'price'         => -20,
                'sku'           => 'product sku',
                'option_type_id'=> -1,
           $opt = Mage::getModel('catalog/product_option');
                   Mage::log("option should be added now");
         // }
  • catch product save before event in app/local/PoleOuest/CustomOptions/etc/config.xml
    <?xml version="1.0" encoding="utf-8"?>

Mapress pro : use taxonomies to generate maps

Mappress pro, a plugin for wordpress, is worth its price : it can automatically create maps from custom fields adresses. I needed the possibility to create maps from a specific taxonomy, and this requires some hacking. here's the way to go for serious coders who want, like me, to spend one  intense hour . hope mappress pro incorporates that for future buyers !!

FIRST STEP : create a new configuration option for mappress to specify the custom taxonomy

  • in mappress.php
add_setting_field('customTaxonomyMap', __("Custom Taxonomy", 'mappress'), array(&this, 'setTaxonomy'), 'mappress', 'mappress_pro_settings'));
function set_custom_taxonomy_map() {
$options = Mappress_Options::get();
$pro_link = "<a href='' title='MapPress Pro'>MapPress Pro</a>";
printf(__("This setting requires %s.  Automatically create maps from custom taxonomy.", 'mappress'), $pro_link);
in mappress_pro.php
  • function set_custom_taxonomy_map()
    {        $options = Mappress_Options::get();
        echo __(" Update map when terms are added to a post in the following taxonomy  ", "mappress");
            echo "<input type='text' size='30' name='mappress_options[customTaxonomyMap]' value='"  . $options->customTaxonomyMap. "'/>";}
  • and in mappress_api, don't forget to declare your new option as class variable of Mappress_Options

SECOND STEP : implement action hooks to create the map when the post is saved

  • in mappress_pro.php, function Mappress_Pro()
            if ($options->customTaxonomyMap) {
                    add_action('deleted_term_relationships', array(&$this, 'term_delete'), 10, 4);
                    add_action('added_term_relationship', array(&$this, 'term_added'), 10, 4);
  • and
     function getTaxonomyMapKey($taxonomy)
          return "tax" . $taxonomy;
    function term_added($postid, $termId) // poleouest
         $options = Mappress_Options::get();
        $this->term_delete($postid, $termId);
        $terms=get_the_terms( $postid, $taxonomy );
          foreach( $terms as $term ) {
        if ($city!="")
        {$atts = array("address" => $city);
        $atts = $this->scrub_atts($atts);
       $poi = new Mappress_Poi($atts);
       $result = $poi->geocode(true);
       $pois[] = $poi;
        $map = new Mappress_Map();
            // Update with new POIs
            $map->update(array('pois' => $pois, 'title' => $city, 'metaKey' =>$mapMetaKey, 'center' => array('lat' => 0, 'lng' => 0)));
    function term_delete($postid, $termId) // poleouest
         $options = Mappress_Options::get();
         $map = Mappress_Map::get_post_map($postid, null, $mapMetaKey);
       if ($map)  $map->delete();

ixedit : Jquery development without coding

IxEdit is a JavaScript-based interaction design tool for the web taht gives designers and developers a few ready to use jquery tools, such as animation, form enhancements (date picker), and DOM manipulation, all designed within a web based interface. It uses GEARS, a tool developed by google that interfaces browsers with desktop, and the only requirement to start working on a web page is to include the ixedit javascript, plus the jquery libraries.

Jquery drop down menu, named mega

I usually take superfish for granted when working on a jquery based drop down menu : based on regular ul / li tags, it uses CSS layout directives to position menu items, which I have tried up to 3 levels of navigation. I have just found another good example of submenu implementation that demonstrates the ability to write paragraphs inside the sub layer, as  shown in the illustration below. The tutorial written by Jon Philipps on The Web Squeeze explains how CSS3 manages to implement rounded corners while jquery deals with the drop down effect. Nothing really new, just another way of working with Jquery and layers, but nice.


Form builders : getting hot

A few months ago I published a quick comparison of 3 opensource cmses that come with a form builder. At the time the form builder feature was quite new and innovative, it now comes as a standard feature in a lot of web publishing solutions. I have reviewed a few hosted form makers, such as

They all have very nice interfaces including data gathering and statistics but the one I loved best was MachForm that is also distributed as a standalone application fro a very reasonable price. It uses Jquery as the main javascript library and lets the user build forms using drag and drop. One good idea is the composite field that lets the user add adresse field in one click. The screenshot below displays my own translation of the admin interface to french.


Magento : display product image on invoice + shipping PDF

Magento's wiki has a few articles on the subject of Magento's PDF generation, which is not very efficient in its default version : one of the main critics I've seen is the size of the generated PDF, which can fly to more than 1MB, where a simple font replacement can bring the weight to less than a few KBs ! The subject of the article below is to illustrate how to display images on each line of the generated invoice and shipping PDF.
The product line display occurs in specific PHP classes within  the app/code/core/Mage/sales/Model/order/pdf folder

there is one folder for shipment, one for invoice, and one for credit. The product display occurs in the DEfault file where the Mage_Sales_Model_Order_Pdf_Items_Abstract is defined. What I did was simply instanciate a product object using the id from order / items, and get the image file using the following code in the draw function :

//<display image>
$id = Mage::getModel('catalog/product')->getIdBySku($this->getSku($item));
$product=  Mage::getModel('catalog/product')->load($id);
$imageUrl = $product->getSmallImageUrl();
$imageFile=  str_replace(Mage::getBaseUrl('media'),"media/",$imageUrl);
// $page->drawText($imageFile , 65, $pdf->y-$shift{1}, 'UTF-8');
$imageWidth = 100; $imageHeight = 50;
$image = Zend_Pdf_Image::imageWithPath($imageFile,$imageWidth,$imageHeight);
$y=$pdf->y - $imageHeight /3;
$page->drawImage($image, 35,$y, 35+ $imageWidth / 2, $y + $imageHeight/2);
//</display image>

Magento one page checkout : display shopping cart details in sidebar


There are a lot of discussions going on about Magento's one page checkout procedure : it is supposed to enhance customer payment experience by probviding ajax based single page order progress. But there are alos some discussions in the forum on how to enhance this process which is quite unusual and might discourage some customers. In a previous post I reviewed the code that produces sidebar shopping cart in default pages with right margin. The solution below explains how to add a full shopping cart display for the customer's that trying to complete an order.

Read more

Weekly news : ZF 1.8, EXTJS 3, Magento enterprise

This month has been full of releases. Zend Framework is reaching V1.8 featuring the new Zend_Application interface that instantiantes a preconfigured bootstrap when used via the Zend Tool generator (tutorial here in french). EXT JS, the popular and controversial semi commercial javscript library has reached a new milestone with a 3PR1 release. We've already mentioned Tine20, a new version is out but you want to keep that link where the developers publish a tutorial that explains how to combine EXT JS with Zend Framework.  On the Magento side, version 1.3.1 is out, should fix a lot of bugs but more importantly is the fact that Magento has finally annouced the release of an enterprise edition that starts at 8900$ per server. Nice to know that the company behind the most popular opensource ecommerce application is going to make money on a business model that proves to encourage customers and technicians to adopt this solution for long term development. Redhat did it and it's still around with the FEDORA that's developped independently. Let's hope some features annouced for Magento enterprise will come one day to the opensource product as affordable extensions : Administrator Permission Roles on Website and Store Levels, Private Sales including Events, Invitations and Category access permissions, Category View and Purchase permissions per on customer group , Gift Certificates/Cards are among features that certainly justify some financial investment. Currently we have the Customer Groups Configurable Catalog extension , but obviously you'd have to test that before going ahead in production.

ajaXplorer vs extplorer vs ajax file manager


We've not covered PHP based file explorers yet : they are indeed an essential component of any serious web application. When Ajax comes in the game, browsing, uploading and dealing with files is as easy online as it can be on your desktop. Thos willing to develop might be interested in extjs grid views, while application developpers looking for a working and bug free component have the choice of two or three opensource components available. All of them have the following features

  • access control
  • flash based and  / or FTP upload for big files 
  • file viewing / previewing
  • drag and drop folders

The choice is rought. For integration into a Wysiwyg editor such as FCKEDitor, we preferred the  Ajax file manager from PHPLetter because it is light and does not come with a huge infrastructure. For a quick access to web based files, we prefered ExtPLorer because the interface is based on the famous ext js library. As a new challenger on this area, ajaXplorer comes with a nice polished layout (picture above), a MP3 player (DEWPLayer) and a FLV player. But lacks translation into most languages.

Magento custom attributes display on product page

The flexibility created by the attribute feature in Magento allows limitless possibilities : vairous product types can be created and each of them can go with specific attributes, meaning specific form fields for the admin, that are inserted in the product view (template/product/view.phtml) for public display. The functions availble for each user defined attributes are very simple to guess : they are dynamically created for each attribute create using , as explained in the Pratthost developer zone blog...
Read more

Magento Specials prices

There is a feature that prsetashop comes with in its default installation, that is cruelly missing in Magento : the ability to display specials on the website, either on the margin of the home page and category pages, or inside a specifi page. But as always, there are already many discussions going on about this subject, and a community extension has been released, does the job fine but the whole subject  needs more investigation.

  • The Catalog Sale Item community extension comes with its own xml layout page,  phtml design template, and Mage_Catalog_Block_Layer_View / Mage_Core_Block_Template class extensions. It creates a new page that displays all products currently on sale.
  • Activecodeline publishes some code that extends the product list view to enable sorting products by specials price.
  • Inchoo publishes an alternative category list view that displays only products in promotion or with special price, to be selecetd from the category / custom design menu.
  • Magento's forum has a dedicated "special price products" discussion that exlains how to use the product collection with specific query attributes to select only proucts with special price.

Magento CMS : 2 methods for static blocks

Magento's backoffice comes with a fairly simple CMS that can do a lot : single pages can be modified (content and layout) via the CMS / Manage Pages menu, and page parts can be shared and modified via the CMS / Static Block menu. Web developers who get a first sight inside templates might find it difficult to integrate a newly created block : we describe here two methods to integrate a block in your magento website.

How to create a CMS block : Go to Magento admin uder CMS -> Static Blocks and Add New Block. Insert Block Title, Identifier (for example: mycompany-newsblock), set Status to Enabled, insert block Content and Save Block.

How to add the CMS block to pages (exemple on the right column). You can choose one of these 2 methods

  1. LAYOUT block  modification: in layout/page.xml , find the default / right column block
    <block type="core/text_list" name="right" as="right" />

    and transform it by incorporating the newly created CMS block  :
    <block type="core/text_list" name="right" as="right">
    <block type="cms/block" name="ruedesiam.marge" as="ruedesiam.marge" after="-">
    <action method="setBlockId"><block_id>mycompany-newsblock</block_id></action>
  2. Template block addition : add the following code to

    <?= $this->getLayout()->createBlock('cms/block')->setBlockId('mycompany-newsblock')->toHtml() ?>

The solutionbelow explains how to add a template block : everything here is done via HTML files. (example for theleft column)

1. in layout/page.xml or in your page custom design, add the following code

<reference name="left">
<block type="core/template" name="productbrand" alias="productbrand" as="productbrand" template="catalog/product/brand.phtml"  />

2. in template/callouts/ left_col.phtml, add the following :

<? $this->getChildHtml('productbrand') ?>

Note : you can avoid xml configuration by creating the core template directly within the phtml :

 <?php  echo $this->getLayout()->createBlock('core/template')->setTemplate('callouts/rassure.phtml')->toHtml() ?>

<?php  echo $this->getLayout()->createBlock('core/template')->setTemplate('callouts/rassure.phtml')->toHtml() ?>

Magento Extension : Category product tab edit link


PoleOuest_CategoryProductEditLink Magento extension is a lightweight magento backend extension that allows store managers to edit products straight from the category admin page.

2012 update : This extension is compatible with all versions of MAGENTO community up to 1.6 

Browsing products by category in the admin : there are many examples of opensource ecommerce systems that can do that. Among them, Prestashop backoffice is built around this navigation paradigm, and even Oscommerce  displays products by category in its 5 years old backoffice. Of course none of those two have the flexibility that Magento allows in terms of category / product association in a multistore environment.

But in Magento you can't search product by category in the admin : can you imagine that this feature is missing in Magento !  As of version 1.4 (and now tested on 1.5 and 1.6!!!) this is still the reality, easily enhanced by the PoleOuest_CategoryProductEditLink Magento (see the page on Magento website).



  1. Buy (29$ via Paypal) the extension on our shop
    Note : purchasing the extension gives you unlimited website license and full access to PHP Code
  2. Download (TGZ)
  4. unzip the file in your app/code/local, in order to get the structure below,
  5. create the xml module file PoleOuest_All.xmlin app/etc/modules with the following code :
    <?xml version="1.0"?>
  6. REMEMBER to flush magento's cache and log out / log in the admin
  7. go ahead, try it and let me know how to package this thing into a usable magento connect extension !


Magento How to : add prototype based image rollover

We will today work on a nice and easy fetaure of temlpate design : adding javascript and static images, with the objective of implementing a simple prototype based image rollover. We chose the simple unobstrusive rollover script by Herryanto Satiano.

  • download the zip and place the rollover.js file in your js/prototype folder (or in you js skin folder)
  • edit app/design/../layout/page.xml and add the following line in the header block :
    <action method="addJs"><script>prototype/rollover.js</script></action>
    Note that you can also add your javascript in your own magento skin via the following block action :
    <action method="addItem"><type>skin_js</type><name>js/prototype/rollover.js</name></action>
  • add the rollover instanciation in you rpage/head.phtml file :
      <script type="text/javascript">
        window.onload = function() {
          new Rollover('nav');
  • test on tow imagse with _over suffix.

WordPress Plugin Review : SEO all in one

The popular All-in-on SEO pack plugin for wordperss does more than just adding the essential meta fields to your articles and pages interfaces. For lazy writers, SEO pack will also create meta tags AUTOMATICALLY the content for these essential code addons that will boost your search engine positionning. A simple tag based configuration will allow you to set up categories, tag and archive pages optimisation via the TITLE tag, most important of all because it is the first thing visitors see when they look at search engines result pages.