本文整理汇总了PHP中Mage_Downloadable_Model_Link::getBasePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Downloadable_Model_Link::getBasePath方法的具体用法?PHP Mage_Downloadable_Model_Link::getBasePath怎么用?PHP Mage_Downloadable_Model_Link::getBasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Downloadable_Model_Link
的用法示例。
在下文中一共展示了Mage_Downloadable_Model_Link::getBasePath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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('*/*/');
}
示例3: 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);
}
示例4: 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;
}
示例5: 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');
}
示例6: 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);
}
示例7: linkAction
/**
* Download link action
*
*/
public function linkAction()
{
$linkId = $this->getRequest()->getParam('id', 0);
$link = AO::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 = AO::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) {
$this->_getCustomerSession()->addError(AO::helper('downloadable')->__('Sorry, there was an error getting requested content'));
}
}
}
示例8: save
/**
* Enter description here...
*
* @return Mage_Downloadable_Model_Product_Type
*/
public function save()
{
parent::save();
$product = $this->getProduct();
/* @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 = Zend_Json::decode($sampleItem['file']);
unset($sampleItem['file']);
}
$sampleModel->setData($sampleItem)->setSampleType($sampleItem['type'])->setProductId($product->getId())->setStoreId($product->getStoreId());
$fileStatusNew = false;
if (isset($files[0]) && $sampleModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$sampleModel->setSampleFile($files[0]['file']);
if ($files[0]['status'] == 'new') {
$fileStatusNew = true;
}
}
$sampleModel->save();
if ($sampleModel->getSampleType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE && $fileStatusNew) {
try {
Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Sample::getBaseTmpPath(), Mage_Downloadable_Model_Sample::getBasePath(), $files[0]['file']);
} catch (Exception $e) {
Mage::throwException(Mage::helper('downloadable')->__('An error occurred while saving the file(s).'));
}
}
}
}
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 = Zend_Json::decode($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());
if (null === $linkModel->getPrice()) {
$linkModel->setPrice(0);
}
if ($linkModel->getIsUnlimited()) {
$linkModel->setNumberOfDownloads(0);
}
$fileStatusNew = false;
if (isset($files[0]) && $linkModel->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$linkModel->setLinkFile($files[0]['file']);
if ($files[0]['status'] == 'new') {
$fileStatusNew = true;
}
}
$sampleFileNew = false;
if ($sample && isset($sample['type'])) {
if ($sample['type'] == 'url' && $sample['url'] != '') {
$linkModel->setSampleUrl($sample['url'])->setSampleType($sample['type']);
}
$sampleFile = Zend_Json::decode($sample['file']);
if ($sample['type'] == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE && isset($sampleFile[0])) {
$linkModel->setSampleFile($sampleFile[0]['file'])->setSampleType($sample['type']);
if ($sampleFile[0]['status'] == 'new') {
$sampleFileNew = true;
}
}
}
//.........这里部分代码省略.........
示例9: linkAction
/**
* Download link action
*/
public function linkAction()
{
$id = $this->getRequest()->getParam('id', 0);
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
$order_item_id = $linkPurchasedItem->getOrderItemId();
$checkGift = $this->checkGiftLink($order_item_id);
if (!$linkPurchasedItem->getId()) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link does not exist."));
return $this->_redirect('*/customer/products');
}
$product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
//Modification. Put already loaded product into registry so it does not need to be loaded again
//When checking for a copyright value.
Mage::register('downloadable_product', $product);
Mage::register('link_purchased_item', $linkPurchasedItem);
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 does not exist."));
//return $this->_redirect('*/customer/products');
return $this->_redirect('ecodes/account/products/');
}
}
$downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought() - $linkPurchasedItem->getNumberOfDownloadsUsed();
$status = $linkPurchasedItem->getStatus();
if ($status == 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 {
$linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed() + 1);
if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 && !($downloadsLeft - 1)) {
$linkPurchasedItem->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED);
}
$linkPurchasedItem->save();
/* Update in the volumelicense reports*/
if (Mage::helper('core')->isModuleEnabled('ICC_Volumelicense')) {
$order_id = Mage::getResourceModel('sales/order_item_collection')->addAttributeToSelect('order_id')->addAttributeToFilter('item_id', $linkPurchasedItem->getOrderItemId())->getFirstItem()->getData();
if ($order_id) {
$order = Mage::getModel("sales/order")->load($order_id);
if ($order->getData('volume_license')) {
Mage::helper('volumelicense')->setReportsLog($order, FALSE, TRUE);
unset($order);
}
}
}
/* Update in the volumelicense reports code end*/
// Ticket#2013121810000161, in case when PDF file has a huge size, we have to increase the value of NumberOfDownloadsUsed before downloading, to avoid killing the PHP script by web server by timeout
$this->_processDownload($resource, $resourceType, $checkGift);
exit(0);
} catch (Exception $e) {
$this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.'));
}
} elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link has expired.'));
} elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING || $status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW) {
$this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link is not available.'));
} else {
$this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.'));
}
//return $this->_redirect('*/customer/products');
return $this->_redirect('ecodes/account/products/');
}
示例10: addDownloads
public function addDownloads($_item_id, $new = true)
{
$model = Mage::getModel('soapsync/ibramssync');
$item_id = $model->getCollection()->returnItemId($_item_id);
$model->load($item_id);
if (!($entity_id = $model->getMageId())) {
Mage::getSingleton('adminhtml/session')->addError("Could not load product {$item_id}");
// continue;
if (!$new) {
return false;
}
}
$type = 'links';
$error = false;
if (!$new) {
Mage::helper('soapsync')->delLinks($entity_id);
}
$filePath = Mage_Downloadable_Model_Link::getBasePath();
$jpg = str_replace(array('.JPG', '.jpeg', '.JPEG', '.psd', '.gif', '.tif', '.png', '.bmp', '.BMP'), '.jpg', $model->getFilename());
if (is_file(Mage::getBaseDir('media') . DS . 'import' . DS . $jpg)) {
$uploader = new Digiswiss_File_Uploader($jpg);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
try {
$result = $uploader->save($filePath);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
Mage::helper('soapsync')->saveLinkModel($result['file'], $entity_id, $this->_capt72);
} else {
$error = true;
Mage::getSingleton('adminhtml/session')->addError("Downloadable 72dpi " . strtolower($model->getFilename()) . " not found in media/import/");
}
// if (is_file(Mage::getBaseDir('media') . DS . 'import' . DS . $this->_folder150 . DS . $jpg)) {
// $uploader = new Digiswiss_File_Uploader($jpg, $this->_folder150);
// $uploader->setAllowRenameFiles(true);
// $uploader->setFilesDispersion(true);
// try {
// $result = $uploader->save($filePath);
// } catch(Exception $e) {
// Mage::log($e->getMessage());
// }
// Mage::helper('soapsync')->saveLinkModel($result['file'], $entity_id, $this->_capt150);
// } else {
// $error = true;
// Mage::getSingleton('adminhtml/session')->addError(
// "Downloadable 150dpi " . strtolower($model->getFilename()) . " not found in $this->_folder150"
// );
// }
if (is_file(Mage::getBaseDir('media') . DS . 'import' . DS . $this->_folder300 . DS . $jpg)) {
$uploader = new Digiswiss_File_Uploader($jpg, $this->_folder300);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
try {
$result = $uploader->save($filePath);
} catch (Exception $e) {
Mage::log($e->getMessage());
}
Mage::helper('soapsync')->saveLinkModel($result['file'], $entity_id, $this->_capt300);
} else {
$error = true;
Mage::getSingleton('adminhtml/session')->addError("Downloadable 300dpi " . $jpg . " not found in {$this->_folder300}");
}
// $model->setId($item_id)->delete();
if (!$new && !$error) {
return true;
}
}
示例11: saveDownLoadProductLink
/**
* Save download product link
*
* @param array $downloadableData
* @param number $downloadProductId
* @param array $linkTpath
* @param array $slinkTpath
*
* @return void
*
*/
public function saveDownLoadProductLink($downloadableData, $downloadProductId, $linkTpath, $slinkTpath, $store)
{
/**
* Storing Downloadable product sample data
*/
foreach ($downloadableData['link'] as $linkItem) {
$linkId = '';
$linkfile = $samplefile = array();
$linkId = $linkItem['link_id'];
$linkfile = $this->assignLinkFile($linkTpath, $linkId, $linkfile);
$samplefile = $this->assignLinkFile($slinkTpath, $linkId, $samplefile);
$linkModel = Mage::getModel('downloadable/link')->setData($linkfile)->setLinkType($linkItem['type'])->setProductId($downloadProductId)->setWebsiteIds(array(Mage::app()->getStore($store)->getWebsiteId()))->setStoreId(0)->setSortOrder($linkItem['sort_order'])->setTitle($linkItem['title'])->setIsShareable($linkItem['is_shareable']);
if ($linkItem['type'] == 'url') {
$linkModel->setLinkUrl($linkItem['link_url']);
}
$linkModel->setPrice($linkItem['price']);
$linkModel->setNumberOfDownloads($linkItem['number_of_downloads']);
if (isset($linkItem['sample']['type'])) {
if ($linkItem['sample']['type'] == 'url') {
$linkModel->setSampleUrl($linkItem['sample']['url']);
}
$linkModel->setSampleType($linkItem['sample']['type']);
}
$sampleFile = '';
$sampleFile = Zend_Json::decode(json_encode($samplefile));
if (!empty($linkTpath[$linkId]) && $linkItem['type'] == 'file') {
$linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Link::getBaseTmpPath(), Mage_Downloadable_Model_Link::getBasePath(), $linkfile);
$linkModel->setLinkFile($linkFileName);
}
if (!empty($slinkTpath[$linkId]) && isset($sampleFile) && ($linkItem['sample']['type'] = 'file')) {
$linkSampleFileName = Mage::helper('downloadable/file')->moveFileFromTmp(Mage_Downloadable_Model_Link::getBaseSampleTmpPath(), Mage_Downloadable_Model_Link::getBaseSamplePath(), $sampleFile);
$linkModel->setSampleFile($linkSampleFileName);
}
Mage::helper('marketplace/marketplace')->saveDownLoadLink($linkModel);
}
}