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_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links extends Mage_Adminhtml_Block_Template
00035 {
00036
00037
00038
00039
00040
00041 protected $_purchasedSeparatelyAttribute = null;
00042
00043
00044
00045
00046
00047 public function __construct()
00048 {
00049 parent::__construct();
00050 $this->setTemplate('downloadable/product/edit/downloadable/links.phtml');
00051 }
00052
00053
00054
00055
00056
00057
00058 public function getProduct()
00059 {
00060 return Mage::registry('product');
00061 }
00062
00063
00064
00065
00066
00067
00068 public function getPurchasedSeparatelyAttribute()
00069 {
00070 if (is_null($this->_purchasedSeparatelyAttribute)) {
00071 $_attributeCode = 'links_purchased_separately';
00072
00073 $this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute')
00074 ->loadByCode('catalog_product', $_attributeCode);
00075 }
00076
00077 return $this->_purchasedSeparatelyAttribute;
00078 }
00079
00080
00081
00082
00083
00084
00085 public function getPurchasedSeparatelySelect()
00086 {
00087 $select = $this->getLayout()->createBlock('adminhtml/html_select')
00088 ->setName('product[links_purchased_separately]')
00089 ->setId('downloadable_link_purchase_type')
00090 ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray())
00091 ->setValue($this->getProduct()->getLinksPurchasedSeparately());
00092
00093 return $select->getHtml();
00094 }
00095
00096
00097
00098
00099
00100
00101 public function getAddButtonHtml()
00102 {
00103 $addButton = $this->getLayout()->createBlock('adminhtml/widget_button')
00104 ->setData(array(
00105 'label' => Mage::helper('downloadable')->__('Add New Row'),
00106 'id' => 'add_link_item',
00107 'class' => 'add',
00108 ));
00109 return $addButton->toHtml();
00110 }
00111
00112
00113
00114
00115
00116
00117 public function getLinksTitle()
00118 {
00119 return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE);
00120 }
00121
00122
00123
00124
00125
00126
00127 public function getUsedDefault()
00128 {
00129 return is_null($this->getProduct()->getAttributeDefaultValue('links_title'));
00130 }
00131
00132
00133
00134
00135
00136
00137 public function getIsPriceWebsiteScope()
00138 {
00139 $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
00140 if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
00141 return true;
00142 }
00143 return false;
00144 }
00145
00146
00147
00148
00149
00150
00151 public function getLinkData()
00152 {
00153 $linkArr = array();
00154 $links = $this->getProduct()->getTypeInstance(true)->getLinks($this->getProduct());
00155 $priceWebsiteScope = $this->getIsPriceWebsiteScope();
00156 foreach ($links as $item) {
00157 $tmpLinkItem = array(
00158 'link_id' => $item->getId(),
00159 'title' => $item->getTitle(),
00160 'price' => $this->getPriceValue($item->getPrice()),
00161 'number_of_downloads' => $item->getNumberOfDownloads(),
00162 'is_shareable' => $item->getIsShareable(),
00163 'link_url' => $item->getLinkUrl(),
00164 'link_type' => $item->getLinkType(),
00165 'sample_file' => $item->getSampleFile(),
00166 'sample_url' => $item->getSampleUrl(),
00167 'sample_type' => $item->getSampleType(),
00168 'sort_order' => $item->getSortOrder()
00169 );
00170 $file = Mage::helper('downloadable/file')->getFilePath(
00171 Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
00172 );
00173 if ($item->getLinkFile() && is_file($file)) {
00174 $name = '<a href="' . $this->getUrl('downloadableadmin/product_edit/link', array('id' => $item->getId(), '_secure' => true)) . '">' .
00175 Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) .
00176 '</a>';
00177 $tmpLinkItem['file_save'] = array(
00178 array(
00179 'file' => $item->getLinkFile(),
00180 'name' => $name,
00181 'size' => filesize($file),
00182 'status' => 'old'
00183 ));
00184 }
00185 $sampleFile = Mage::helper('downloadable/file')->getFilePath(
00186 Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
00187 );
00188 if ($item->getSampleFile() && is_file($sampleFile)) {
00189 $tmpLinkItem['sample_file_save'] = array(
00190 array(
00191 'file' => $item->getSampleFile(),
00192 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
00193 'size' => filesize($sampleFile),
00194 'status' => 'old'
00195 ));
00196 }
00197 if ($item->getNumberOfDownloads() == '0') {
00198 $tmpLinkItem['is_unlimited'] = ' checked="checked"';
00199 }
00200 if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
00201 $tmpLinkItem['store_title'] = $item->getStoreTitle();
00202 }
00203 if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
00204 $tmpLinkItem['website_price'] = $item->getWebsitePrice();
00205 }
00206 $linkArr[] = new Varien_Object($tmpLinkItem);
00207 }
00208 return $linkArr;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217 public function getPriceValue($value)
00218 {
00219 return number_format($value, 2, null, '');
00220 }
00221
00222
00223
00224
00225
00226
00227 public function getConfigMaxDownloads()
00228 {
00229 return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_DEFAULT_DOWNLOADS_NUMBER);
00230 }
00231
00232
00233
00234
00235
00236 protected function _prepareLayout()
00237 {
00238 $this->setChild(
00239 'upload_button',
00240 $this->getLayout()->createBlock('adminhtml/widget_button')
00241 ->addData(array(
00242 'id' => '',
00243 'label' => Mage::helper('adminhtml')->__('Upload Files'),
00244 'type' => 'button',
00245 'onclick' => 'Downloadable.massUploadByType(\'links\');Downloadable.massUploadByType(\'linkssample\')'
00246 ))
00247 );
00248 }
00249
00250
00251
00252
00253
00254
00255 public function getUploadButtonHtml()
00256 {
00257 return $this->getChild('upload_button')->toHtml();
00258 }
00259
00260
00261
00262
00263
00264
00265 public function getConfigJson($type='links')
00266 {
00267 $this->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('downloadableadmin/file/upload', array('type' => $type, '_secure' => true)));
00268 $this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
00269 $this->getConfig()->setFileField($type);
00270 $this->getConfig()->setFilters(array(
00271 'all' => array(
00272 'label' => Mage::helper('adminhtml')->__('All Files'),
00273 'files' => array('*.*')
00274 )
00275 ));
00276 $this->getConfig()->setReplaceBrowseWithRemove(true);
00277 $this->getConfig()->setWidth('32');
00278 $this->getConfig()->setHideUploadButton(true);
00279 return Zend_Json::encode($this->getConfig()->getData());
00280 }
00281
00282
00283
00284
00285
00286
00287 public function getConfig()
00288 {
00289 if(is_null($this->_config)) {
00290 $this->_config = new Varien_Object();
00291 }
00292
00293 return $this->_config;
00294 }
00295 }