Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Downloadable_Adminhtml_Downloadable_FileController
  • Mage_Downloadable_Adminhtml_Downloadable_Product_EditController
  • Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable
  • Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
  • Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Samples
  • Mage_Downloadable_Block_Adminhtml_Sales_Items_Column_Downloadable_Name
  • Mage_Downloadable_Block_Catalog_Product_Links
  • Mage_Downloadable_Block_Catalog_Product_Samples
  • Mage_Downloadable_Block_Catalog_Product_View_Type
  • Mage_Downloadable_Block_Checkout_Cart_Item_Renderer
  • Mage_Downloadable_Block_Checkout_Success
  • Mage_Downloadable_Block_Customer_Products_List
  • Mage_Downloadable_Block_Sales_Order_Email_Items_Downloadable
  • Mage_Downloadable_Block_Sales_Order_Email_Items_Order_Downloadable
  • Mage_Downloadable_Block_Sales_Order_Item_Renderer_Downloadable
  • Mage_Downloadable_CustomerController
  • Mage_Downloadable_DownloadController
  • Mage_Downloadable_Helper_Catalog_Product_Configuration
  • Mage_Downloadable_Helper_Data
  • Mage_Downloadable_Helper_Download
  • Mage_Downloadable_Helper_File
  • Mage_Downloadable_Model_CatalogIndex_Data_Downloadable
  • Mage_Downloadable_Model_Link
  • Mage_Downloadable_Model_Link_Api
  • Mage_Downloadable_Model_Link_Api_Uploader
  • Mage_Downloadable_Model_Link_Api_V2
  • Mage_Downloadable_Model_Link_Api_Validator
  • Mage_Downloadable_Model_Link_Purchased
  • Mage_Downloadable_Model_Link_Purchased_Item
  • Mage_Downloadable_Model_Mysql4_Indexer_Price
  • Mage_Downloadable_Model_Mysql4_Link
  • Mage_Downloadable_Model_Mysql4_Link_Collection
  • Mage_Downloadable_Model_Mysql4_Link_Purchased
  • Mage_Downloadable_Model_Mysql4_Link_Purchased_Collection
  • Mage_Downloadable_Model_Mysql4_Link_Purchased_Item
  • Mage_Downloadable_Model_Mysql4_Link_Purchased_Item_Collection
  • Mage_Downloadable_Model_Mysql4_Sample
  • Mage_Downloadable_Model_Mysql4_Sample_Collection
  • Mage_Downloadable_Model_Observer
  • Mage_Downloadable_Model_Product_Price
  • Mage_Downloadable_Model_Product_Type
  • Mage_Downloadable_Model_Resource_Indexer_Price
  • Mage_Downloadable_Model_Resource_Link
  • Mage_Downloadable_Model_Resource_Link_Collection
  • Mage_Downloadable_Model_Resource_Link_Purchased
  • Mage_Downloadable_Model_Resource_Link_Purchased_Collection
  • Mage_Downloadable_Model_Resource_Link_Purchased_Item
  • Mage_Downloadable_Model_Resource_Link_Purchased_Item_Collection
  • Mage_Downloadable_Model_Resource_Sample
  • Mage_Downloadable_Model_Resource_Sample_Collection
  • Mage_Downloadable_Model_Sales_Order_Pdf_Items_Abstract
  • Mage_Downloadable_Model_Sales_Order_Pdf_Items_Creditmemo
  • Mage_Downloadable_Model_Sales_Order_Pdf_Items_Invoice
  • Mage_Downloadable_Model_Sample
  • Mage_Downloadable_Model_System_Config_Source_Contentdisposition
  • Mage_Downloadable_Model_System_Config_Source_Orderitemstatus
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Downloadable
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Download controller
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Downloadable
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Downloadable_DownloadController extends Mage_Core_Controller_Front_Action
 35: {
 36: 
 37:     /**
 38:      * Return core session object
 39:      *
 40:      * @return Mage_Core_Model_Session
 41:      */
 42:     protected function _getSession()
 43:     {
 44:         return Mage::getSingleton('core/session');
 45:     }
 46: 
 47:     /**
 48:      * Return customer session object
 49:      *
 50:      * @return Mage_Customer_Model_Session
 51:      */
 52:     protected function _getCustomerSession()
 53:     {
 54:         return Mage::getSingleton('customer/session');
 55:     }
 56: 
 57:     protected function _processDownload($resource, $resourceType)
 58:     {
 59:         $helper = Mage::helper('downloadable/download');
 60:         /* @var $helper Mage_Downloadable_Helper_Download */
 61: 
 62:         $helper->setResource($resource, $resourceType);
 63: 
 64:         $fileName       = $helper->getFilename();
 65:         $contentType    = $helper->getContentType();
 66: 
 67:         $this->getResponse()
 68:             ->setHttpResponseCode(200)
 69:             ->setHeader('Pragma', 'public', true)
 70:             ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
 71:             ->setHeader('Content-type', $contentType, true);
 72: 
 73:         if ($fileSize = $helper->getFilesize()) {
 74:             $this->getResponse()
 75:                 ->setHeader('Content-Length', $fileSize);
 76:         }
 77: 
 78:         if ($contentDisposition = $helper->getContentDisposition()) {
 79:             $this->getResponse()
 80:                 ->setHeader('Content-Disposition', $contentDisposition . '; filename='.$fileName);
 81:         }
 82: 
 83:         $this->getResponse()
 84:             ->clearBody();
 85:         $this->getResponse()
 86:             ->sendHeaders();
 87: 
 88:         $helper->output();
 89:     }
 90: 
 91:     /**
 92:      * Download sample action
 93:      *
 94:      */
 95:     public function sampleAction()
 96:     {
 97:         $sampleId = $this->getRequest()->getParam('sample_id', 0);
 98:         $sample = Mage::getModel('downloadable/sample')->load($sampleId);
 99:         if ($sample->getId()) {
100:             $resource = '';
101:             $resourceType = '';
102:             if ($sample->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
103:                 $resource = $sample->getSampleUrl();
104:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
105:             } elseif ($sample->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
106:                 $resource = Mage::helper('downloadable/file')->getFilePath(
107:                     Mage_Downloadable_Model_Sample::getBasePath(), $sample->getSampleFile()
108:                 );
109:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
110:             }
111:             try {
112:                 $this->_processDownload($resource, $resourceType);
113:                 exit(0);
114:             } catch (Mage_Core_Exception $e) {
115:                 $this->_getSession()->addError(Mage::helper('downloadable')->__('Sorry, there was an error getting requested content. Please contact the store owner.'));
116:             }
117:         }
118:         return $this->_redirectReferer();
119:     }
120: 
121:     /**
122:      * Download link's sample action
123:      *
124:      */
125:     public function linkSampleAction()
126:     {
127:         $linkId = $this->getRequest()->getParam('link_id', 0);
128:         $link = Mage::getModel('downloadable/link')->load($linkId);
129:         if ($link->getId()) {
130:             $resource = '';
131:             $resourceType = '';
132:             if ($link->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
133:                 $resource = $link->getSampleUrl();
134:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
135:             } elseif ($link->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
136:                 $resource = Mage::helper('downloadable/file')->getFilePath(
137:                     Mage_Downloadable_Model_Link::getBaseSamplePath(), $link->getSampleFile()
138:                 );
139:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
140:             }
141:             try {
142:                 $this->_processDownload($resource, $resourceType);
143:                 exit(0);
144:             } catch (Mage_Core_Exception $e) {
145:                 $this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('Sorry, there was an error getting requested content. Please contact the store owner.'));
146:             }
147:         }
148:         return $this->_redirectReferer();
149:     }
150: 
151:     /**
152:      * Download link action
153:      */
154:     public function linkAction()
155:     {
156:         $id = $this->getRequest()->getParam('id', 0);
157:         $linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
158:         if (! $linkPurchasedItem->getId() ) {
159:             $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link does not exist."));
160:             return $this->_redirect('*/customer/products');
161:         }
162:         if (!Mage::helper('downloadable')->getIsShareable($linkPurchasedItem)) {
163:             $customerId = $this->_getCustomerSession()->getCustomerId();
164:             if (!$customerId) {
165:                 $product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
166:                 if ($product->getId()) {
167:                     $notice = Mage::helper('downloadable')->__('Please log in to download your product or purchase <a href="%s">%s</a>.', $product->getProductUrl(), $product->getName());
168:                 } else {
169:                     $notice = Mage::helper('downloadable')->__('Please log in to download your product.');
170:                 }
171:                 $this->_getCustomerSession()->addNotice($notice);
172:                 $this->_getCustomerSession()->authenticate($this);
173:                 $this->_getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('downloadable/customer/products/'),
174:                     array('_secure' => true)
175:                 );
176:                 return ;
177:             }
178:             $linkPurchased = Mage::getModel('downloadable/link_purchased')->load($linkPurchasedItem->getPurchasedId());
179:             if ($linkPurchased->getCustomerId() != $customerId) {
180:                 $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link does not exist."));
181:                 return $this->_redirect('*/customer/products');
182:             }
183:         }
184:         $downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought()
185:             - $linkPurchasedItem->getNumberOfDownloadsUsed();
186: 
187:         $status = $linkPurchasedItem->getStatus();
188:         if ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE
189:             && ($downloadsLeft || $linkPurchasedItem->getNumberOfDownloadsBought() == 0)
190:         ) {
191:             $resource = '';
192:             $resourceType = '';
193:             if ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
194:                 $resource = $linkPurchasedItem->getLinkUrl();
195:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
196:             } elseif ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
197:                 $resource = Mage::helper('downloadable/file')->getFilePath(
198:                     Mage_Downloadable_Model_Link::getBasePath(), $linkPurchasedItem->getLinkFile()
199:                 );
200:                 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
201:             }
202:             try {
203:                 $this->_processDownload($resource, $resourceType);
204:                 $linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed() + 1);
205: 
206:                 if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 && !($downloadsLeft - 1)) {
207:                     $linkPurchasedItem->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED);
208:                 }
209:                 $linkPurchasedItem->save();
210:                 exit(0);
211:             }
212:             catch (Exception $e) {
213:                 $this->_getCustomerSession()->addError(
214:                     Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.')
215:                 );
216:             }
217:         } elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) {
218:             $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link has expired.'));
219:         } elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING
220:             || $status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW
221:         ) {
222:             $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link is not available.'));
223:         } else {
224:             $this->_getCustomerSession()->addError(
225:                 Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.')
226:             );
227:         }
228:         return $this->_redirect('*/customer/products');
229:     }
230: 
231: }
232: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0