本文整理汇总了PHP中Mage_Downloadable_Model_Link类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Downloadable_Model_Link类的具体用法?PHP Mage_Downloadable_Model_Link怎么用?PHP Mage_Downloadable_Model_Link使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Downloadable_Model_Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLinkData
/**
* Return array of links
*
* @return array
*/
public function getLinkData()
{
$linkArr = array();
$prod = $this->getProduct();
$prodType = $this->getProduct()->getTypeInstance(true);
$links = $this->getProduct()->getTypeInstance(true)->getLinks($this->getProduct());
$priceWebsiteScope = $this->getIsPriceWebsiteScope();
foreach ($links as $item) {
$tmpLinkItem = array('link_id' => $item->getId(), 'title' => $item->getTitle(), 'price' => $this->getCanReadPrice() ? $this->getPriceValue($item->getPrice()) : '', 'number_of_downloads' => $item->getNumberOfDownloads(), 'number_of_purchases' => $item->getNumberOfPurchases(), 'is_shareable' => $item->getIsShareable(), 'link_url' => $item->getLinkUrl(), 'link_type' => $item->getLinkType(), 'sample_file' => $item->getSampleFile(), 'sample_url' => $item->getSampleUrl(), 'sample_type' => $item->getSampleType(), 'sort_order' => $item->getSortOrder());
$file = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile());
if ($item->getLinkFile() && !is_file($file)) {
Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
}
if ($item->getLinkFile() && is_file($file)) {
$name = '<a href="' . $this->getUrl('*/downloadable_product_edit/link', array('id' => $item->getId(), '_secure' => true)) . '">' . Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) . '</a>';
$tmpLinkItem['file_save'] = array(array('file' => $item->getLinkFile(), 'name' => $name, 'size' => filesize($file), 'status' => 'old'));
}
$sampleFile = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile());
if ($item->getSampleFile() && is_file($sampleFile)) {
$tmpLinkItem['sample_file_save'] = array(array('file' => $item->getSampleFile(), 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()), 'size' => filesize($sampleFile), 'status' => 'old'));
}
if ($item->getNumberOfDownloads() == '0') {
$tmpLinkItem['is_unlimited'] = ' checked="checked"';
}
if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
$tmpLinkItem['store_title'] = $item->getStoreTitle();
}
if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
$tmpLinkItem['website_price'] = $item->getWebsitePrice();
}
$linkArr[] = new Varien_Object($tmpLinkItem);
}
return $linkArr;
}
开发者ID:ankita-parashar,项目名称:magento,代码行数:39,代码来源:ICC_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links.php
示例2: uploadAction
/**
* Upload file controller action
*/
public function uploadAction()
{
$type = $this->getRequest()->getParam('type');
$tmpPath = '';
if ($type == 'samples') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
} elseif ($type == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
} elseif ($type == 'link_samples') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
}
$result = array();
try {
$uploader = new Mage_Core_Model_File_Uploader($type);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($tmpPath);
if (isset($result['file'])) {
$fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFile($fullPath);
}
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode($result));
}
示例3: massImportAction
public function massImportAction()
{
$fotothekeIds = $this->getRequest()->getParam('fototheke');
if (!is_array($fotothekeIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
} else {
try {
$filePath = Mage_Downloadable_Model_Link::getBasePath();
$i = 0;
foreach ($fotothekeIds as $fotothekeId) {
$model = Mage::getModel('soapsync/ibramssync');
$added = $model->getCollection()->addDownloads($fotothekeId, false);
if ($added) {
$productmodel = Mage::getModel('catalog/product');
$product = $productmodel->load($fotothekeId);
$product->setStockData(array('use_config_manage_stock' => 1, 'manage_stock' => 1, 'qty' => 1, 'is_in_stock' => 1, 'min_sale_qty' => 0, 'max_sale_qty' => 1));
$product->setLinksPurchasedSeparately(1);
$product->setHasOptions(1);
$product->setRequiredOptions(1);
$product->save();
$i++;
}
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Total of %d record(s) were successfully copied to filesystem and links saved to Database', $i));
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
示例4: uploadAction
/**
* Upload file controller action
*/
public function uploadAction()
{
$type = $this->getRequest()->getParam('type');
$tmpPath = '';
if ($type == 'samples') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
} elseif ($type == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
} elseif ($type == 'link_samples') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
}
$result = array();
try {
$uploader = new Mage_Core_Model_File_Uploader($type);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($tmpPath);
/**
* Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
*/
$result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
$result['path'] = str_replace(DS, "/", $result['path']);
if (isset($result['file'])) {
$fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
Mage::helper('core/file_storage_database')->saveFile($fullPath);
}
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
示例5: getFormattedLinkPrice
/**
* Enter description here...
*
* @param Mage_Downloadable_Model_Link $link
* @return string
*/
public function getFormattedLinkPrice($link)
{
$price = $link->getPrice();
if (0 == $price) {
return '';
}
$_priceInclTax = Mage::helper('tax')->getPrice($link->getProduct(), $price, true);
$_priceExclTax = Mage::helper('tax')->getPrice($link->getProduct(), $price);
$priceStr = '<span class="price-notice">+';
if (Mage::helper('tax')->displayPriceIncludingTax()) {
$priceStr .= $this->helper('core')->currency($_priceInclTax, true, true);
} elseif (Mage::helper('tax')->displayPriceExcludingTax()) {
$priceStr .= $this->helper('core')->currency($_priceExclTax, true, true);
} elseif (Mage::helper('tax')->displayBothPrices()) {
$priceStr .= $this->helper('core')->currency($_priceExclTax, true, true);
if ($_priceInclTax != $_priceExclTax) {
$priceStr .= ' (+' . $this->helper('core')->currency($_priceInclTax, true, true) . ' ' . $this->__('Incl. Tax') . ')';
}
}
$priceStr .= '</span>';
return $priceStr;
}
示例6: linkAction
/**
* Download link action
*
*/
public function linkAction()
{
$linkId = $this->getRequest()->getParam('id', 0);
$link = Mage::getModel('downloadable/link')->load($linkId);
if ($link->getId()) {
$resource = '';
$resourceType = '';
if ($link->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
$resource = $link->getLinkUrl();
$resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
} elseif ($link->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$resource = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBasePath(), $link->getLinkFile());
$resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
}
try {
$this->_processDownload($resource, $resourceType);
} catch (Mage_Core_Exception $e) {
Mage::getSingleton('udropship/session')->addError(Mage::helper('downloadable')->__('An error occurred while getting the requested content.'));
}
}
exit(0);
}
示例7: uploadAction
/**
* Upload file controller action
*/
public function uploadAction()
{
$type = $this->getRequest()->getParam('type');
$tmpPath = '';
if ($type == 'samples') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
} elseif ($type == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
} elseif ($type == 'link_samples') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
}
$result = array();
try {
$uploader = new Varien_File_Uploader($type);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($tmpPath);
$result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
} catch (Exception $e) {
$result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
示例8: save
/**
* Save Product downloadable information (links and samples)
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Downloadable_Model_Product_Type
*/
public function save($product = null)
{
parent::save($product);
$product = $this->getProduct($product);
/* @var Mage_Catalog_Model_Product $product */
if ($data = $product->getDownloadableData()) {
if (isset($data['sample'])) {
$_deleteItems = array();
foreach ($data['sample'] as $sampleItem) {
if ($sampleItem['is_delete'] == '1') {
if ($sampleItem['sample_id']) {
$_deleteItems[] = $sampleItem['sample_id'];
}
} else {
unset($sampleItem['is_delete']);
if (!$sampleItem['sample_id']) {
unset($sampleItem['sample_id']);
}
$sampleModel = Mage::getModel('downloadable/sample');
$files = array();
if (isset($sampleItem['file'])) {
$files = Mage::helper('core')->jsonDecode($sampleItem['file']);
unset($sampleItem['file']);
}
$sampleModel->setData($sampleItem)->setSampleType($sampleItem['type'])->setProductId($product->getId())->setStoreId($product->getStoreId());
if ($sampleModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$sampleFileName = Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Sample::getBaseTmpPath(), Mage_Downloadable_Model_Sample::getBasePath(), $files);
$sampleModel->setSampleFile($sampleFileName);
}
$sampleModel->save();
}
}
if ($_deleteItems) {
Mage::getResourceModel('downloadable/sample')->deleteItems($_deleteItems);
}
}
if (isset($data['link'])) {
$_deleteItems = array();
foreach ($data['link'] as $linkItem) {
if ($linkItem['is_delete'] == '1') {
if ($linkItem['link_id']) {
$_deleteItems[] = $linkItem['link_id'];
}
} else {
unset($linkItem['is_delete']);
if (!$linkItem['link_id']) {
unset($linkItem['link_id']);
}
$files = array();
if (isset($linkItem['file'])) {
$files = Mage::helper('core')->jsonDecode($linkItem['file']);
unset($linkItem['file']);
}
$sample = array();
if (isset($linkItem['sample'])) {
$sample = $linkItem['sample'];
unset($linkItem['sample']);
}
$linkModel = Mage::getModel('downloadable/link')->setData($linkItem)->setLinkType($linkItem['type'])->setProductId($product->getId())->setStoreId($product->getStoreId())->setWebsiteId($product->getStore()->getWebsiteId())->setProductWebsiteIds($product->getWebsiteIds());
if (null === $linkModel->getPrice()) {
$linkModel->setPrice(0);
}
if ($linkModel->getIsUnlimited()) {
$linkModel->setNumberOfDownloads(0);
}
$sampleFile = array();
if ($sample && isset($sample['type'])) {
if ($sample['type'] == 'url' && $sample['url'] != '') {
$linkModel->setSampleUrl($sample['url']);
}
$linkModel->setSampleType($sample['type']);
$sampleFile = Mage::helper('core')->jsonDecode($sample['file']);
}
if ($linkModel->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Link::getBaseTmpPath(), Mage_Downloadable_Model_Link::getBasePath(), $files);
$linkModel->setLinkFile($linkFileName);
}
if ($linkModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$linkSampleFileName = Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Link::getBaseSampleTmpPath(), Mage_Downloadable_Model_Link::getBaseSamplePath(), $sampleFile);
$linkModel->setSampleFile($linkSampleFileName);
}
$linkModel->save();
}
}
if ($_deleteItems) {
Mage::getResourceModel('downloadable/link')->deleteItems($_deleteItems);
}
if ($this->getProduct($product)->getLinksPurchasedSeparately()) {
$this->getProduct($product)->setIsCustomOptionChanged();
}
}
}
return $this;
}
示例9: getTmpPathForDownloadable
/**
* Get temporary path for downloadable product
*
* @param array $key
* @return array $tmpPathResult
*/
public function getTmpPathForDownloadable($key)
{
$type = $tmpPath = '';
$tmpPathResult = array();
if (substr($key, 0, 5) == 'sampl') {
$tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
$type = 'samples';
}
if (substr($key, 0, 5) == 'links') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
$type = 'links';
}
if (substr($key, 0, 5) == 'l_sam') {
$tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
$type = 'link_samples';
}
$tmpPathResult['type'] = $type;
$tmpPathResult['tmp_path'] = $tmpPath;
return $tmpPathResult;
}
示例10: saveItemTitleAndPrice
/**
* Save title and price of link item
*
* @param Mage_Downloadable_Model_Link $linkObject
* @return Mage_Downloadable_Model_Mysql4_link
*/
public function saveItemTitleAndPrice($linkObject)
{
$stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_title'))->where('link_id = ?', $linkObject->getId())->where('store_id = ?', $linkObject->getStoreId());
if ($this->_getReadAdapter()->fetchOne($stmt)) {
$where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId());
if ($linkObject->getUseDefaultTitle()) {
$this->_getWriteAdapter()->delete($this->getTable('downloadable/link_title'), $where);
} else {
$this->_getWriteAdapter()->update($this->getTable('downloadable/link_title'), array('title' => $linkObject->getTitle()), $where);
}
} else {
if (!$linkObject->getUseDefaultTitle()) {
$this->_getWriteAdapter()->insert($this->getTable('downloadable/link_title'), array('link_id' => $linkObject->getId(), 'store_id' => $linkObject->getStoreId(), 'title' => $linkObject->getTitle()));
}
}
$stmt = null;
$stmt = $this->_getReadAdapter()->select()->from($this->getTable('downloadable/link_price'))->where('link_id = ?', $linkObject->getId())->where('website_id = ?', $linkObject->getWebsiteId());
if ($this->_getReadAdapter()->fetchOne($stmt)) {
$where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId());
if ($linkObject->getUseDefaultPrice()) {
$this->_getReadAdapter()->delete($this->getTable('downloadable/link_price'), $where);
} else {
$this->_getWriteAdapter()->update($this->getTable('downloadable/link_price'), array('price' => $linkObject->getPrice()), $where);
}
} else {
if (!$linkObject->getUseDefaultPrice()) {
$this->_getWriteAdapter()->insert($this->getTable('downloadable/link_price'), array('link_id' => $linkObject->getId(), 'website_id' => $linkObject->getWebsiteId(), 'price' => $linkObject->getPrice()));
}
}
return $this;
}
示例11: deleteItems
/**
* Delete data by item(s)
*
* @param Mage_Downloadable_Model_Link|array|int $items
* @return Mage_Downloadable_Model_Resource_Link
*/
public function deleteItems($items)
{
$writeAdapter = $this->_getWriteAdapter();
$where = array();
if ($items instanceof Mage_Downloadable_Model_Link) {
$where = array('link_id = ?' => $items->getId());
} elseif (is_array($items)) {
$where = array('link_id in (?)' => $items);
} else {
$where = array('sample_id = ?' => $items);
}
if ($where) {
$writeAdapter->delete($this->getMainTable(), $where);
$writeAdapter->delete($this->getTable('downloadable/link_title'), $where);
$writeAdapter->delete($this->getTable('downloadable/link_price'), $where);
}
return $this;
}
示例12: items
/**
* Retrieve downloadable product links
*
* @param int|string $productId
* @param string|int $store
* @param string $identifierType ('sku'|'id')
* @return array
*/
public function items($productId, $store = null, $identifierType = null)
{
$product = $this->_getProduct($productId, $store, $identifierType);
$linkArr = array();
$links = $product->getTypeInstance(true)->getLinks($product);
foreach ($links as $item) {
$tmpLinkItem = array('link_id' => $item->getId(), 'title' => $item->getTitle(), 'price' => $item->getPrice(), 'number_of_downloads' => $item->getNumberOfDownloads(), 'is_shareable' => $item->getIsShareable(), 'link_url' => $item->getLinkUrl(), 'link_type' => $item->getLinkType(), 'sample_file' => $item->getSampleFile(), 'sample_url' => $item->getSampleUrl(), 'sample_type' => $item->getSampleType(), 'sort_order' => $item->getSortOrder());
$file = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile());
if ($item->getLinkFile() && !is_file($file)) {
Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
}
if ($item->getLinkFile() && is_file($file)) {
$name = Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile());
$tmpLinkItem['file_save'] = array(array('file' => $item->getLinkFile(), 'name' => $name, 'size' => filesize($file), 'status' => 'old'));
}
$sampleFile = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile());
if ($item->getSampleFile() && is_file($sampleFile)) {
$tmpLinkItem['sample_file_save'] = array(array('file' => $item->getSampleFile(), 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()), 'size' => filesize($sampleFile), 'status' => 'old'));
}
if ($item->getNumberOfDownloads() == '0') {
$tmpLinkItem['is_unlimited'] = 1;
}
if ($product->getStoreId() && $item->getStoreTitle()) {
$tmpLinkItem['store_title'] = $item->getStoreTitle();
}
if ($product->getStoreId() && Mage::helper('downloadable')->getIsPriceWebsiteScope()) {
$tmpLinkItem['website_price'] = $item->getWebsitePrice();
}
$linkArr[] = $tmpLinkItem;
}
unset($item);
unset($tmpLinkItem);
unset($links);
$samples = $product->getTypeInstance(true)->getSamples($product)->getData();
return array('links' => $linkArr, 'samples' => $samples);
}
示例13: linkAction
/**
* Download link action
*/
public function linkAction()
{
$id = $this->getRequest()->getParam('id', 0);
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
if (!$linkPurchasedItem->getId()) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link doesn't exist."));
return $this->_redirect('*/customer/products');
}
if (!Mage::helper('downloadable')->getIsShareable($linkPurchasedItem)) {
$customerId = $this->_getCustomerSession()->getCustomerId();
if (!$customerId) {
$product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
if ($product->getId()) {
$notice = Mage::helper('downloadable')->__('Please log in to download your product or purchase <a href="%s">%s</a>.', $product->getProductUrl(), $product->getName());
} else {
$notice = Mage::helper('downloadable')->__('Please log in to download your product.');
}
$this->_getCustomerSession()->addNotice($notice);
$this->_getCustomerSession()->authenticate($this);
$this->_getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('downloadable/customer/products/'), array('_secure' => true));
return;
}
$linkPurchased = Mage::getModel('downloadable/link_purchased')->load($linkPurchasedItem->getPurchasedId());
if ($linkPurchased->getCustomerId() != $customerId) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link doesn't exist."));
return $this->_redirect('*/customer/products');
}
}
$downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought() - $linkPurchasedItem->getNumberOfDownloadsUsed();
if ($linkPurchasedItem->getStatus() == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE && ($downloadsLeft || $linkPurchasedItem->getNumberOfDownloadsBought() == 0)) {
$resource = '';
$resourceType = '';
if ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
$resource = $linkPurchasedItem->getLinkUrl();
$resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
} elseif ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$resource = Mage::helper('downloadable/file')->getFilePath(Mage_Downloadable_Model_Link::getBasePath(), $linkPurchasedItem->getLinkFile());
$resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
}
try {
$this->_processDownload($resource, $resourceType);
$linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed() + 1);
if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 && !($linkPurchasedItem->getNumberOfDownloadsBought() - $linkPurchasedItem->getNumberOfDownloadsUsed())) {
$linkPurchasedItem->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED);
}
$linkPurchasedItem->save();
exit(0);
} catch (Exception $e) {
$this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('Sorry, there was an error getting requested content. Please contact store owner.'));
}
} elseif ($linkPurchasedItem->getStatus() == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('Link has expired.'));
} elseif ($linkPurchasedItem->getStatus() == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('Link is not available.'));
} else {
$this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('Sorry, there was an error getting requested content. Please contact store owner.'));
}
return $this->_redirect('*/customer/products');
}
示例14: deleteItems
/**
* Delete data by item(s)
*
* @param Mage_Downloadable_Model_Link|array|int $items
* @return Mage_Downloadable_Model_Mysql4_Link
*/
public function deleteItems($items)
{
$where = '';
if ($items instanceof Mage_Downloadable_Model_Link) {
$where = $this->_getReadAdapter()->quoteInto('link_id = ?', $items->getId());
} elseif (is_array($items)) {
$where = $this->_getReadAdapter()->quoteInto('link_id in (?)', $items);
} else {
$where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items);
}
if ($where) {
$this->_getWriteAdapter()->delete($this->getTable('downloadable/link'), $where);
$this->_getWriteAdapter()->delete($this->getTable('downloadable/link_title'), $where);
$this->_getWriteAdapter()->delete($this->getTable('downloadable/link_price'), $where);
}
return $this;
}
示例15: getIsLinkChecked
/**
* Returns whether link checked by default or not
*
* @param Mage_Downloadable_Model_Link $link
* @return bool
*/
public function getIsLinkChecked($link)
{
$configValue = $this->getProduct()->getPreconfiguredValues()->getLinks();
if (!$configValue || !is_array($configValue)) {
return false;
}
return $configValue && in_array($link->getId(), $configValue);
}