如何在成功订单后获得可下载的产品链接 [英] How to get downloadable product links after successfull order
问题描述
在成功订单之后,我想直接向success.phtml文件中购买的产品买家直接提供可下载的URL。
我写了这段代码来知道最新订单的产品价值:
//获取最新的订单ID
$ order = Mage :: getModel '销售/订单') - >负载(法师:: getSingleton( '结帐/会话') - > getLastOrderId());
//获取最新订单上的所有产品
$ items = $ order-> getAllItems();
//循环产品
foreach($ items as $ item){
$ product = Mage :: getModel('catalog / product') - > setStoreId命令 - > getStoreId()) - >负载($本期特价货品> getProductId());
//这里我需要功能来获得可下载的URL链接
}
我找到了一个解决方案,这里是:
首先,在template /可下载的/ downloadablelist.phtml
然后复制我们新的downloadablelist.phtml中的所有template / downloadable / customer / products / list.phtml
这将给我们一份客户帐户的可下载产品列表。
在成功页面中打电话给我们:
<?php echo $ this-> getLayout() - > createBlock('downloadable / customer_products_list') - > setTemplate('downloadable / checkout /一个.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-> __('可下载的产品')':< / 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') - > __('开始下载')?> <?php echo $ this-> getIsOpenInNewWindow()?'onclick =this.target = \'_blank\''':''; ?>><?php echo $ _item-> getLinkTitle()?>< / a>< / li>
<?php}
endforeach; ?>
< / ul>
<?php endif; ?>
我更改了原始可下载文件的URL:
href =<?php echo $ this-> getUrl('downloadable / download / link /',array('id'=> $ _item-> ; getLinkHash(),'_secure'=> true))?>
谢谢
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
这篇关于如何在成功订单后获得可下载的产品链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!