Archive for June, 2013

Magento Staging Setup Accessing Live Database with SSL Certificate

Saturday, June 22nd, 2013

With a recent project, we needed to get the Magento staging environment on the same server and accessing the same database as the live environment.  There was lots of setup, product adjusting, etc. that needed to be done, and the client didn’t want to have to do it twice.

Setting up the staging environment was fairly straightforward, thanks to the excellent article over at Mag Life.  However, the article didn’t quite get the job done.

The live site, like all good live ecommerce sites should, was using an SSL certificate to provide a secure connection.  However, the SSL was for a fully qualified domain name ( and the staging site was on a subdomain (  Because the SSL settings are in the database, every time we attempted to hit a secure page, the dev site would no longer load, and instead would attempt to load the live site again.

Additionally, I felt lazy and didn’t want to set up server environment variables like the article at Mag Life, so I made a few other alterations to the code.

When attempting to set this up, follow the directions over at Mag Life, but utilize this code in your Store.php file:

class Alphachannel_Core_Model_Store extends Mage_Core_Model_Store

     *  This function is modified per the Mag Life article.
     *  With one modification to avoid setting server environment variables
    public function getBaseUrl($type=self::URL_TYPE_LINK, $secure=null)
    	// This is the lazy bit.  Rather than setting 
        // environment variables, just set the url's here
    	$urls = array(""=>"");
        $store_code = $this->getCode();
        $url = parent::getBaseUrl($type, $secure);
        // Several nested ifs are removed from Mag Life version 
        // that deal with the environment variables
        $host = parse_url($url, PHP_URL_HOST);
        if (isset($urls[$host]))
            $url = str_replace('://'.$host.'/', '://'.$urls[$host].'/', $url);
            $url = str_replace("https:", "http:", $url);
        return $url;

     * This is the same function as the core files, with one 
     * minor alteration to prevent https redirects
    public function isCurrentlySecure()
        $standardRule = !empty($_SERVER['HTTPS']) && 'off' != $_SERVER['HTTPS'];
        $offloaderHeader = trim(Mage::getStoreConfig('web/secure/offloader_header'));

        if ((!empty($offloaderHeader) && !empty($_SERVER[$offloaderHeader])) || $standardRule) {
            return true;

        if (Mage::isInstalled()) {
            $secureBaseUrl = Mage::getStoreConfig('web/secure/base_route_url');
            if ( ! $secureBaseUrl) 
                // Here's our hack.  Lie to tell it is secure!
            	return true;
                return false;
            $uri = Zend_Uri::factory($secureBaseUrl);
            $isSecure = ($uri->getScheme() == 'https' )
                && isset($_SERVER['SERVER_PORT'])
                && ($uri->getPort() == $_SERVER['SERVER_PORT']);
            return $isSecure;
        } else {
            $isSecure = isset($_SERVER['SERVER_PORT']) && (443 == $_SERVER['SERVER_PORT']);
            return $isSecure;

And, for a little icing on this cake, check out the simple debugging script I whipped up that made it fast and easy to trace back which class / method is calling the current function: Get the calling function or class method

Conversion Rates – What is Your Site’s Job?

Wednesday, June 19th, 2013

We focus on conversion rate optimization with our clients.  We want the site to be effective at it’s job, and the best measure of that is to measure how often a visitor “converts”.

When you are building a site, it is important that you decide – up front – the job of your site.  Part of defining that is deciding what a “conversion” looks like for your site.  After all, in order to improve conversion rates, you need to first measure conversions.  And to measure conversions, you need to be able to describe what a conversion is for your site.

For an e-commerce site, that’s simple: a conversion is when someone purchases.  Maybe there’s a secondary, lower priority conversion of signing up for a newsletter, but the primary conversion is clearly for someone to purchase.

For other sites, it may be less obvious.  Maybe it’s completing a “Contact Us” form, maybe it’s signing up for a survey, maybe it’s something else.

And for other sites, there may be several different conversion objectives.  In a discussion with a non-profit client recently, it became clear that they had many potential conversions.  I suspect when we are done identifying them, we will end up with a list of somewhere between 8 and 12 different conversions.

It’s not until you’ve identified what a conversion means that you can then structure your pages to be effective.  Each page has a job, and that job should be to help move the visitor towards one of your conversions.  See how it would be difficult to design a page without knowing what it’s job is?

Once you’ve defined your conversions, you can then use Google Analytics to track conversions, and to calculate (quickly and easily) the conversion rate for each and every one of your conversions.  Then, using Google Analytic’s tools, you can see where people are bouncing, where they are maybe getting stuck in loops, or where you are losing them in the conversion process.

Get the Calling Function or Class Method

Wednesday, June 19th, 2013

During a recent Magento project, I needed to get the calling class and method from a class that was being called multiple times. Due to the construction of Magento, the simplest way would be to use php’s debug_backtrace function. However, in this case when it was output there were over 82,000 lines of debug information. All I was concerned with was the calling function and class, so trying to wade through all of that information was rather overwhelming.

So, I whipped up this little function that takes care of things quite nicely, even formatting the output in the standard class->method structure:

        foreach($callers as $call) {
        	echo "
" . $call['class'] . '->' . $call['function']; }

Integrating LimeSurvey

Monday, June 3rd, 2013

Our first foray into the world of LimeSurvey, we’ve discovered the power and flexibility it offers.  With an easy theme system, and powerful options for creating useful surveys, we like it so far.  And, for a free, Open Source package, it sure packs a lot of power.