home | contact us
» » June


My favourite IDE Netbeans has recently been released as version 6.7. Now installed and looking forward to taking advantage of some new features and fixes


 

I recently came across rgba colours which are a very simple and logical way to produce a colour (rgb) with alpha transparency as well. This is ideal if for example you want to create a translucent white box to put some text in.

CSS does have some (dodgy) opacity controls, but they set everything as transparent including any text or pictures contained within the element. By using rgba, we can set a translucent background colour and have opaque elements contained within.

As usual, to get it to work in IE requires some extra effort, however this hack mentioned here and originally credited here seems to offer a solution.


 

I have recently had the misfortune of stepping out of my usual developers bubble and having to do a bit of graphic web design. Of course that means that not only did I have to try to make something look good with my meagre design skills, but then I had to worry about making sure it worked in IE…

Web Designers… I FEEL YOUR PAIN

As I only use Ubuntu or Mac’s, testing in IE is not exactly easy. Or at least it wasn’t until I decided to take the plunge and set up XP as a virtual machine. It’s really really easy on Ubuntu.

1. Go to the Applications-Add / Remove system

2. type virtualbox in the searchbox

3. Install VirtualBox OSE

4. Go to the Applications-Accessories menu and launch VirtualBox OSE

5. Hit the blue New icon in the top left

6. Follow the wizard. I used the following settings:

6.a name: xp

6.b: memory: 192mb

7. At the boot disk stage, you need to hit the New button to create and install a new ‘boot disk’.

8. Whack your XP CD in the drive and install it.

By default the right hand ctrl key is your key for escaping out of your virtual machine. This means that if you click on your virtual machine with your mouse (for example to go through to multiple steps required to tell XP that you want English UK keyboard, and surprise surprise an English Keyboard layout and furthermore you don’t really need to install English US as a separate language)

Note – to access your Ubuntu environment you will need to have folder sharing set up, the virtual machine will see the host Ubuntu like another computer on a network.

If like me you need to edit the hosts file to point a dummy domain to your local development environment, the IP address you need to use is 10.0.2.2


 

This is a nice little script I just knocked together that helps to synchronise databases when the table structures might not be exactly the same (for example different versions of the same system).

You would need to edit the top section to put the correct DB credentials etc.

This is definitely not to be used on a live DB, purely for aiding development and migration.

<?php
/** Database Synchronisation / Migration Tool
 *
 * For synching up an old and a new DB schema.
 *
 * @author EdmondsCommerce.co.uk
 *
 */

//do you want the system to empty the new table before inserting data from the old table?
$truncate=true;

/**
 * DB Server Credentials - Needs to have full access to both databases
 */
$dbHost='localhost';
$dbUser='root';
$dbPass='password';

/** Tables to Synch
 */
$tablesToSynch = array(
    'categories',
    'categories_description',
    'products',
    'products_description',
    'products_to_categories',
    'manufacturers',
);

$dbOld = 'dbold';

$dbNew = 'dbnew';


/*********** CODE BELOW HERE - NO NEED TO EDIT UNLESS YOU WANT TO ***********/
$_conn = mysql_connect($dbHost,$dbUser,$dbPass) or die('DB Connection Failed');

$dbOldTables= fetch_tables($dbOld);

$dbNewTables = fetch_tables($dbNew);


foreach($tablesToSynch as $table){

    echo '<h3>Doing '.$table.'</h3>';
    //check for common tables
    if(in_array($table, $dbOldTables) && in_array($table, $dbNewTables)){
        //now get column data
        $dbOldTableCols = fetch_columns($dbOld,$table);

        $dbNewTableCols = fetch_columns($dbNew,$table);

        //now for the column comparison
        $cols=array_intersect($dbOldTableCols, $dbNewTableCols);

        //now emptying the new DB if set to do so
        if($truncate){
            db_query("TRUNCATE $dbNew.$table");
        }

        //copy old table to new DB so we can copy columns
        $tempTable=copy_table($dbOld, $dbNew, $table);

        //now build SQL and run
        $sql = "insert into $dbNew.$table (" . implode(', ',$cols) . ") select " . implode(', ',$cols) . " from $dbNew.$tempTable";
        db_query($sql);

        //now drop temp table
        db_query("DROP TABLE $dbNew.$tempTable");
    }
    
}

/****** FUNCTIONS ********/

