Howto: Resolve “Failed to Open File” error when installing Magneto Connect extensions

If you’re trying to install a Magento extension though Magento Connect and getting an error like the following:

CONNECT ERROR: Failed to open file /var/www/magento/downloader/.cache/community/OrganicInternet_SimpleConfigurableProducts-0.7.4/app/code/community/OrganicInternet/SimpleConfigurableProducts/Catalog/Model/Product/Type/Configurabl

It’s caused by a simple (yet long-lived and un-fixed) bug in Magento’s downloader.

Open:

/downloader\lib\Mage\Archive\Tar.php

Find:

if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
     $header['name'] = trim($header['name']);
     return $header;
}

Replace with:

if (!(trim($header['name']) == '././@LongLink' && $header['type'] == 'L')) {
     $header['name'] = trim($header['name']);
     return $header;
}

Then try to install your extension again. Always remember to disable the compiler before hand, clear caches, and log out of the admin after installing an extension.

Add customers to Magento newsletter via web form form

Recently I was tasked with adding customers to a Magento newsletter via a pre-exisitng form. Previously this form just sent an email that was mostly ignored, so now the ManInCharge wanted it feeding into Magento, which has several nice plugins for MailChimp integration, but that’s a story for another day.

Setup your form just like any other HTML text form, point it with a POST action at something like this:

$email = $_POST["email"];
if ($email){

# create new subscriber without send an confirmation email
Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);

# get just generated subscriber
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);

# change status to "subscribed" and save
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->save();
}

With some help from ifuelinteractive and paniticz