成功订购后如何获得可下载的产品链接

时间:2010-04-01 16:01:35

标签: url download magento hyperlink product

在成功下单后,我想直接建议买家在success.phtml文件中购买的可下载网址。

我写了这段代码来了解最新订单的产品价值:

// 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
}

2 个答案:

答案 0 :(得分:2)

这对我有用:

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

答案 1 :(得分:2)

我找到了一个解决方案,这里是:

首先,在template / downloadable /中创建一个新的.phtml文件,我打电话给我的downloadablelist.phtml

然后在我们的新downloadablelist.phtml中复制所有模板/可下载/客户/产品/ list.phtml

这将为我们提供可下载产品列表的客户帐户副本。

在成功页面中调用我们的块:

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

现在我从产品列表中清理了我不需要的东西。我删除了表并添加了一个ul。

接下来只显示从最后一个订单生成的产品。

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

我更改了原始可下载文件的网址:

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

谢谢