Export Excel CSVs with double quotes

This is a necessary evil for anyone who is working with CSV files manipulating them for data import to Magento (when XML is not suitable). Add the following function (sub routine) to Excel and hit the Macro button to run it. You’ll have no more failed Magento imports with this handy function. Sub subExportCSV() On Error GoTo subexport_exit Dim strDelimiter As String strDelimiter = "," Dim strQualifier As String strQualifier = """" Dim arrRng arrRng = ActiveSheet.UsedRange.Value Dim f As String Dim i As Long Dim j As Long Dim strTemp As String f = InputBox("Enter a filename for saving", , "c:test.csv") If Trim(f) = "" Then Exit Sub Open f For Output As #1 For i = 1 To UBound(arrRng, 1) strTemp = "" For j = 1 To UBound(arrRng, 2) strTemp = strTemp & strQualifier & arrRng(i, j) & strQualifier & strDelimiter Next j Print #1, Left(strTemp, Len(strTemp) … Continue reading

Quick script to export Magento categories with IDs

If you are after a quick method to get all the category ID’s for your categories for some Excel lookups (for new data imports), then this quick PHP script should help you out: <?php define(‘MAGENTO’, realpath(dirname(__FILE__))); require_once MAGENTO . ‘/app/Mage.php’; Mage::app(); $category = Mage::getModel ( ‘catalog/category’ ); $tree = $category->getTreeModel (); $tree->load (); $ids = $tree->getCollection ()->getAllIds (); if ($ids) { $file = "var/import/catwithid.csv"; file_put_contents($file,"catId, catNamen"); foreach ( $ids as $id ) { $string = $id . ‘, ‘ .$category->load($id)->getName() . "n"; file_put_contents($file,$string,FILE_APPEND); } } Simply save the above code in a PHP file in the base Magento directory of your store, and visit the URL in your web browser, simples!

Speeding up the Magento admin

I’ve noticed a few people discussing this issue on the Magento Commerce forum, so it might be worthwhile for us to offer a level of assistance (other than the fast Magento hosting we provide already from sonassi hosting). Downloading the following file, SlowManageCategories.zip patch. Extract the zip file and copy Sonassi_All.xml to your ./app/etc/modules/ directory. Copy the SlowManageCategories directory to ./app/code/local/ directory. SlowManageCategories patch

Random redirect to homepage with Magento

This issue has bobbed its head a few times in various different ways. The example is that a user reaches checkout, my account or an equally session critical area, but instead of reaching the selected page, they are redirected to the homepage. This can be a conversion killer as usually the bug appears most notably on checkout. There can be a few reasons for this, however, we have found the two most common are: 1. Missing Com.php class This is very common and a peculiar “bug” as it isn’t in the strictest sense. The file is required by the Zend library, but isn’t present with Magento’s default installation. Thankfully, this is a quick fix. Com.php should be in ./lib/Zend/Validate/Hostname/Com.php. You can easily create it by copying ./lib/Zend/Validate/Hostname/De.php to ./lib/Zend/Validate/Hostname/Com.php and editing the file contents, so the class name is: class Zend_Validate_Hostname_Com implements Zend_Validate_Hostname_Interface Or use the whole file contents shown … Continue reading

Migrate a Magento store without SSH access

We were recently asked to migrate a store to our Sonassi Hosting platform, but the client did not have SSH access to his previous hosting account. So we quickly knocked up a script to take care of the backup process <?php $db_host = ""; $db_name = ""; $db_username = ""; $db_password = ""; // Backup database shell_exec("/usr/bin/mysqldump -h ".$db_host." -u ".$db_username." -p".$db_password." > ".$db_name.".sql &"); // Backup entire site shell_exec("/usr/bin/tar cfz ".$_SERVER['HTTP_HOST'].".tar.gz –exclude=./".$_SERVER['HTTP_HOST'].".tar.gz –exclude=./var/session".$_SERVER['HTTP_HOST']." –exclude=./var/cache".$_SERVER['HTTP_HOST']." ".$_SERVER['DOCUMENT_ROOT']." &"); ?> We carried out the restoration via SSH, but you could also have a PHP script take care of that too: <?php $db_host = ""; $db_name = ""; $db_username = ""; $db_password = ""; // Only set these if you are changing your domain name $old_domain = ""; $new_domain = ""; // Restore entire site shell_exec("/usr/bin/tar xfz ".$_SERVER['HTTP_HOST'].".tar.gz ".$_SERVER['DOCUMENT_ROOT']); if (!empty($old_domain) && !empty($new_domain)) { $sql = &file_get_contents($db_name.".sql"); file_put_contents($db_name.".sql.bak",$sql); $sql = str_replace($old_domain,$new_domain,$sql) file_put_contents($db_name.".sql",$sql); } … Continue reading