00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Downloadable_Block_Customer_Products_List extends Mage_Core_Block_Template
00035 {
00036
00037
00038
00039
00040 public function __construct()
00041 {
00042 parent::__construct();
00043 $session = Mage::getSingleton('customer/session');
00044 $purchased = Mage::getResourceModel('downloadable/link_purchased_collection')
00045 ->addFieldToFilter('customer_id', $session->getCustomerId())
00046 ->addOrder('created_at', 'desc');
00047 $this->setPurchased($purchased);
00048 $purchasedIds = array();
00049 foreach ($purchased as $_item) {
00050 $purchasedIds[] = $_item->getId();
00051 }
00052 $purchasedItems = Mage::getResourceModel('downloadable/link_purchased_item_collection')
00053 ->addFieldToFilter('purchased_id', array('in' => $purchasedIds))
00054 ->addFieldToFilter('status', array('nin' => Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT))
00055 ->setOrder('item_id', 'desc');
00056 $this->setItems($purchasedItems);
00057 }
00058
00059
00060
00061
00062
00063
00064 protected function _prepareLayout()
00065 {
00066 parent::_prepareLayout();
00067
00068 $pager = $this->getLayout()->createBlock('page/html_pager', 'downloadable.customer.products.pager')
00069 ->setCollection($this->getItems());
00070 $this->setChild('pager', $pager);
00071 $this->getItems()->load();
00072 foreach ($this->getItems() as $item) {
00073 $item->setPurchased($this->getPurchased()->getItemById($item->getPurchasedId()));
00074 }
00075 return $this;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 public function getOrderViewUrl($orderId)
00085 {
00086 return $this->getUrl('sales/order/view', array('order_id' => $orderId));
00087 }
00088
00089
00090
00091
00092
00093
00094 public function getBackUrl()
00095 {
00096 if ($this->getRefererUrl()) {
00097 return $this->getRefererUrl();
00098 }
00099 return $this->getUrl('customer/account/');
00100 }
00101
00102
00103
00104
00105
00106
00107 public function getRemainingDownloads($item)
00108 {
00109 if ($item->getNumberOfDownloadsBought()) {
00110 $downloads = $item->getNumberOfDownloadsBought() - $item->getNumberOfDownloadsUsed();
00111 return $downloads;
00112 }
00113 return Mage::helper('downloadable')->__('Unlimited');
00114 }
00115
00116
00117
00118
00119
00120
00121
00122 public function getDownloadUrl($item)
00123 {
00124 return $this->getUrl('*/download/link', array('id' => $item->getLinkHash(), '_secure' => true));
00125 }
00126
00127
00128
00129
00130
00131
00132 public function getIsOpenInNewWindow()
00133 {
00134 return Mage::getStoreConfigFlag(Mage_Downloadable_Model_Link::XML_PATH_TARGET_NEW_WINDOW);
00135 }
00136
00137 }