Commit 507d206a authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V5.99: Automatic updates, Library factorization, prices on VM2

parent 1ec7d505
......@@ -2,16 +2,17 @@ BASE=rules_shipping
BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment
ZIPBASE=opentools_vm
VERSION=6.0
VERSION=5.99
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE).script.php $(BASE).xml index.html
PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE)_framework_joomla.php $(BASE).script.php $(BASE).xml index.html
PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE)_framework_joomla.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
TRANSLATIONS=$(call wildcard,language/en*/*.plg_$(PLUGINTYPE)_$(BASE).*ini)
TRANSLATIONS_ADV=$(subst $(BASE),$(BASE_ADV),$(TRANSLATIONS))
INDEXFILES=language/index.html $(call wildcard,language/**/index.html) $(call wildcard,elements/*.html)
ELEMENTS=$(call wildcard,elements/*.php)
FIELDS=$(call wildcard,fields/*.php)
LIBRARY=library/
ZIPFILE=plg_$(ZIPBASE)_$(BASE)_v$(VERSION).zip
ZIPFILE_ADV=plg_$(ZIPBASE)_$(BASE_ADV)_v$(VERSION).zip
......@@ -28,8 +29,8 @@ translations: $(TRANSLATIONS)
zip: $(PLUGINFILES) $(TRANSLATIONS) $(ADVANCEDFILES)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(ELEMENTS) $(FIELDS) $(INDEXFILES) LICENSE.txt
@zip -r $(ZIPFILE_ADV) $(PLUGINFILES_ADV) $(TRANSLATIONS_ADV) $(ELEMENTS) $(FIELDS) $(INDEXFILES) LICENSE.txt
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(ELEMENTS) $(FIELDS) $(LIBRARY) $(INDEXFILES) LICENSE.txt
@zip -r $(ZIPFILE_ADV) $(PLUGINFILES_ADV) $(TRANSLATIONS_ADV) $(ELEMENTS) $(FIELDS) $(LIBRARY) $(INDEXFILES) LICENSE.txt
clean:
rm -f $(ZIPFILE) $(ZIPFILE_ADV)
<?php
defined('_JEXEC') or die();
/**
*
* @package VirtueMart
* @subpackage Plugins - Fields
* @author Reinhold Kainhofer, Open Tools
* @link http://www.open-tools.net
* @copyright Copyright (c) 2016 Reinhold Kainhofer. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* 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.
*/
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
if (!class_exists( 'VmConfig' ))
require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
class JFormFieldVmUpdateCredentialsCheck extends JFormField {
var $_name = 'vmUpdateCredentialsCheck';
// VM2 on J2 works, VM3 on J3 works out of the box, but
// VM3 on J2 does NOT work by simply calling vmJsApi::jQuery, because
// the JS is never added to the page header, so we have to add this manually
public function loadjQuery() {
vmJsApi::jQuery();
// TODO: jquery::ui available only in J3:
if (version_compare(JVERSION, '3.0', 'lt')) {
} else {
JHtml::_('jquery.ui', array('core', 'sortable'));
}
// If we are on Joomla 2.5 and VM 3, manually add the script declarations
// cached in vmJsApi to the document header:
if (version_compare(JVERSION, '3.0', 'lt') && defined('VM_VERSION') && VM_VERSION>=3) {
$document = JFactory::getDocument();
$scripts = vmJsApi::getJScripts();
foreach ($scripts as $name => $jsToAdd) {
if($jsToAdd['written']) continue;
$file = $jsToAdd['script'] ? $jsToAdd['script'] : $name;
if(strpos($file,'/')!==0){
$file = vmJsApi::setPath($file,false,'');
} else if(strpos($file,'//')!==0){
$file = JURI::root(true).$file;
}
$ver = '';
if(!empty($jsToAdd['ver'])) $ver = '?vmver='.$jsToAdd['ver'];
$document->addScript( $file .$ver,"text/javascript",$jsToAdd['defer'],$jsToAdd['async'] );
vmJsApi::removeJScript($name);
}
}
}
protected function getJavaScript() {
return "
var credentials_ajaxurl = \"".$this->element["ajaxurl"]."\";
var credentials_updateMessages = function(messages, area) {
jQuery( \"#system-message-container #system-message .\"+area+\"-message\").remove();
var newmessages = jQuery( messages ).find(\"div.alert, .message\").addClass(area+\"-message\");
if (!jQuery( \"#system-message-container #system-message\").length && newmessages.length) {
if (jQuery(newmessages).first().prop(\"tagName\")==\"dt\") { // Joomla 2.x:
jQuery( \"#system-message-container\" ).append( \"<dl id=\'system-message\'></div>\" );
} else {
jQuery( \"#system-message-container\" ).append( \"<div id=\'system-message\'></div>\" );
}
}
newmessages.appendTo( \"#system-message-container #system-message\");
};
var checkUpdateCredentialsError = function() {
alert (\"".JText::_('OPENTOOLS_CHECK_CREDENTIALS_ERROR')."\");
}
var checkUpdateCredentials = function () {
var ordernumber = jQuery('#jform_params_order_number').val();
var orderpass = jQuery('#jform_params_order_pass').val();
var ajaxargs = {
type: \"POST\",
dataType: \"text\",
url: credentials_ajaxurl,
data: {
action: \"check_update_access\",
order_number: ordernumber,
order_pass: orderpass
},
success: function ( json ) {
try {
json = jQuery.parseJSON(json);
credentials_updateMessages(json['messages'], 'ordernumber');
} catch (e) {
checkUpdateCredentialsError();
return;
}
var success=0;
if (json.success>0) {
success=1;
}
jQuery('#update_credentials_hidden_checked').val(success);
jQuery('.credentials_checked')
.removeClass('credentials_checked_0')
.removeClass('credentials_checked_1')
.addClass('credentials_checked_'+success);
},
error: function() { checkUpdateCredentialsError(); },
complete: function() { },
};
jQuery.ajax(ajaxargs);
};
jQuery(document).ready (function () {
jQuery('#jform_params_order_number').focusout(checkUpdateCredentials);
jQuery('#jform_params_order_pass').focusout(checkUpdateCredentials);
});
";
}
protected function getCSS() {
return "
div.credentials_checked {
padding: 10px 5px;
float: left;
clear: left;
display: block;
width: 100%;
}
div.credentials_checked_0 {
background-color: #FFD0D0;
}
div.credentials_checked_1 {
background-color: #D0FFD0;
}
a#credentials_check {
}
";
}
protected function getInput() {
// Tell the user that automatic updates are not available in Joomla 2.5:
if (version_compare(JVERSION, '3.0', 'lt')) {
JFactory::getApplication()->enqueueMessage(JText::_('OPENTOOLS_COMMERCIAL_UPDATES_J25'), 'warning');
}
$this->loadjQuery();
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($this->getJavaScript());
$doc->addStyleDeclaration($this->getCSS());
if ($this->value!=1) {
$this->value=0;
}
// if ($this->value==1) {
return "<input type='hidden' id=\"update_credentials_hidden_checked\" name='".$this->name."' value='".$this->value."' /><div class='credentials_checked credentials_checked_".$this->value."'><a href=\"#\" class=\"btn btn-info credentials_check\" id=\"credentials_check\" onclick=\"checkUpdateCredentials()\" >".JText::_('OPENTOOLS_CHECK_CREDENTIALS')."</a></div>";
}
}
......@@ -56,10 +56,14 @@ VMSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY="Definition of custom functions (return
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED="Custom function %s already defined. Ignoring this definition and using previous one."
VMSHIPMENT_RULES_FIELDSET_CREDENTIALS="Automatische Aktualisierung"
VMSHIPMENT_RULES_CREDENTIALS_DESC="Bitte geben Sie hier die Bestellungsnummer und -passwort ein, die Sie in der Bestellbestätigung (per Mail) von <a href="https://www.open-tools.net/">open-tools.net</a> erhalten haben. Wird keine gültige Kombination eingegeben, ist die Funktionalität der Erweiterung in keiner Weise eingeschränkt, jedoch stehen keine automatischen Aktualisierungen zur Verfügung."
VMSHIPMENT_RULES_ORDERNUMBER="Bestellungsnummer (lt. Rechnung):"
VMSHIPMENT_RULES_ORDERNUMBER_DESC="Bitte geben Sie hier die Bestellungsnummer Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
VMSHIPMENT_RULES_ORDERPASS="Bestellungspassword (lt. Rechnung):"
VMSHIPMENT_RULES_ORDERPASS_DESC="Bitte geben Sie hier das Bestellungspasswort Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_FIELDSET_CREDENTIALS="Automatische Aktualisierung"
OPENTOOLS_CREDENTIALS_DESC="Bitte geben Sie hier die Bestellungsnummer und -passwort ein, die Sie in der Bestellbestätigung (per Mail) von <a href="https://www.open-tools.net/">open-tools.net</a> erhalten haben. Wird keine gültige Kombination eingegeben, ist die Funktionalität der Erweiterung in keiner Weise eingeschränkt, jedoch stehen keine automatischen Aktualisierungen zur Verfügung."
OPENTOOLS_ORDERNUMBER="Bestellungsnummer:"
OPENTOOLS_ORDERNUMBER_DESC="Bitte geben Sie hier die Bestellungsnummer Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_ORDERPASS="Bestellungspassword:"
OPENTOOLS_ORDERPASS_DESC="Bitte geben Sie hier das Bestellungspasswort Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_CHECK_CREDENTIALS="Zugangsdaten überprüfen und speichern"
OPENTOOLS_CHECK_CREDENTIALS_ERROR="Konnte Zugangsdaten nicht überprüfen. Bitte stellen Sie sicher, dass die Erweiterung in Joomla freigegeben ist!"
OPENTOOLS_XMLMANIFEST_ERROR="Konnte die XML-Manifest-Datei der Erweiterung nicht laden (%s)"
OPENTOOLS_UPDATESCRIPT_ERROR="Konnte die Aktualisierungsinformationen nicht laden (%s)"
OPENTOOLS_COMMERCIAL_UPDATES_J25="Automatische Aktualisierungen von kommerziellen Erweiterungen sind in Joomla 2.5 leider nicht möglich (erste ab Joomla 3.x). Bitte informieren Sie sich auf der Homepage des Entwicklers über mögliche Aktualisierungen und installieren Sie diese manuell."
......@@ -46,10 +46,14 @@ VMSHIPMENT_RULES_EVALUATE_ASSIGNMENT_TOPLEVEL="Assignments are not allows inside
VMSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE="Evaluation yields unknown value while evaluating rule part '%s'."
VMSHIPMENT_RULES_FIELDSET_CREDENTIALS="Automatische Aktualisierung"
VMSHIPMENT_RULES_CREDENTIALS_DESC="Bitte geben Sie hier die Bestellungsnummer und -passwort ein, die Sie in der Bestellbestätigung (per Mail) von <a href="https://www.open-tools.net/">open-tools.net</a> erhalten haben. Wird keine gültige Kombination eingegeben, ist die Funktionalität der Erweiterung in keiner Weise eingeschränkt, jedoch stehen keine automatischen Aktualisierungen zur Verfügung."
VMSHIPMENT_RULES_ORDERNUMBER="Bestellungsnummer (lt. Rechnung):"
VMSHIPMENT_RULES_ORDERNUMBER_DESC="Bitte geben Sie hier die Bestellungsnummer Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
VMSHIPMENT_RULES_ORDERPASS="Bestellungspassword (lt. Rechnung):"
VMSHIPMENT_RULES_ORDERPASS_DESC="Bitte geben Sie hier das Bestellungspasswort Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_FIELDSET_CREDENTIALS="Automatische Aktualisierung"
OPENTOOLS_CREDENTIALS_DESC="Bitte geben Sie hier die Bestellungsnummer und -passwort ein, die Sie in der Bestellbestätigung (per Mail) von <a href="https://www.open-tools.net/">open-tools.net</a> erhalten haben. Wird keine gültige Kombination eingegeben, ist die Funktionalität der Erweiterung in keiner Weise eingeschränkt, jedoch stehen keine automatischen Aktualisierungen zur Verfügung."
OPENTOOLS_ORDERNUMBER="Bestellungsnummer:"
OPENTOOLS_ORDERNUMBER_DESC="Bitte geben Sie hier die Bestellungsnummer Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_ORDERPASS="Bestellungspassword:"
OPENTOOLS_ORDERPASS_DESC="Bitte geben Sie hier das Bestellungspasswort Ihres Kaufs der Erweiterung auf open-tools.net an. Wenn keine gültige Kombination aus Bestellungsnummer und -passwort angegeben wird, funktioniert die Erweiterung dennoch, jedoch sind keine automatischen Aktualisierungen möglich."
OPENTOOLS_CHECK_CREDENTIALS="Zugangsdaten überprüfen und speichern"
OPENTOOLS_CHECK_CREDENTIALS_ERROR="Konnte Zugangsdaten nicht überprüfen. Bitte stellen Sie sicher, dass die Erweiterung in Joomla freigegeben ist!"
OPENTOOLS_XMLMANIFEST_ERROR="Konnte die XML-Manifest-Datei der Erweiterung nicht laden (%s)"
OPENTOOLS_UPDATESCRIPT_ERROR="Konnte die Aktualisierungsinformationen nicht laden (%s)"
OPENTOOLS_COMMERCIAL_UPDATES_J25="Automatische Aktualisierungen von kommerziellen Erweiterungen sind in Joomla 2.5 leider nicht möglich (erste ab Joomla 3.x). Bitte informieren Sie sich auf der Homepage des Entwicklers über mögliche Aktualisierungen und installieren Sie diese manuell."
......@@ -67,10 +67,15 @@ VMSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY="Definition of custom functions (return
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED="Custom function %s already defined. Ignoring this definition and using previous one."
VMSHIPMENT_RULES_FIELDSET_CREDENTIALS="Update credentials"
VMSHIPMENT_RULES_CREDENTIALS_DESC="Please enter your order number and the order password, which can be found in the order confirmation mail you received after your purchase at <a href="https://www.open-tools.net/">open-tools.net</a>. If you do not enter a valid combination, the plugin will continue to work, but automatic updates will only be provided with a valid order number and password."
VMSHIPMENT_RULES_ORDERNUMBER="Order number (see order confirmation mail):"
VMSHIPMENT_RULES_ORDERNUMBER_DESC="Please enter the order number of your purchase at open-tools.net to get access to automatic updates. If no valid order number and password is entered, the plugin will still work, but automatic updates will not be available."
VMSHIPMENT_RULES_ORDERPASS="Order password (see order confirmation mail):"
VMSHIPMENT_RULES_ORDERPASS_DESC="Please enter the order password of your purchase at open-tools.net to get access to automatic updates. If no valid order number and password is entered, the plugin will still work, but automatic updates will not be available."
OPENTOOLS_FIELDSET_CREDENTIALS="Update credentials"
OPENTOOLS_CREDENTIALS_DESC="Please enter your order number and the order password, which can be found in the order confirmation mail you received after your purchase at <a href="https://www.open-tools.net/">open-tools.net</a>. If you do not enter a valid combination, the plugin will continue to work, but automatic updates will only be provided with a valid order number and password."
OPENTOOLS_ORDERNUMBER="Order number:"
OPENTOOLS_ORDERNUMBER_DESC="Please enter the order number of your purchase at open-tools.net to get access to automatic updates. If no valid order number and password is entered, the plugin will still work, but automatic updates will not be available."
OPENTOOLS_ORDERPASS="Order password:"
OPENTOOLS_ORDERPASS_DESC="Please enter the order password of your purchase at open-tools.net to get access to automatic updates. If no valid order number and password is entered, the plugin will still work, but automatic updates will not be available."
OPENTOOLS_CHECK_CREDENTIALS="Check and save update credentials"
OPENTOOLS_CHECK_CREDENTIALS_ERROR="Unable to check the download credentials. Please make sure that the plugin is enabled in your Joomla installation!"
OPENTOOLS_XMLMANIFEST_ERROR="Unable to load the plugin manifest file (%s)"
OPENTOOLS_UPDATESCRIPT_ERROR="Unable to load the update information from the update server (%s)"
OPENTOOLS_COMMERCIAL_UPDATES_J25="Automatic updates of commercial Joomla extensions are not available in Joomla 2.5 (only in Joomla 3.x). Please check the software developer's homepage and manually install updates."
......@@ -6,12 +6,14 @@
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013-2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>6.0</version>
<version>5.99</version>
<description>OTSHIPMENT_RULES_DESC</description>
<files>
<filename plugin="rules_shipping">rules_shipping.php</filename>
<filename>rules_shipping_base.php</filename>
<filename>rules_shipping_framework_joomla.php</filename>
<folder>language</folder>
<folder>library</folder>
<folder>elements</folder>
<folder>fields</folder>
</files>
......@@ -148,7 +150,7 @@
</params>
<updateservers>
<server type="extension" name="VM Shipping by Rules Updates"><![CDATA[http://open-tools.net/UpdateServer/index.php?package=Joomla&amp;extension=ShippingByRules]]></server>
<server type="extension" name="VM Shipping by Rules Updates"><![CDATA[http://open-tools.net/UpdateServer/index.php?package=Joomla&amp;extension=ShippingByRules&amp;file=extension.xml]]></server>
</updateservers>
</extension>
......@@ -79,4 +79,201 @@ class plgVmShipmentRules_Shipping_Advanced extends plgVmShipmentRules_Shipping_B
// print("<pre>values: ".print_r($values,1)."</pre>");
}
/**
* plgVmOnSelfCallBE ... Called to execute some plugin action in the backend (e.g. set/reset dl counter, show statistics etc.)
*/
function plgVmOnSelfCallBE($type, $name, &$output) {
if ($name != $this->_name || $type != $this->_type) return false;
vmDebug('plgVmOnSelfCallBE');
$user = JFactory::getUser();
$authorized = ($user->authorise('core.admin','com_virtuemart') or
$user->authorise('core.manage','com_virtuemart') or
$user->authorise('vm.orders','com_virtuemart'));
$json = array();
$json['authorized'] = $authorized;
if (!$authorized) return FALSE;
$action = vRequest::getCmd('action');
$json['action'] = $action;
$json['success'] = 0; // default: unsuccessfull
switch ($action) {
case "check_update_access":
$order_number = vRequest::getString('order_number');
$order_pass = vRequest::getString('order_pass');
$json = $this->checkUpdateAccess($order_number, $order_pass, $json);
break;
}
// Also return all messages (in HTML format!):
// Since we are in a JSON document, we have to temporarily switch the type to HTML
// to make sure the html renderer is actually used
$document = JFactory::getDocument ();
$previoustype = $document->getType();
$document->setType('html');
$msgrenderer = $document->loadRenderer('message');
$json['messages'] = $msgrenderer->render('Message');
$document->setType($previoustype);
// WORKAROUND for broken (i.e. duplicate) content-disposition headers in Joomla 2.x:
// We request everything in raw and here send the headers for JSON and return
// the raw output in json format
$document =JFactory::getDocument();
$document->setMimeEncoding('application/json');
JResponse::setHeader('Content-Disposition','attachment;filename="opentools_update_access.json"');
$output = json_encode($json);
}
public function checkUpdateAccess($order_number, $order_pass, $json = array()) {
// First, extract the update server URL from the manifest, then load
// the update XML from the update server, extract the download URL,
// append the order number and password and check whether access is
// possible.
$json['success'] = FALSE;
$xml = simplexml_load_file($this->_xmlFile);
if (!$xml || !isset($xml->updateservers)) {
JFactory::getApplication()->enqueueMessage(JText::sprintf('OPENTOOLS_XMLMANIFEST_ERROR', $this->_xmlFile), 'error');
return $json;
}
$updateservers = $xml->updateservers;
foreach ($updateservers->children() as $server) {
if ($server->getName()!='server') {
JFactory::getApplication()->enqueueMessage(JText::sprintf('OPENTOOLS_XMLMANIFEST_ERROR', $this->_xmlFile), 'error');
continue;
}
$updateurl = html_entity_decode((string)$server);
$updatescript = simplexml_load_file($updateurl);
if (!$updatescript) {
JFactory::getApplication()->enqueueMessage(JText::sprintf('OPENTOOLS_UPDATESCRIPT_ERROR', $updateurl), 'error');
continue;
}
$urls = $updatescript->xpath('/updates/update/downloads/downloadurl');
while (list( , $node) = each($urls)) {
$downloadurl = (string)($node);
if ($order_number) {
$downloadurl .= (parse_url($downloadurl, PHP_URL_QUERY) ? '&' : '?') . 'order_number=' . urlencode($order_number);
}
if ($order_pass) {
$downloadurl .= (parse_url($downloadurl, PHP_URL_QUERY) ? '&' : '?') . 'order_pass=' . urlencode($order_pass);
}
$downloadurl .= (parse_url($downloadurl, PHP_URL_QUERY) ? '&' : '?') . 'check_access=1';
$headers = get_headers($downloadurl);
list($version, $status_code, $msg) = explode(' ',$headers[0], 3);
// Check the HTTP Status code
switch($status_code) {
case 200:
$json['success'] = TRUE;
JFactory::getApplication()->enqueueMessage($msg, 'message');
$this->setupUpdateCredentials($order_number, $order_pass);
break;
default:
JFactory::getApplication()->enqueueMessage($msg, 'error');
// Clear the credentials...
$this->setupUpdateCredentials("", "");
break;
}
$this->setAndSaveParams(array(
'update_credentials_checked'=>$json['success'],
'order_number' => $order_number,
'order_pass' => $order_pass,
));
}
}
return $json;
}
protected function setAndSaveParams($params) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('extension_id')
->from('#__extensions')
->where('folder = '.$db->quote($this->_type))
->where('element = '.$db->quote($this->_name))
->where('type =' . $db->quote('plugin'))
->order('ordering');
$plugin = $db->setQuery($query)->loadObject();
if (!$plugin)
return;
$pluginId=$plugin->extension_id;
foreach ($params as $param=>$parvalue) {
$this->params->set($param, $parvalue);
}
$extensions = JTable::getInstance('extension');
$extensions->load($pluginId);
$extensions->bind(array('params' => $this->params->toString()));
// check and store
if (!$extensions->check()) {
$this->setError($extensions->getError());
return false;
}
if (!$extensions->store()) {
$this->setError($extensions->getError());
return false;
}
}
function setupUpdateCredentials($ordernumber, $orderpass) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('extension_id AS id')
->from('#__extensions')
->where('folder = '.$db->quote($this->_type))
->where('element = '.$db->quote($this->_name))
->where('type =' . $db->quote('plugin'))
->order('ordering');
$plugin = $db->setQuery($query)->loadObject();
if (empty($plugin))
return;
$ordernumber = preg_replace("/[^-A-Za-z0-9_]/", '', $ordernumber);
$orderpass = preg_replace("/[^-A-Za-z0-9_]/", '', $orderpass);
$extra_query = array();
if ($ordernumber!='') {
$extra_query[] = 'order_number='.preg_replace("/[^-A-Za-z0-9_]/", '', $ordernumber);
}
if ($orderpass!='') {
$extra_query[] = 'order_pass='.preg_replace("/[^-A-Za-z0-9_]/", '', $orderpass);
}
$extra_query = implode('&amp;', $extra_query);
// The following code is based on Nicholas K. Dionysopoulos' Joomla Pull request:
// https://github.com/joomla/joomla-cms/pull/2508
// Load the update site record, if it exists
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('update_site_id AS id')
->from($db->qn('#__update_sites_extensions'))
->where($db->qn('extension_id').' = '.$db->q($plugin->id));
$db->setQuery($query);
$updateSites = $db->loadObjectList();
foreach ($updateSites as $updateSite) {
// Update the update site record
$query = $db->getQuery(true)
->update($db->qn('#__update_sites'))
->set('extra_query = '.$db->q($extra_query))
->set('last_check_timestamp = 0')
->where($db->qn('update_site_id').' = '.$db->q($updateSite->id));
$db->setQuery($query);
$db->execute();
// Delete any existing updates (essentially flushes the updates cache for this update site)
$query = $db->getQuery(true)
->delete($db->qn('#__updates'))
->where($db->qn('update_site_id').' = '.$db->q($updateSite->id));
$db->setQuery($query);
$db->execute();
}
}
}
......@@ -6,12 +6,14 @@
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013-2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>6.0</version>
<version>5.99</version>
<description>OTSHIPMENT_RULES_ADV_DESC</description>
<files>
<filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename>
<filename>rules_shipping_base.php</filename>
<filename>rules_shipping_framework_joomla.php</filename>
<folder>language</folder>
<folder>library</folder>
<folder>elements</folder>
<folder>fields</folder>
</files>
......@@ -149,15 +151,16 @@
<config>
<fields name="params">
<fieldset name="update_credentials" label="VMSHIPMENT_RULES_FIELDSET_CREDENTIALS">
<field name="credentials_desc" type="spacer" label="VMSHIPMENT_RULES_CREDENTIALS_DESC" />
<field name="order_number" type="text" default="" label="VMSHIPMENT_RULES_ORDERNUMBER" description="VMSHIPMENT_RULES_ORDERNUMBER_DESC"/>
<field name="order_pass" type="text" default="" label="VMSHIPMENT_RULES_ORDERPASS" description="VMSHIPMENT_RULES_ORDERPASS_DESC"/>
<fieldset name="update_credentials" label="OPENTOOLS_FIELDSET_CREDENTIALS" addfieldpath="/plugins/vmshipment/rules_shipping_advanced/fields">
<field name="credentials_desc" type="spacer" label="OPENTOOLS_CREDENTIALS_DESC" />
<field name="order_number" type="text" default="" label="OPENTOOLS_ORDERNUMBER" description="OPENTOOLS_ORDERNUMBER_DESC"/>
<field name="order_pass" type="text" default="" label="OPENTOOLS_ORDERPASS" description="OPENTOOLS_ORDERPASS_DESC"/>
<field name="update_credentials_checked" type="vmUpdateCredentialsCheck" label="" ajaxurl="index.php?option=com_virtuemart&amp;view=plugin&amp;type=vmshipment&amp;name=rules_shipping_advanced&amp;format=raw" />
</fieldset>
</fields>
</fields>
</config>
<updateservers>
<server type="extension" name="VM Advanced Shipping by Rules Updates"><![CDATA[http://open-tools.net/UpdateServer/index.php?package=Joomla&amp;extension=AdvancedShippingByRules]]></server>
<server type="extension" name="VM Advanced Shipping by Rules Updates"><![CDATA[http://open-tools.net/UpdateServer/index.php?package=Joomla&amp;extension=AdvancedShippingByRules&amp;file=extension.xml]]></server>
</updateservers>
</extension>
......@@ -98,7 +98,7 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
* - getOrderDimensions
*/
/** Functions to calculate all the different variables for the given cart and given (sub)set of products in the cart */
protected function getOrderCounts (VirtueMartCart $cart, $products, $method) {
protected function getOrderCounts ($cart, $products, $method) {
$counts = array(
'articles' => 0,
'products' => count($products),
......@@ -292,17 +292,23 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
// Calculate the prices from the individual products!
// Possible problems are discounts on the order total
foreach ($products as $product) {
$data['amount'] += $product->quantity*$product->allPrices[$product->selectedPrice]['salesPrice'];
$data['amountwithtax'] += $product->quantity*$product->allPrices[$product->selectedPrice]['salesPrice'];
$data['amountwithouttax'] += $product->quantity*$product->allPrices[$product->selectedPrice]['priceWithoutTax'];
$data['baseprice'] += $product->quantity*$product->allPrices[$product->selectedPrice]['basePrice'];
$data['basepricewithtax'] += $product->quantity*$product->allPrices[$product->selectedPrice]['basePriceWithTax'];
$data['discountedpricewithouttax'] += $product->quantity*$product->allPrices[$product->selectedPrice]['discountedPriceWithoutTax'];
$data['salesprice'] += $product->quantity*$product->allPrices[$product->selectedPrice]['salesPrice'];
$data['taxamount'] += $product->quantity*$product->allPrices[$product->selectedPrice]['taxAmount'];
$data['salespricewithdiscount'] += $product->quantity*$product->allPrices[$product->selectedPrice]['salesPriceWithDiscount'];
$data['discountamount'] += $product->quantity*$product->allPrices[$product->selectedPrice]['discountAmount'];
$data['pricewithouttax'] += $product->quantity*$product->allPrices[$product->selectedPrice]['priceWithoutTax'];
// $prices = isset($product->allPrices)?($product->allPrices[$product->selectedPrice]):($product->prices);
$prices = $product->prices;
$quant = $product->quantity;
$data['amount'] += $quant * $prices['salesPrice'];
$data['amountwithtax'] += $quant * $prices['salesPrice'];
$data['amountwithouttax'] += $quant * $prices['priceWithoutTax'];
$data['baseprice'] += $quant * $prices['basePrice'];
$data['basepricewithtax'] += $quant * $prices['basePriceWithTax'];
$data['discountedpricewithouttax'] += $quant * $prices['discountedPriceWithoutTax'];
$data['salesprice'] += $quant * $prices['salesPrice'];
$data['taxamount'] += $quant * $prices['taxAmount'];
$data['salespricewithdiscount'] += $quant * $prices['salesPriceWithDiscount'];
$data['discountamount'] += $quant * $prices['discountAmount'];
$data['pricewithouttax'] += $quant * $prices['priceWithoutTax'];
// JFactory::getApplication()->enqueueMessage("<pre>prices: ".print_r($prices,1)."</pre>", 'error');
// JFactory::getApplication()->enqueueMessage("<pre>product: ".print_r($product,1)."</pre>", 'error');
}
// }
return $data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment