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:  * Downloadable links API model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Downloadable
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Downloadable_Model_Link_Api extends Mage_Catalog_Model_Api_Resource
 35: {
 36:     /**
 37:      * Return validator instance
 38:      *
 39:      * @return Mage_Downloadable_Model_Link_Api_Validator
 40:      */
 41:     protected function _getValidator()
 42:     {
 43:         return Mage::getSingleton('downloadable/link_api_validator');
 44:     }
 45: 
 46:     /**
 47:      * Decode file from base64 and upload it to donwloadable 'tmp' folder
 48:      *
 49:      * @param array $fileInfo
 50:      * @param string $type
 51:      * @return string
 52:      */
 53:     protected function _uploadFile($fileInfo, $type)
 54:     {
 55:         $tmpPath = '';
 56:         if ($type == 'sample') {
 57:             $tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
 58:         } elseif ($type == 'link') {
 59:             $tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
 60:         } elseif ($type == 'link_samples') {
 61:             $tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
 62:         }
 63: 
 64:         $result = array();
 65:         try {
 66:             $uploader = Mage::getModel('downloadable/link_api_uploader', $fileInfo);
 67:             $uploader->setAllowRenameFiles(true);
 68:             $uploader->setFilesDispersion(true);
 69:             $result = $uploader->save($tmpPath);
 70: 
 71:             if (isset($result['file'])) {
 72:                 $fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
 73:                 Mage::helper('core/file_storage_database')->saveFile($fullPath);
 74:             }
 75:         } catch (Exception $e) {
 76:             if ($e->getMessage() != '') {
 77:                 $this->_fault('upload_failed', $e->getMessage());
 78:             } else {
 79:                 $this->_fault($e->getCode());
 80:             }
 81:         }
 82: 
 83:         $result['status'] = 'new';
 84:         $result['name'] = substr($result['file'], strrpos($result['file'], '/')+1);
 85:         return Mage::helper('core')->jsonEncode(array($result));
 86:     }
 87: 
 88:     /**
 89:      * Add downloadable content to product
 90:      *
 91:      * @param int|string $productId
 92:      * @param array $resource
 93:      * @param string $resourceType
 94:      * @param string|int|null $store
 95:      * @param string|null $identifierType ('sku'|'id')
 96:      * @return boolean
 97:      */
 98:     public function add($productId, $resource, $resourceType, $store = null, $identifierType = null)
 99:     {
100:         try {
101:             $this->_getValidator()->validateType($resourceType);
102:             $this->_getValidator()->validateAttributes($resource, $resourceType);
103:         } catch (Exception $e) {
104:             $this->_fault('validation_error', $e->getMessage());
105:         }
106: 
107:         $resource['is_delete'] = 0;
108:         if ($resourceType == 'link') {
109:             $resource['link_id'] = 0;
110:         } elseif ($resourceType == 'sample') {
111:             $resource['sample_id'] = 0;
112:         }
113: 
114:         if ($resource['type'] == 'file') {
115:             if (isset($resource['file'])) {
116:                 $resource['file'] = $this->_uploadFile($resource['file'], $resourceType);
117:             }
118:             unset($resource[$resourceType.'_url']);
119:         } elseif ($resource['type'] == 'url') {
120:             unset($resource['file']);
121:         }
122: 
123:         if ($resourceType == 'link' && $resource['sample']['type'] == 'file') {
124:             if (isset($resource['sample']['file'])) {
125:                 $resource['sample']['file'] = $this->_uploadFile($resource['sample']['file'], 'link_samples');
126:             }
127:             unset($resource['sample']['url']);
128:         } elseif ($resourceType == 'link' && $resource['sample']['type'] == 'url') {
129:             $resource['sample']['file'] = null;
130:         }
131: 
132:         $product = $this->_getProduct($productId, $store, $identifierType);
133:         try {
134:             $downloadable = array($resourceType => array($resource));
135:             $product->setDownloadableData($downloadable);
136:             $product->save();
137:         } catch (Exception $e) {
138:             $this->_fault('save_error', $e->getMessage());
139:         }
140: 
141:         return true;
142:     }
143: 
144:     /**
145:      * Retrieve downloadable product links
146:      *
147:      * @param int|string $productId
148:      * @param string|int $store
149:      * @param string $identifierType ('sku'|'id')
150:      * @return array
151:      */
152:     public function items($productId, $store = null, $identifierType = null)
153:     {
154:         $product = $this->_getProduct($productId, $store, $identifierType);
155: 
156:         $linkArr = array();
157:         $links = $product->getTypeInstance(true)->getLinks($product);
158:         foreach ($links as $item) {
159:             $tmpLinkItem = array(
160:                 'link_id' => $item->getId(),
161:                 'title' => $item->getTitle(),
162:                 'price' => $item->getPrice(),
163:                 'number_of_downloads' => $item->getNumberOfDownloads(),
164:                 'is_shareable' => $item->getIsShareable(),
165:                 'link_url' => $item->getLinkUrl(),
166:                 'link_type' => $item->getLinkType(),
167:                 'sample_file' => $item->getSampleFile(),
168:                 'sample_url' => $item->getSampleUrl(),
169:                 'sample_type' => $item->getSampleType(),
170:                 'sort_order' => $item->getSortOrder()
171:             );
172:             $file = Mage::helper('downloadable/file')->getFilePath(
173:                 Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
174:             );
175: 
176:             if ($item->getLinkFile() && !is_file($file)) {
177:                 Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
178:             }
179: 
180:             if ($item->getLinkFile() && is_file($file)) {
181:                 $name = Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile());
182:                 $tmpLinkItem['file_save'] = array(
183:                     array(
184:                         'file' => $item->getLinkFile(),
185:                         'name' => $name,
186:                         'size' => filesize($file),
187:                         'status' => 'old'
188:                     ));
189:             }
190:             $sampleFile = Mage::helper('downloadable/file')->getFilePath(
191:                 Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
192:             );
193:             if ($item->getSampleFile() && is_file($sampleFile)) {
194:                 $tmpLinkItem['sample_file_save'] = array(
195:                     array(
196:                         'file' => $item->getSampleFile(),
197:                         'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
198:                         'size' => filesize($sampleFile),
199:                         'status' => 'old'
200:                     ));
201:             }
202:             if ($item->getNumberOfDownloads() == '0') {
203:                 $tmpLinkItem['is_unlimited'] = 1;
204:             }
205:             if ($product->getStoreId() && $item->getStoreTitle()) {
206:                 $tmpLinkItem['store_title'] = $item->getStoreTitle();
207:             }
208:             if ($product->getStoreId() && Mage::helper('downloadable')->getIsPriceWebsiteScope()) {
209:                 $tmpLinkItem['website_price'] = $item->getWebsitePrice();
210:             }
211:             $linkArr[] = $tmpLinkItem;
212:         }
213:         unset($item);
214:         unset($tmpLinkItem);
215:         unset($links);
216: 
217:         $samples = $product->getTypeInstance(true)->getSamples($product)->getData();
218:         return array('links' => $linkArr, 'samples' => $samples);
219:     }
220: 
221:     /**
222:      * Remove downloadable product link
223:      * @param string $linkId
224:      * @param string $resourceType
225:      * @return bool
226:      */
227:     public function remove($linkId, $resourceType)
228:     {
229:         try {
230:             $this->_getValidator()->validateType($resourceType);
231:         } catch (Exception $e) {
232:             $this->_fault('validation_error', $e->getMessage());
233:         }
234: 
235:         switch($resourceType) {
236:             case 'link':
237:                 $downloadableModel = Mage::getSingleton('downloadable/link');
238:                 break;
239:             case 'sample':
240:                 $downloadableModel = Mage::getSingleton('downloadable/sample');
241:                 break;
242:         }
243: 
244:         $downloadableModel->load($linkId);
245:         if (is_null($downloadableModel->getId())) {
246:             $this->_fault('link_was_not_found');
247:         }
248: 
249:         try {
250:             $downloadableModel->delete();
251:         } catch (Exception $e) {
252:             $this->_fault('remove_error', $e->getMessage());
253:         }
254: 
255:         return true;
256:     }
257: 
258:     /**
259:      * Return loaded downloadable product instance
260:      *
261:      * @param  int|string $productId (SKU or ID)
262:      * @param  int|string $store
263:      * @param  string $identifierType
264:      * @return Mage_Catalog_Model_Product
265:      */
266:     protected function _getProduct($productId, $store = null, $identifierType = null)
267:     {
268:         $product = parent::_getProduct($productId, $store, $identifierType);
269: 
270:         if ($product->getTypeId() !== Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
271:             $this->_fault('product_not_downloadable');
272:         }
273: 
274:         return $product;
275:     }
276: }
277: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0