Skip to content
Snippets Groups Projects
Commit 6ec2c348 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 1.4: Make status for download configurable; also set to shipped after download

parent 261a5e1a
No related branches found
No related tags found
No related merge requests found
BASE=downloads_for_sale
PLUGINTYPE=vmcustom
VERSION=1.3.1
VERSION=1.4
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
TRANSLATIONS=$(call wildcard,language/*/*.plg_$(PLUGINTYPE)_$(BASE).*ini)
INDEXFILES=$(BASE)/index.html language/index.html $(call wildcard,language/*/index.html)
ELEMENTS=$(call wildcard,elements/*.php) elements/index.html
TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(BASE)/index.html $(BASE)/tmpl/index.html
ASSETS=$(call wildcard,$(BASE)/assets/*.png) $(call wildcard,$(BASE)/assets/*.css) $(BASE)/assets/index.html
ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip
......
......@@ -27,7 +27,6 @@ if (JVM_VERSION === 2) {
}
class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
var $status_allowed = array ('S', 'C');
function __construct(& $subject, $config) {
parent::__construct($subject, $config);
......@@ -38,6 +37,8 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
'invoice_link_type'=>array('text', 'char'),
'product_link_type'=>array('image','char'),
'download_type'=>array('free_download','char'),
'paid_status'=>array(array('S', 'C'), 'array'),
'downloaded_status'=>array('S', 'char'),
);
$this->setConfigParameterable('custom_params',$varsToPush);
$this->onStoreInstallPluginTable($this->_psType);
......@@ -94,10 +95,10 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
}
$orderitems = array();
foreach ($orders as $order) {
if ($order && in_array($order['details']['BT']->order_status, $this->status_allowed)) {
if ($order && in_array($order['details']['BT']->order_status, $field->paid_status)) {
foreach ($order['items'] as $i) {
if ($i->virtuemart_product_id == $prodid) {
if (in_array($i->order_status, $this->status_allowed)) {
if (in_array($i->order_status, $field->paid_status)) {
$orderitems[] = $i;
} elseif ($show_warnings) {
JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_STATUS_NOT_AUTHORIZED'), 'error');
......@@ -121,7 +122,7 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
return ($userId>0);
}
// In all other cases, check that the orderitem has the correct state
if ($orderitem && in_array($orderitem->order_status, $this->status_allowed)) {
if ($orderitem && in_array($orderitem->order_status, $field->paid_status)) {
return true;
}
return false;
......@@ -153,16 +154,18 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
}
header("Content-Type: " . $media->file_mimetype);
header("Content-Disposition: attachment; filename=\"".JFile::getName($media->file_url)."\"");
if (!@readfile($media->file_url)) {
if (@readfile($media->file_url)) {
return true;
} else {
header_remove("Content-Type");
header_remove("Content-Disposition");
JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_DLSALE_ERROR_NO_FILE_SET', $media_id, $media->file_url), 'error');
return false;
}
JExit();
} else {
$output = JText::_('VMCUSTOM_DLSALE_NO_FILE_FOUND');
}
return false;
}
......@@ -192,6 +195,20 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
}
}
function updateOrderStatus ($field, $orderitem) {
if (!$orderitem) return;
$orderModel = VmModel::getModel('orders');
# Update the whole order:
$order = $this->orderDataFromItem ($orderitem->virtuemart_order_item_id);
$orderdata['order_status'] = $field->downloaded_status;
$orderdata['customer_notified'] = 0;
$orderdata['comments'] = '';
if ($order->order_status != $orderdata['order_status']) {
$orderModel->updateStatusForOneOrder($order->virtuemart_order_id, $orderdata, /*triggers=*/false);
}
}
function plgVmOnSelfCallFE($type,$name,&$render) {
if ($name != $this->_name || $type != 'vmcustom') return false;
......@@ -206,11 +223,15 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
$orderitem = empty($orderitems)?null:$orderitems[0];
if ($field) {
if ($this->checkDownloadable ($field, $orderitem, true)) {
// TODO: Update download counter in the mysql table
$this->updateDownloadCounterSQL ($field, $orderitem);
$handled = true;
$this->downloadFile ($field->media_id, $render);
return true;
if ($this->downloadFile ($field->media_id, $render)) {
// Successful download, so set order status to shipped, then exit to prevent the normal joomla page formatting (we sent a potentially binary file already!)
$this->updateDownloadCounterSQL ($field, $orderitem);
$this->updateOrderStatus ($field, $orderitem);
JExit();
} else {
return true;
}
} else {
// JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED_UNKNOWN'), 'error');
}
......@@ -259,10 +280,6 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
$orderdownloads = array();
foreach ($orders as $order) {
if (!in_array($order['details']['BT']->order_status, $this->status_allowed)) {
// Order status does not allow a download in any case, so skip this order
continue;
}
$orderinfo = $order;
$orderinfo['download_products']=array();
foreach ($order['items'] as $i) {
......@@ -270,7 +287,8 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
$productinfo->downloads = array();
$customs = (array)$customModel->getproductCustomslist ($i->virtuemart_product_id);
foreach ($customs as $field) {
if (($field->custom_element == $this->_name) && ($this->checkDownloadable ($field, $i, false))) {
// Order needs to be downloadable and the individiaul field, too:
if (($field->custom_element == $this->_name) && in_array($order['details']['BT']->order_status, $field->paid_status) && ($this->checkDownloadable ($field, $i, false))) {
$productinfo->downloads[] = $this->createDownloadLink ($field, 'order', $field->invoice_link_type, $i);
}
}
......@@ -362,7 +380,7 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
foreach ($orderModel->getOrdersList($cuid, true) as $ol) {
$o = $orderModel->getOrder($ol->virtuemart_order_id);
foreach ($o['items'] as $i) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id && in_array($i->order_status, $this->status_allowed)) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id && in_array($i->order_status, $field->paid_status)) {
$order = $o['details']['BT'];
}
}
......
......@@ -6,7 +6,7 @@
<authorUrl>http://www.open-tools.net/</authorUrl>
<copyright>Copyright (C) 2013 Reinhold Kainhofer. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license>
<version>1.3.1</version>
<version>1.4</version>
<description>VMCUSTOM_DLSALE_DESC</description>
<files>
<filename plugin="downloads_for_sale">downloads_for_sale.php</filename>
......@@ -14,6 +14,7 @@
<folder>downloads_for_sale</folder>
<folder>language</folder>
<filename>index.html</filename>
<folder>elements</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini</language>
......@@ -22,6 +23,7 @@
<language tag="de-DE">de-DE/de-DE.plg_vmcustom_downloads_for_sale.sys.ini</language>
</languages>
<scriptfile>downloads_for_sale.script.php</scriptfile>
<params addpath="/plugins/vmcustom/downloads_for_sale/elements" />
<params addpath="/administrator/components/com_virtuemart/elements">
<param type="vmjpluginwarning" />
<param name="invoice_link_type" type="list" default="link" label="VMCUSTOM_DLSALE_INVOICE_LINK" description="VMCUSTOM_DLSALE_INVOICE_LINK_DESC" >
......@@ -39,5 +41,7 @@
<option value="registered_download">VMCUSTOM_DLSALE_TYPE_REGISTERED</option>
<option value="paid_download">VMCUSTOM_DLSALE_TYPE_PAID</option>
</param>
<param name="paid_status" type="vmorderstates" scope="com_virtuemart" default="C" label="VMCUSTOM_DLSALE_STATUS_PAID" description="VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN" />
<param name="downloaded_status" type="vmorderstate" scope="com_virtuemart" default="S" label="VMCUSTOM_DLSALE_STATUS_DOWNLOADED" description="VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN" />
</params>
</install>
<?php
defined ('_JEXEC') or die();
/**
*
* @package VirtueMart
* @subpackage Plugins - Elements
* @author Valérie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id:$
*/
/*
* This class is used by VirtueMart Payment or Shipment Plugins
* which uses JParameter
* So It should be an extension of JElement
* Those plugins cannot be configured througth the Plugin Manager anyway.
*/
class JElementVmOrderStates extends JElement {
/**
* Element name
*
* @access protected
* @var string
*/
var $_name = 'OrderStates';
function fetchElement ($name, $value, &$node, $control_name) {
$db = JFactory::getDBO ();
$query = 'SELECT `order_status_code` AS value, `order_status_name` AS text
FROM `#__virtuemart_orderstates`
WHERE `virtuemart_vendor_id` = 1
ORDER BY `ordering` ASC ';
$db->setQuery ($query);
$fields = $db->loadObjectList ();
$class = 'class="inputbox" multiple="multiple" size="6" ';
foreach ($fields as $field) {
$field->text= JText::_ ($field->text);
}
return JHTML::_ ('select.genericlist', $fields, $control_name . '[' . $name . '][]', $class, 'value', 'text', $value, $control_name . $name);
}
}
......@@ -21,6 +21,11 @@ VMCUSTOM_DLSALE_TYPE_FREE="Kostenloser Download"
VMCUSTOM_DLSALE_TYPE_REGISTERED="Download nur nach Registrierung"
VMCUSTOM_DLSALE_TYPE_PAID="Bezahlter Download"
VMCUSTOM_DLSALE_STATUS_PAID="Status um bezahlte Download verfügbar zu machen"
VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN="Wählen sie die Liste der Statuswerte aus, wann bezahlte Downloads zur Verfügung gestellt werden."
VMCUSTOM_DLSALE_STATUS_DOWNLOADED="Status nach Download"
VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN="Nach einem bezahlten Download wird der Status der Bestellung auf diesen Wert gesetzt."
VMCUSTOM_DLSALE_NO_FILES="Keine Mediendatein für den Download oder Verkauf gefunden."
VMCUSTOM_DLSALE_DOWNLOAD_FILE="Datei zum Download"
VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED="Nicht zum Download authorisiert. Bitte loggen Sie sich als entsprechender Benutzer ein."
......
......@@ -21,6 +21,11 @@ VMCUSTOM_DLSALE_TYPE_FREE="Free download"
VMCUSTOM_DLSALE_TYPE_REGISTERED="Download after registration"
VMCUSTOM_DLSALE_TYPE_PAID="Paid download"
VMCUSTOM_DLSALE_STATUS_PAID="Status to enable paid download"
VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN="Select the statuses for paid downloads that allow the buyer to download the file."
VMCUSTOM_DLSALE_STATUS_DOWNLOADED="Status after download"
VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN="After a file was downloaded through this plugin, the order status will be set to this value, indication a download was initiated by the user."
VMCUSTOM_DLSALE_NO_FILES="No media files found for download or sale."
VMCUSTOM_DLSALE_DOWNLOAD_FILE="Download file"
VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED="Not authorized to download. Please log in."
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment