Author Archives: admin

Magento 1.6: Fix Missing Submit Shipment Button

If you have installed Magento 1.6 or upgraded to Magento 1.6, and if you click on the Ship button on the order page in the back-end, the Submit Shipment button at the bottom right may be missing. Only an empty yellow box will be displayed.

To fix this, copy app/code/core/Mage/Sales/Model/Order.php to app/code/local/Mage/Sales/Model/Order.php (because you never, ever, want to be editing Magento core files). Open up the local Order.php, on line 1218-ish, you will find:

$shippingMethod = parent::getShippingMethod();

Change it to:

$shippingMethod = $this->getData('shipping_method');

For possible reasons on why this is happening in the first place, see the Magento boards.

Fixing Contact Form 7 Redirection Referrer Failure with IE

On a client WordPress site, we wanted to use Contact Form 7 to grab visitor information and redirect them to an inner page after submission. To make sure they filled out the submission form, the destination page checked the referrer to make sure they came from the form page. Now, there are other ways of doing this, like setting cookies, but this method was good enough for the client.

So this all worked in Chrome and Firefox, but not Internet Explorer.

Shocking.

The Contact Form 7 blog has instructions on how to redirect users to a different page after a successful submission. Under Additional Settings, simply do this:

on_sent_ok: "location='http://www.fubar.com/thanks';"

The on_sent_ok is a Javascript hook. Inside of scripts.js in the plugin, it eventually makes this call:

if (data.onSentOk)
    $.each(data.onSentOk, function(i, n) { eval(n) });

So “location=’http://www.fubar.com/thanks’;” gets evaluated by Javascript and the page redirects. Great.

On the destination page, we were checking the referrer to verify they were coming from the form, here is an example of how you could do it:

/* Set where they should be redirected to if user didn't come from the form */
$redirectString = "Location: ". get_site_url() . "/contactform";

$referrer = $_SERVER['HTTP_REFERER'];

if ($referrer == NULL)
{
        header($redirectString);
        exit();
}
else
{
        $domain = parse_url($referrer);
        $pos = strpos ($domain["path"], "contactform");
        if ($pos == false)
        {
                header($redirectString);
                exit();
        }
}

Now, your PHP should be cleaner, more error checking, check for XSS, don’t hard-code anything, etc, etc.

The problem was that the referrer would always be null when the visitor was using Internet Explorer. Referrer isn’t required to be set by the browser. Browsers won’t set it if you started out on a HTTPS site but click on a non-secure link.

And IE won’t set it on redirection, but it will set it if you click on a link. So if a fake a link click, IE will set the referrer.

Lets create a Javascript function to fake a link click. This code is stolen from Stack Overflow:

function goTo(url)
{
    var a = document.createElement("a");
    if (a.click)
    {
        // HTML5 browsers and IE support click() on <a>, early FF does not.
        a.setAttribute("href", url);
        a.style.display = "none";
        document.body.appendChild(a);
        a.click();
    } else {
        // Early FF can, however, use this usual method
        // where IE cannot with secure links.
        window.location = url;
    }
}

Ok. Remember, the Contact Form 7 redirection is a Javascript hook. So now we change the on_sent_ok to call the goTo function instead:

on_sent_ok: "goTo('http://www.fubar.com/thanks');"

Bam. Done.

Nick Cast Episode 24 – iPad vs Books #volomo11

Trying to figure out if I should take the iPad on our safari, or just a few books. And wondering if Chloe will scratch me.

Nick Cast Episode 23 – Packing…Or Not #volomo11

Progress on packing for Kenya and Turkey. Only 5 days to go!

Nick Cast Episode 22 – The Verge and Carne Asada Burritos #volomo11

Quick review of the technology site called The Verge. The best carne asada burrito I had ever. From El Taco Valez.

Nick Cast Episode 21 – Sushi and Zoe’s Kitchen #vlomo11

Had some nice sushi and stopped by Zoe’s Kitchen for a Gruben. Also, #vlomo11 kicks off even though I forgot to talk about.

Nick Cast Episode 20 – Passport Stamps

Recently got my passport renewed. Going over some of the passport stamps in the old one: China, Jamaica, Mexico, Czech Republic, Spain, and Canada.

Nick Cast Episode 19 Halloween Pumpkins, Shaving, and PhotoFunia

Our scary plastic halloween pumpkin, I finally get around to shaving, and a pic using the iPhone app PhotoFunia.

Nick Cast Episode 18 – Back to Vlogging

Getting back into vlogging. Discussing our upcoming trip to Kenya and Turkey.

Magento + Prototype.js + New Window + PDF Links

Prototype.jsThis is relatively straightforward to do, but I’m posting it so I have the Javascript next time I need it. On a Magento client site, all PDFs needed to be opened in a new window. Why? No clue. The Magento template wasn’t doing anything fancy, it was simply using the standard Magento Prototype.js library. Not having used Prototype.js in a long time, it took me a while to figure out the function calls to set the target attribute on all PDFs links to _blank, but here it is:

document.observe("dom:loaded", function() {

    $$('a[href!=""]').each(function(link){
        if(link.readAttribute('href').toLowerCase().include('.pdf')) {
            link.writeAttribute('target','_blank');
        }
    });
});

This is pretty much self-explanatory, but I’ll go through it anyway. document.observe(“dom:loaded”) is the jQuery equivalent of $(document).ready. readAttribute is like jQuery.attr(), include is like a Javascript IndexOf.

Thats pretty much it.

Atlanta Lions Club
Atlanta Web Design