home | contact us
» » April


If you are migrating from an old ecommerce package into Magento, you may well want to extend Magento’s password hashing system so that it can understand the passwords that are hashed by the previous system and customers can log in using their old passwords without any hassle.

You would start off by overriding the Mage_Core_Model_Encryption class like so:

class EdmondsCommerce_LegacyPassword_Model_Encryption extends Mage_Core_Model_Encryption {

    /**
     * Validate hash against hashing method (with or without salt)
     * 
     * Extended to support the legacy password hashing of the previous system
     *
     * @param string $password
     * @param string $hash
     * @return bool
     * @throws Exception
     */
    public function validateHash($password, $hash) {
        if (/*password matches legacy pattern (as stored hash in DB)*/) {            
            // create a hash of the plain text password and compare to the stored hash
            return $hashed_pass == $hashval;
        }
        //default magento hashing from here
        return parent::validateHash($password, $hash);
    }

}

However, you will find that the standard model override does not work and you may start vigorous hair pulling at this point.

The answer though is that your override XML is actually fine, but it isn’t being used. This is because of the getEncryptor model in Mage_Core_Helper_Data creates the model using ‘new’ rather than getModel.

/**
     * @return Mage_Core_Model_Encryption
     */
    public function getEncryptor()
    {
        if ($this->_encryptor === null) {
            $encryptionModel = (string)Mage::getConfig()->getNode(self::XML_PATH_ENCRYPTION_MODEL);
            if ($encryptionModel) {
                $this->_encryptor = new $encryptionModel;
            } else {
                $this->_encryptor = Mage::getModel('core/encryption');
            }

            $this->_encryptor->setHelper($this);
        }
        return $this->_encryptor;
    }

The class name to use for the encryptor is stored in the config.xml for Mage_Core.

The solution here is to replicate this XML in your config.xml and also make your legacy module depend on Mage_Core so that it get loaded afterwards and can override the XML.

<?xml version="1.0"?>
<config>
    <modules>
        <EdmondsCommerce_LegacyPassword>
            <version>0.1.1</version>
            <depends>Mage_Core</depends>
        </EdmondsCommerce_LegacyPassword>
    </modules>
    <global>
        <models>
            <core>
                <rewrite>
                    <encryption>EdmondsCommerce_LegacyPassword_Model_Encryption</encryption>
                </rewrite>
            </core>
        </models>
        <helpers>
            <core>
                <encryption_model>EdmondsCommerce_LegacyPassword_Model_Encryption</encryption_model>
            </core>
        </helpers>
    </global>    
</config>

Easy once you understand. Another gotcha you have to look out for though!


 

If you have written your own modules, and need to rearrange the order that your attributes or displayed in, or change anything else, you can use the following SQL statements to fix their order.

First you need to get the attribute group that the attributes are under. This can be done by running the following
[mysql]
SELECT attribute_group_id, attribute_group_name FROM eav_attribute_group
[/mysql]

This will give all of the different tabs for categories as well as the products. Find the group ID that you need and then run the following command to see all of the attributes associated with it
[mysql]
SELECT eea.*, ea.attribute_code FROM eav_entity_attribute AS eea JOIN eav_attribute AS ea ON eea.attribute_id = ea.attribute_id WHERE eea.attribute_group_id = 4
[/mysql]

Here we are using the group_id of 4 which gives the following result

The sort_order is the attribute that you need to change to move the attributes around the page. If the sort order is sequential then a simple trick to add some padding is to run the following command
[mysql]
UPDATE eav_entity_attribute SET sort_order = (sort_order*10) WHERE attribute_group_id = 4;
[/mysql]

Which will multiple each sort order by 10 allowing you to move the attributes around easier.


 

If you are having performance issues with your Magento store and you are running on a dedicated or VPS server that you think should be up to the task of running your store properly but you continue to have performance problems then this post is for you.

Having decent server specification is only the first step on the road to having a high performance Magento store. Without proper configuration your server is not going to make the best use of its resources and that could make the difference of literally seconds or even tens of seconds of page load time.

