Search This Blog

Friday 18 January 2013

Redirect to My Downloads page in checkout success

Script to redirect (after 10 seconds) the customer to my downloads page if the order contains downloadable item. Please the following code in success.phtml page at the end in your current theme.

<?php
    $hasDownloadableItem = false;
    try {
        if ($this->getOrderId())
        {
            $orderId = $this->getOrderId();
            $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
            $items = $order->getAllItems();
            foreach ($items as $itemId => $item)
            {
                //$_product = Mage::getModel('catalog/product')->load($item->getProductId());
                $itemData = $item->getData();
                if(isset($itemData['product_type']) and $itemData['product_type']=="downloadable")
                {
                    $hasDownloadableItem = true;
                    break;
                }
            }
        }
    } catch (Exception $e) {
        Mage::log($e->getMessage(), 7);
    }
?>
<?php if($hasDownloadableItem): ?>
<script type="text/javascript">
//<![CDATA[
    setTimeout(function(){ location.href = '<?php echo $this->getUrl() ?>downloadable/customer/products/'},10000);
//]]>
</script>
<?php endif;?>

Note: This is for the logged in customers only.

No comments:

Post a Comment