function db_query($query){
$output = mysql_query($query) or die('
<h1 style="color: red">Uh Oh......MySQL Error:</h1>
<h3>Query:</h3>


		


<h3>MySQL Error:</h3>
' . mysql_error() . '
<hr /> <hr />');	return $output;
}


function fetch_tables($dbname){
    $query=db_query("show tables from $dbname");
    while($r=mysql_fetch_assoc($query)){
        $return[]=$r["Tables_in_$dbname"];
    }
    return $return;
}

function fetch_columns($dbname, $table){
    $query = db_query("SHOW COLUMNS from $dbname.$table");
    while($r= mysql_fetch_assoc($query)){
        $return[]=$r['Field'];
    }
    return $return;
}

function copy_table($fromDb, $toDb, $table){
    db_query("DROP TABLE IF EXISTS $toDb.temp_$table");
	db_query("CREATE TABLE $toDb.temp_$table LIKE $fromDb.$table");
	db_query("ALTER TABLE $toDb.temp_$table DISABLE KEYS");
	db_query("INSERT INTO $toDb.temp_$table SELECT * FROM $fromDb.$table");
	db_query("ALTER TABLE $toDb.temp_$table ENABLE KEYS");
    return "temp_$table";
}

 

This is as much a note to self plus anyone else googling for the words Ubuntu Jaunty and Filezilla

The version that’s in the repositories is a bit old and missing some cool features like synchronised browsing.

The latest version is available from GetDeb – http://www.getdeb.net/app/FileZilla

If you have already installed a version from the repos, totally remove it using syntaptic package manager. Then download the main filezilla package and the filezilla-common package from GetDeb. Install the filezilla-common package first and then the Filezilla package itself.

Sorted.


 

Had another tearing hair out moment when trying to figure out why my helper override was working fine, but my block override wasn’t working. Here is the result:

helper working, block not working:

<?xml version="1.0"?>
<config>
    <modules>
        <EC_CatalogSearch>
            <version>0.1.0</version>
        </EC_CatalogSearch>
    </modules>
    <global>
        <helpers>
            <catalogSearch>
                <rewrite>
                    <data>EC_CatalogSearch_Helper_Data</data>
                </rewrite>
            </catalogSearch>
        </helpers>
        <blocks>
            <catalogSearch>
                <rewrite>
                    <result>EC_CatalogSearch_Block_Result</result>
                </rewrite>
            </catalogSearch>
        </blocks>
    </global>
</config>

then after a load of messing about, this one does work:

helper and block both working

<?xml version="1.0"?>
<config>
    <modules>
        <EC_CatalogSearch>
            <version>0.1.0</version>
        </EC_CatalogSearch>
    </modules>
    <global>
        <helpers>
            <catalogSearch>
                <rewrite>
                    <data>EC_CatalogSearch_Helper_Data</data>
                </rewrite>
            </catalogSearch>
        </helpers>
        <blocks>
            <catalogsearch>
                <rewrite>
                    <result>EC_CatalogSearch_Block_Result</result>
                </rewrite>
            </catalogsearch>
        </blocks>
    </global>
</config>

yeah exactly :S


 

Recently spoke to a client about the possiblity of setting up Magento on EC2 and remembered that I had seen a pre optimised AMI including caching etc to hopefully run Magento well.

A quick bit of Googling though and I saw that the top results are all people charging for AMI’s.

That can’t be right, so I thought I would do a quick post to give the free optimsed AMI an SEO booster.

Debian Etch Linux Optimized for Magento:
Magento Optimised AMI for Amazon EC2


 

After a few hours of intense googling I have finally figured out why my Magento custom module is refusing to activate. I finally figured it out. It’s all because the snippet of XML that I copied and pasted off a tutorial somewhere did not have the right capitalisation.

doesn’t work – EC_All.xml

<?xml version="1.0"?>
<config>
    <modules>
        <EC_CatalogSearch>
            <active>true</active>
            <codepool>local</codepool>
        </EC_CatalogSearch>
    </modules>
</config>

does work – EC_All.xml

<?xml version="1.0"?>
<config>
    <modules>
        <EC_CatalogSearch>
            <active>true</active>
            <codePool>local</codePool>
        </EC_CatalogSearch>
    </modules>
</config>

I think next time I’m just going to use the module creator!


 

If you fancy having a select box allowing people to search within a top level category on your site directly from the quick search box, check out this little modification. This gives your search a bit of an Amazon feel. This idea could easily be extended if required.

You can drop this file in as a straight replacement to app/design/frontend/###/###/template/catalogsearch/form.mini.phtml

<?php
/**
 * Magento

 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 *
 *
 * @version Edmonds Commerce Quick Search with Top Level Categories
 *
 */

$category = Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
    $current_category_path=Mage::registry('current_category')->getPathIds();
}else{
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
foreach($children as $c){
    $selected = (in_array($c, $current_category_path))?'SELECTED':'';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
}
?>
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
    <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <div class="mini-search">
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
            <select name="cat" id="cat" class="input-text">
            <option value="">All Departments</option>
            <?= $extra_options ?>
           </select>
            <input type="submit" value="Go" style="border: 1px solid #808080;" alt="<?php echo $this->__('Search') ?>" />
            <div id="search_autocomplete" class="search-autocomplete"></div>
            <script type="text/javascript">
            //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('search site...') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
            //]]>
            </script>
        </div>
    </fieldset>
</form>


 

If you are trying to modify your mod_security configuration on a plesk server and have tried using htaccess files you have probably realised that it won’t work. That’s a good thing, it makes it harder for people to screw up your server by turning off this protection.

Instead the way to do it is to edit the vhost.conf file located in the conf folder in the domain / sub domain root (the folder containing the httpdocs folder).

You can apply any settings you want to this file and then run the following command to get Plesk to rebuild your httpd configuration including your new settings. This is working with Plesk the way it was intended to be used and is a better solution that the htaccess file approach.

The command to rebuild your Apache configuration when you make a change to the vhost.conf ssl_vhost.conf file is:

        /usr/local/psa/admin/bin/websrvmng -a -v

This rebuilds the configuration for ALL virtual hosts. It shouldn’t take more than a few seconds, obviously you then need to restart Apache.


 
rss icon