The first and most important thing to check is that you are running a PHP opcode cacher such as APC. Opcode caching takes your PHP source code and compiles it to opcodes and then stores this in a cache. This opcode is actually what is run when people visit your store and the process of creating it, especially if you have a very large application with lots of file (like Magento), can be a real performance bottleneck. This problem is easily resolved by having APC installed and configured. If you are not sure, ring your hosting company and find out and if you don’t have it running, ask them to set it up for you.

The next thing to check is MySQL configuration. The standard MySQL configuration defaults were set when server hardware and memory was a tiny fraction of what it is today and that means that the configuration is generally way too sparse with allocation of memory for caching and other optimisations. Tweaking MySQL can be a little tricky, its definitely not something you should do if you are not sure, but it is well worth getting someone to optimise your MySQL configuration.

After that, the next major performance gain with Magento is to make proper use of block caching. Magento has a brilliant built in feature where every block (page section) can be cached so that next time someone visits the page, the logic used to generate that section of page (for example a best sellers list) does not have to be run, we simply redisplay the cached copy of that block’s HTML.

Beyond these three steps there are still many more things that can be done to improve the performance of your Magento store. If you would like professional help getting the best out of your server and Magento with a view to getting the lowest possible page load speeds then get in touch with Edmonds Commerce today.


 

If you would like to upgrade wordpress directly on the command line using bash then you might like this little script:

#!/bin/bash
# This is a script to upgrade wordpress.
# Put it in your wordpress document root (the folder that contains wp-config.php)
# chmod +x to make executable
# ./wp-upgrade.bash to run
# Originally here: http://yabfog.com/blog/2011/12/12/wordpress-update-bash-script
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMPDIR=/tmp/wp-upgrader
mkdir -p $TMPDIR
WPDIR=$TMPDIR/wordpress
mkdir -p $WPDIR
cd $TMPDIR
rm -rf latest.zip ./wordpress # Clean up from the last run
wget -nd http://wordpress.org/latest.zip
unzip latest.zip
mv $DIR/wp-config.php $DIR/.wp-config.php.backup # Stash your configuration someplace safe
rm $DIR/*.{txt,html,php} # Delete the old install
rm -rf $DIR/{wp-admin,wp-includes} # Delete more. Don't delete plugins or themes.
cp -aR $WPDIR/* $DIR/
mv $DIR/.wp-config.php.backup  $DIR/wp-config.php # Restore the configuration
# You may not need the last two lines. I like to give my web server the ability to write files.
#chown -R .www-data $DIR/*.php $DIR/wp-admin $DIR/wp-includes
#chmod -R g+w $DIR/*.php $DIR/wp-includes

Please don’t use on a live site or anything like that, but for local development its a quick way to upgrade the site.

The script was originally here I simply edited it a little


 

Today we and no doubt countless other Ubuntu 10.10 users got the dreaded:

You can read the official announcement here.
As everyone is aware, Ubuntu and Gnome have both moved towards a new desktop environment paradigm which is designed to be a bit more dumbed down and accessible to less technical users.

Unfortunately its not really suitable for power users who might have a LOT of open windows spread over multiple desktops and often running multiple monitors.

Gnome 2, simple as it was, has some really nice desktop features that once you are used to them it feels like you can’t live without them.

So now the big question is, what next?

We already have one Linux Mint fan in the office and it is looking like this project is going in the right kind of direction for us with their support for MATE (Gnome 2 basically) and also the Cinnamon desktop which is a more modern take on the classic Gnome 2 desktop paradigm. Its more than likely this is where we will be going to next.


 

If you find yourself typing away whilst something else loads or another window pops open and all of a sudden your typing has gone into a different window then this solution is for you

Open gconf-editor. Open a terminal and type gconf-editor and hit return.

Now navigate to /apps/compiz/general/screen0/options/focus_prevention_level key and set its value to 4.

That’s it.

You might actually decide that focus stealing is sometimes useful in which case you can always change it back.

Originally found here: http://askubuntu.com/a/55220


 

So one of our customer’s sites started throwing this error message immediately following an upgrade.
Illegal scheme supplied, only alphanumeric characters are permitted

Turns out 1.6.2.0 doesn’t like anything other than a-z and 0-9 in the store run code and the customer in question had underscores (_) in the store run code.

The simple fix was to strip it out and alter the url to store code logic to match.

Hope this helps someone else out there. As to why someone at magento thought this was a good idea is beyond me though.


 
rss icon