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:  * Adminhtml catalog product downloadable items tab links section
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Downloadable
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
 35:     extends Mage_Adminhtml_Block_Template
 36: {
 37:     /**
 38:      * Purchased Separately Attribute cache
 39:      *
 40:      * @var Mage_Catalog_Model_Resource_Eav_Attribute
 41:      */
 42:     protected $_purchasedSeparatelyAttribute = null;
 43: 
 44:     /**
 45:      * Class constructor
 46:      *
 47:      */
 48:     public function __construct()
 49:     {
 50:         parent::__construct();
 51:         $this->setTemplate('downloadable/product/edit/downloadable/links.phtml');
 52:         $this->setCanEditPrice(true);
 53:         $this->setCanReadPrice(true);
 54:     }
 55: 
 56:     /**
 57:      * Get product that is being edited
 58:      *
 59:      * @return Mage_Catalog_Model_Product
 60:      */
 61:     public function getProduct()
 62:     {
 63:         return Mage::registry('product');
 64:     }
 65: 
 66:     /**
 67:      * Retrieve Purchased Separately Attribute object
 68:      *
 69:      * @return Mage_Catalog_Model_Resource_Eav_Attribute
 70:      */
 71:     public function getPurchasedSeparatelyAttribute()
 72:     {
 73:         if (is_null($this->_purchasedSeparatelyAttribute)) {
 74:             $_attributeCode = 'links_purchased_separately';
 75: 
 76:             $this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute')
 77:                 ->loadByCode(Mage_Catalog_Model_Product::ENTITY, $_attributeCode);
 78:         }
 79: 
 80:         return $this->_purchasedSeparatelyAttribute;
 81:     }
 82: 
 83:     /**
 84:      * Retrieve Purchased Separately HTML select
 85:      *
 86:      * @return string
 87:      */
 88:     public function getPurchasedSeparatelySelect()
 89:     {
 90:         $select = $this->getLayout()->createBlock('adminhtml/html_select')
 91:             ->setName('product[links_purchased_separately]')
 92:             ->setId('downloadable_link_purchase_type')
 93:             ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray())
 94:             ->setValue($this->getProduct()->getLinksPurchasedSeparately());
 95: 
 96:         return $select->getHtml();
 97:     }
 98: 
 99:     /**
100:      * Retrieve Add button HTML
101:      *
102:      * @return string
103:      */
104:     public function getAddButtonHtml()
105:     {
106:         $addButton = $this->getLayout()->createBlock('adminhtml/widget_button')
107:             ->setData(array(
108:                 'label' => Mage::helper('downloadable')->__('Add New Row'),
109:                 'id'    => 'add_link_item',
110:                 'class' => 'add'
111:             ));
112:         return $addButton->toHtml();
113:     }
114: 
115:     /**
116:      * Retrieve default links title
117:      *
118:      * @return string
119:      */
120:     public function getLinksTitle()
121:     {
122:         return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE);
123:     }
124: 
125:     /**
126:      * Check exists defined links title
127:      *
128:      * @return bool
129:      */
130:     public function getUsedDefault()
131:     {
132:         return $this->getProduct()->getAttributeDefaultValue('links_title') === false;
133:     }
134: 
135:     /**
136:      * Return true if price in website scope
137:      *
138:      * @return bool
139:      */
140:     public function getIsPriceWebsiteScope()
141:     {
142:         $scope =  (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
143:         if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
144:             return true;
145:         }
146:         return false;
147:     }
148: 
149:     /**
150:      * Return array of links
151:      *
152:      * @return array
153:      */
154:     public function getLinkData()
155:     {
156:         $linkArr = array();
157:         $links = $this->getProduct()->getTypeInstance(true)->getLinks($this->getProduct());
158:         $priceWebsiteScope = $this->getIsPriceWebsiteScope();
159:         foreach ($links as $item) {
160:             $tmpLinkItem = array(
161:                 'link_id' => $item->getId(),
162:                 'title' => $this->escapeHtml($item->getTitle()),
163:                 'price' => $this->getCanReadPrice() ? $this->getPriceValue($item->getPrice()) : '',
164:                 'number_of_downloads' => $item->getNumberOfDownloads(),
165:                 'is_shareable' => $item->getIsShareable(),
166:                 'link_url' => $item->getLinkUrl(),
167:                 'link_type' => $item->getLinkType(),
168:                 'sample_file' => $item->getSampleFile(),
169:                 'sample_url' => $item->getSampleUrl(),
170:                 'sample_type' => $item->getSampleType(),
171:                 'sort_order' => $item->getSortOrder(),
172:             );
173:             $file = Mage::helper('downloadable/file')->getFilePath(
174:                 Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
175:             );
176: 
177:             if ($item->getLinkFile() && !is_file($file)) {
178:                 Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
179:             }
180: 
181:             if ($item->getLinkFile() && is_file($file)) {
182:                 $name = '<a href="'
183:                     . $this->getUrl('*/downloadable_product_edit/link', array(
184:                         'id' => $item->getId(),
185:                         '_secure' => true
186:                     )) . '">' . Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) . '</a>';
187:                 $tmpLinkItem['file_save'] = array(
188:                     array(
189:                         'file' => $item->getLinkFile(),
190:                         'name' => $name,
191:                         'size' => filesize($file),
192:                         'status' => 'old'
193:                     ));
194:             }
195:             $sampleFile = Mage::helper('downloadable/file')->getFilePath(
196:                 Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
197:             );
198:             if ($item->getSampleFile() && is_file($sampleFile)) {
199:                 $tmpLinkItem['sample_file_save'] = array(
200:                     array(
201:                         'file' => $item->getSampleFile(),
202:                         'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
203:                         'size' => filesize($sampleFile),
204:                         'status' => 'old'
205:                     ));
206:             }
207:             if ($item->getNumberOfDownloads() == '0') {
208:                 $tmpLinkItem['is_unlimited'] = ' checked="checked"';
209:             }
210:             if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
211:                 $tmpLinkItem['store_title'] = $item->getStoreTitle();
212:             }
213:             if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
214:                 $tmpLinkItem['website_price'] = $item->getWebsitePrice();
215:             }
216:             $linkArr[] = new Varien_Object($tmpLinkItem);
217:         }
218:         return $linkArr;
219:     }
220: 
221:     /**
222:      * Return formated price with two digits after decimal point
223:      *
224:      * @param decimal $value
225:      * @return decimal
226:      */
227:     public function getPriceValue($value)
228:     {
229:         return number_format($value, 2, null, '');
230:     }
231: 
232:     /**
233:      * Retrieve max downloads value from config
234:      *
235:      * @return int
236:      */
237:     public function getConfigMaxDownloads()
238:     {
239:         return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_DEFAULT_DOWNLOADS_NUMBER);
240:     }
241: 
242:     /**
243:      * Prepare block Layout
244:      *
245:      */
246:      protected function _prepareLayout()
247:     {
248:         $this->setChild(
249:             'upload_button',
250:             $this->getLayout()->createBlock('adminhtml/widget_button')->addData(array(
251:                 'id'      => '',
252:                 'label'   => Mage::helper('adminhtml')->__('Upload Files'),
253:                 'type'    => 'button',
254:                 'onclick' => 'Downloadable.massUploadByType(\'links\');Downloadable.massUploadByType(\'linkssample\')'
255:             ))
256:         );
257:     }
258: 
259:     /**
260:      * Retrieve Upload button HTML
261:      *
262:      * @return string
263:      */
264:     public function getUploadButtonHtml()
265:     {
266:         return $this->getChild('upload_button')->toHtml();
267:     }
268: 
269:     /**
270:      * Retrive config json
271:      *
272:      * @return string
273:      */
274:     public function getConfigJson($type='links')
275:     {
276:         $this->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()
277:             ->getUrl('*/downloadable_file/upload', array('type' => $type, '_secure' => true)));
278:         $this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
279:         $this->getConfig()->setFileField($type);
280:         $this->getConfig()->setFilters(array(
281:             'all'    => array(
282:                 'label' => Mage::helper('adminhtml')->__('All Files'),
283:                 'files' => array('*.*')
284:             )
285:         ));
286:         $this->getConfig()->setReplaceBrowseWithRemove(true);
287:         $this->getConfig()->setWidth('32');
288:         $this->getConfig()->setHideUploadButton(true);
289:         return Mage::helper('core')->jsonEncode($this->getConfig()->getData());
290:     }
291: 
292:     /**
293:      * Retrive config object
294:      *
295:      * @return Varien_Config
296:      */
297:     public function getConfig()
298:     {
299:         if(is_null($this->_config)) {
300:             $this->_config = new Varien_Object();
301:         }
302: 
303:         return $this->_config;
304:     }
305: }
306: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0