How to get downloadable product links after successfull order

前端 未结 2 1020
长发绾君心
长发绾君心 2021-01-24 13:08

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 p

相关标签:
2条回答
  • 2021-01-24 13:32

    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

    0 讨论(0)
  • 2021-01-24 13:39

    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 讨论(0)
提交回复
热议问题