PHP Download Directory as Zip Archive

Want to download any directory and its content as zip file? Please use following code where we have used ZipArchive object.

// Get real path for our folder
		$rootPath = realpath($dir);		
 
		// Initialize archive object
		$zip = new ZipArchive();
 
		$archive = 'test.zip';		
		$res = $zip->open($archive, ZipArchive::CREATE);
 
		// Create recursive directory iterator
		/** @var SplFileInfo[] $files */
		$files = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator($rootPath),
			RecursiveIteratorIterator::LEAVES_ONLY
		);
 
		foreach ($files as $name => $file)
		{
			// Skip directories (they would be added automatically)
			if (!$file->isDir())
			{
				// Get real and relative path for current file
				$filePath = $file->getRealPath();
 
				$relativePath = substr($filePath, strlen($rootPath) + 1);
 
				// Add current file to archive
				$zip->addFile($filePath, $relativePath);
			}
		}
 
 
		// Zip archive will be created only after closing object
		$zip->close();
 
		header('Content-Type: application/zip');
		header('Content-disposition: attachment; filename='.$archive);
		header('Content-Length: '.filesize($archive));
		readfile($archive);
		unlink($archive);
		@set_time_limit(0);
		die();

Magento Version 1.9.1.0 Checkout Process Not Working After Update

Go to your theme folder and then navigate through this –

/template/checkout/onepage/payment.phtml

if this file is not present copy one from base default directory.

that is /app/design/frontend/base/default/template/checkout/onepage/payment.phtml

Find:

<fieldset>
<?php echo $this->getChildHtml('methods') ?>
</fieldset>

change to:

<fieldset id="checkout-payment-method-load">
<?php echo $this->getChildHtml('methods') ?>
</fieldset>

Magento Indexing Script

Last time I added how to run reindex process programmatically. The problem with previous script is that process update successfully but when I went to search and try to find any sku that shows no result.

Another solution that works is as follow:

<?php
ini_set('display_errors',1);
require_once './app/Mage.php';
umask(0);
Mage::app('admin');
 
$processes = array();
$collection = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($collection as $process) {
	if ($process->getIndexer()->isVisible() === false) {
		continue;
	}
	$processes[] = $process;
}
 
try {
	Mage::dispatchEvent('shell_reindex_init_process');
	foreach ($processes as $process) {
		/* @var $process Mage_Index_Model_Process */
		$process->reindexEverything();
		Mage::dispatchEvent($process->getIndexerCode() . '_shell_reindex_after');
	}
	Mage::dispatchEvent('shell_reindex_finalize_process');
} catch (Exception $e) {
	Mage::dispatchEvent('shell_reindex_finalize_process');
	echo('Exception in Index Index Referesh' . $e -> getMessage() . PHP_EOL);
}
?>

Magento Test SMTP Detail Script

If we want to check that given SMTP detail are working or not, here is a small script that we can use. We are using Zend mail for sending this.

<?php
ini_set('display_errors',1);
require_once './app/Mage.php';
umask(0);
Mage::app('admin');
$port = 465; //465,587
$ssl = "SSL"; // SSL/TLS
$username = "username";
$password = "password";
$host = "smtp.mail.yahoo.com"; // for Google host will be smtp.gmail.com
$config = array('ssl' => $ssl, 'port' => $port, 'auth' => 'login', 'username' => $username, 'password' => $password);
$smtpConnection = new Zend_Mail_Transport_Smtp($host, $config);
 
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('from@example.com', 'From');
$mail->addTo('to@example.com', 'To');
$mail->setSubject('TestSubject');
$mail->send($smtpConnection);
?>

Magento extension that we can use for SMTP configuration – http://www.magentocommerce.com/magento-connect/smtp-pro-email-free-custom-smtp-email.html

Load CMS Page using SSL

In Magento if you have SSL enabled at your server and you want to display any page using https SSL. You can use link in CMS page or in phtml files.

<li><a title="CMS Page" href="{{store url='page-identifier' _secure="true" )}}">CMS Title</a></li>
 
//or if its not working use force secure
 
<li><a title="CMS Page" href="{{store url='page-identifier' _forced_secure="true" )}}">CMS Title</a></li>
 
//In Phtml files - 
 
Mage::getUrl('page-identifier',array('_forced_secure'=>true));