开发者

How to get downloadable product links after successfull order

After a successfull order I would like to propose directly the downloadable URL for products buyer bought in the success.phtml file.

I wrote this piece of code to know product's values of the latest order:

// Get the latest Order ID
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
// Get every products on the latest order
$items = $order->getAllItems();

// Loop the products
foreach ($items as $item){
    $product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());
    // HERE I NEED FUNCTION TO GET开发者_运维百科 DOWNLOADABLE URL LINK
}


I found a solution, here it is:

First, create a new .phtml file in template/downloadable/ , I called mine downloadablelist.phtml

Then copy all of template/downloadable/customer/products/list.phtml in our new downloadablelist.phtml

This will give us a copy of the customer account my downloadable products list.

Call our block in success page :

<?php echo $this->getLayout()->createBlock('downloadable/customer_products_list')->setTemplate('downloadable/checkout/downloadablelist.phtml')->toHtml(); ?>

Now I cleaned up what I don't need from the product list. I removed the table and added a ul instead.

Next is to show only the products that are made from the last order.

<?php
$_items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(count($_items)):
$_group_id = Mage::helper('customer')->getCustomer()->getGroupId();
echo '<p><strong>'.$this->__('Downloadable products').' : </strong></p>'; ?>
<ul style="margin-left: 30px; list-style: disc;">
        <?php foreach ($_items as $_item):
            $itemOrderId = $_item->getPurchased()->getOrderIncrementId();
            if($itemOrderId == $orderId) {?>
            <li><?php echo $this->htmlEscape($_item->getPurchased()->getProductName()) ?> - <a href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>" title="<?php echo Mage::helper('downloadable')->__('Start Download') ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $_item->getLinkTitle() ?></a></li>
            <?php }
            endforeach; ?>
    </ul>
<?php endif; ?>

I changed the url the original downloadable file had to :

href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>"

Thank you


This worked for me:

$links = Mage::getModel('downloadable/link_purchased_item')->getCollection()
 ->addFieldToFilter('order_item_id', $item->getId());
foreach ($links as $link) {
 echo Mage::helper('downloadable')->__('download') .
  $this->getUrl('downloadable/download/link', 
  array('id' => $link->getLinkHash(), '_store' => $order()->getStore(), 
  '_secure' => true, '_nosid' => true));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