0

Ok so i have got the page working fine for displaying the download links for the downloadable products when the customer is registered and signed in, however when checking out as a guest they are not seeing the links (emails work fine however)

This is my downloadable/block/checkout/list.php

public function __construct()
{
parent::__construct();
$items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
if (!$orderId) {
    return;
}
$orderItems = Mage::getModel('sales/order_item')
          ->getCollection()
          ->setOrderFilter($orderId)
          ->getAllIds();
$itemsToRemove = array();
foreach ($items as $key => $item) {
    if (!in_array($item->getOrderItemId(), $orderItems)) {
    $itemsToRemove[] = $key;
    }
}
foreach ($itemsToRemove as $key) {
    $items->removeItemByKey($key);
}

}

/**
 * Return url to download link
 *
 * @param Mage_Downloadable_Model_Link_Purchased_Item $item
 * @return string
 */
public function getDownloadUrl($item)
{
return $this->getUrl('downloadable/download/link', array('id' => $item->getLinkHash(), '_secure' => true));
}

}

If anyone can give any pointers or want to see any other code please let me know

2

Despite the fact I'm not sure what exactly you mean by

they are not seeing the links

here's my contribution to solve your problem:

There is a seperate block-class Mage_Downloadable_Block_Checkout_Success for the success page of downloadable items with a getOrderHasDownloadable() function.

The function getOrderHasDownloadable() returns false if there is a customer-session with customer-id. It seems that downloads are only available for customers, also depending on the fact, that there is customer_id stored in the downloadable_link_purchased table.

   /**
     * Return true if order(s) has one or more downloadable products
     *
     * @return bool
     */
    public function getOrderHasDownloadable()
    {
        ...
        /**
         * if use guest checkout
         */
        if (!Mage::getSingleton('customer/session')->getCustomerId()) {
            return false;
        }
        ...
    }

Try the following:

  • check if there is a customer-session present in your block
  • check if the link is already generated and saved to the downloadable_link_purchased_item table. The link to the downloadable Product gets generated within the sales_order_item_save_commit_after event in the saveDownloadableOrderItem method in Mage_Downloadable_Model_Observer.

You could try to retrieve the download-link via order-id, order-increment-id in Mage::getModel('downloadable/link_purchased') or purchased-id reference in Mage::getModel('downloadable/link_purchased_item').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.