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));

Magento Sort By Price: Low to High and High to Low

To Make this change please navigate through -> /app/design/frontend/default/your-theme/template/catalog/product/list/toolbar.phtml file.

Find

<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
    <?php echo $this->__($_order) ?>
</option>

and Replace with

<?php if ($_order != 'Price'): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
    <?php echo $this->__($_order) ?>
</option>
<?php else: ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key) && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
    <?php echo $this->__($_order) . ': Low to High' ?>
</option> 
<option value="<?php echo $this->getOrderUrl($_key, 'desc') ?>"<?php if($this->isOrderCurrent($_key) && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
    <?php echo $this->__($_order) . ': High to Low' ?>
</option> 
<?php endif; ?>