PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php

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