From 51efcf5f0663b663be937025f1ffa060032e013e Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Thu, 23 Apr 2015 12:23:54 +0200
Subject: [PATCH] Fix issues with J2V3, translations, JS errors, etc.

---
 fields/vmordernumbercounters.php              |  6 ++--
 fields/vmordernumberreplacements.php          | 27 +++++++-------
 .../de-DE/de-DE.plg_vmshopper_ordernumber.ini | 36 +++++++++++++++++++
 .../de-DE.plg_vmshopper_ordernumber.sys.ini   | 36 +++++++++++++++++++
 .../en-GB/en-GB.plg_vmshopper_ordernumber.ini | 11 +++++-
 .../en-GB.plg_vmshopper_ordernumber.sys.ini   | 11 +++++-
 ordernumber.php                               |  3 ++
 ordernumber.script.php                        |  1 -
 ordernumber/assets/js/ordernumber.js          | 10 +++---
 9 files changed, 119 insertions(+), 22 deletions(-)

diff --git a/fields/vmordernumbercounters.php b/fields/vmordernumbercounters.php
index ea4ba9c..b96e01f 100644
--- a/fields/vmordernumbercounters.php
+++ b/fields/vmordernumbercounters.php
@@ -102,9 +102,9 @@ class JFormFieldVmOrdernumberCounters extends JFormField {
     protected function getInput() {
         $pluginpath = '/plugins/vmshopper/ordernumber/ordernumber/';
         $doc = JFactory::getDocument()->addStyleSheet(JURI::root(true) . $pluginpath . 'assets/css/ordernumber.css');
-        $doc->addScript(JURI::root(true).$pluginpath . 'assets/js/ordernumber.js');
         $this->makeJSTranslationsAvailable();
         $this->loadjQuery();
+        $doc->addScript(JURI::root(true).$pluginpath . 'assets/js/ordernumber.js');
         
         // Look up the current counters
         $db = JFactory::getDBO();
@@ -132,11 +132,11 @@ class JFormFieldVmOrdernumberCounters extends JFormField {
             $html[] = "  <tr class='counter_row counter_type_$this->countertype'>";
             $html[] = "    <td class='counter_format'>" . (string)$displayfmt . "</td>";
             $html[] = "    <td class='counter_value'>" . (string)$c->count . "</td>";
-            $html[] = "    <td class='counter_buttons'><div class='ordernumber-ajax-loading'><img src='" .JURI::root(true).$pluginpath . "assets/images/icon-16-edit.png' class='vmordernumber-counter-editbtn vmordernumber-btn' onClick='ajaxEditCounter(this, $this->countertype, ".json_encode($c->number_format).", $c->count)' /></div><div class='ordernumber-ajax-loading'><img src='" . JURI::root(true).$pluginpath . "assets/images/icon-16-delete.png' class='vmordernumber-counter-deletebtn vmordernumber-btn' onClick='ajaxDeleteCounter(this, $this->countertype, ".json_encode($c->number_format).", $c->count)' /></div></td>";
+            $html[] = "    <td class='counter_buttons'><div class='ordernumber-ajax-loading'><img src='" .JURI::root(true).$pluginpath . "assets/images/icon-16-edit.png' class='vmordernumber-counter-editbtn vmordernumber-btn' onClick='ajaxEditCounter(this, " . json_encode($this->countertype) . ", ".json_encode($c->number_format).", $c->count)' /></div><div class='ordernumber-ajax-loading'><img src='" . JURI::root(true).$pluginpath . "assets/images/icon-16-delete.png' class='vmordernumber-counter-deletebtn vmordernumber-btn' onClick='ajaxDeleteCounter(this, ".json_encode($this->countertype).", ".json_encode($c->number_format).", $c->count)' /></div></td>";
             $html[] = "  </tr>";
         }
         $html[] = "  <tr class='addcounter_row'>";
-        $html[] = "    <td colspan=3 class='counter_add'><div class='vmordernumber-counter-addbtn vmordernumber-btn' onClick='ajaxAddCounter(this, $this->countertype)'><div class='ordernumber-ajax-loading'><img src='" . JURI::root(true).$pluginpath . "assets/images/icon-16-new.png' class='vmordernumber-counter-addbtn' /></div>" . JText::_('PLG_ORDERNUMBER_COUNTERLIST_ADD') . "</div></td>";
+        $html[] = "    <td colspan=3 class='counter_add'><div class='vmordernumber-counter-addbtn vmordernumber-btn' onClick='ajaxAddCounter(this, " . json_encode($this->countertype).")'><div class='ordernumber-ajax-loading'><img src='" . JURI::root(true).$pluginpath . "assets/images/icon-16-new.png' class='vmordernumber-counter-addbtn' /></div>" . JText::_('PLG_ORDERNUMBER_COUNTERLIST_ADD') . "</div></td>";
         $html[] = "  </tr>";
         $html[] = "</table>";
         return implode("\n", $html);
diff --git a/fields/vmordernumberreplacements.php b/fields/vmordernumberreplacements.php
index b1506cd..f84abb9 100644
--- a/fields/vmordernumberreplacements.php
+++ b/fields/vmordernumberreplacements.php
@@ -32,7 +32,10 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
     protected function loadjQuery() {
         vmJsApi::jQuery();
         // TODO: jquery::ui available only in J3:
-        JHtml::_('jquery.ui', array('core', 'sortable'));
+        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) {
@@ -76,9 +79,9 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
     
         $html=array();
         $doc = JFactory::getDocument()->addStyleSheet(self::css_url('ordernumber.css'));
+        $this->loadjQuery();
         $doc->addScript( self::js_url('ordernumber.js'));
         $this->makeJSTranslationsAvailable();
-        $this->loadjQuery();
         
         
         $value = $this->value;
@@ -110,12 +113,12 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
         
         $html[] = '<table id="ordernumber_variables" class="ordernumber_variables widefat wc_input_table sortable" cellspacing="0">';
         $columns = array(
-            'variables_ifvar'    => self::__( 'If variable ...'),
+            'variables_ifvar'    => self::__('PLG_ORDERNUMBER_REPL_IFVAR'),
             'variables_ifop'     => '',
-            'variables_ifval'    => self::__( 'Value'),
-            'variables_then'     => self::__( ''),
-            'variables_thenvar'  => self::__( 'Set variable ...'),
-            'variables_thenval'  => self::__( 'to value ...'),
+            'variables_ifval'    => self::__('PLG_ORDERNUMBER_REPL_IFVAL'),
+            'variables_then'     => self::__(''),
+            'variables_thenvar'  => self::__('PLG_ORDERNUMBER_REPL_SETVAR'),
+            'variables_thenval'  => self::__('PLG_ORDERNUMBER_REPL_TOVAL'),
             'sort'     => '',
             'variables_settings' => '',
         );
@@ -127,7 +130,7 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
         $html[] = '		</tr>';
         $html[] = '		<tr id="ordernumber-replacements-empty-row" class="oton-empty-row-notice ' . (empty($variables)?"":"rowhidden") . '">';
         $html[] = '			<td class="oton-empty-row-notice" colspan="8">';
-        $html[] = '				<em>a' . self::__('No custom variables have been defined.') . '</em>';
+        $html[] = '				<em>a' . self::__('PLG_ORDERNUMBER_REPL_NOCUSTOMVARS') . '</em>';
         $html[] = '				<input type="hidden" name="' . $name . '" value="" ' . (empty($variables))?'':'disabled' . '>';
         $html[] = '			</td>';
         $html[] = '		</tr>';
@@ -148,7 +151,7 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
         $html[] = '			<td colspan=8 class="variable_add">';
         $html[] = '				<div class="ordernumber-variables-addbtn ordernumber-btn" onClick="ordernumberVariablesAddRow(\'ordernumber_variables_template\', \'ordernumber_variables\')">';
         $html[] = '					<div class="ordernumber-ajax-loading"><img src="' . self::img_url( 'icon-16-new.png' ) . '" class="ordernumber-counter-addbtn" /></div>';
-        $html[] = self::__('Add new custom variable');
+        $html[] = self::__('PLG_ORDERNUMBER_REPL_ADDVAR');
         $html[] = '				</div>';
         $html[] = '			</td>';
         $html[] = '		</tr>';
@@ -161,13 +164,13 @@ class JFormFieldVmOrdernumberReplacements extends JFormField {
         $operator = (isset($values['conditionop'])?$values['conditionop']:'');
         $operators = array(
             'equals'       => '=', 
-            'contains'     => self::__('contains'), 
+            'contains'     => self::__('PLG_ORDERNUMBER_REPL_OP_CONTAINS'), 
             'smaller'      => '<',
             'smallerequal' => '<=',
             'larger'       => '>',
             'largerequal'  => '>=', 
-            'startswith'   => self::__('starts with'),
-            'endswith'     => self::__('ends with'),
+            'startswith'   => self::__('PLG_ORDERNUMBER_REPL_OP_STARTS'),
+            'endswith'     => self::__('PLG_ORDERNUMBER_REPL_OP_ENDS'),
         );
         $html  = '
         <tr>
diff --git a/language/de-DE/de-DE.plg_vmshopper_ordernumber.ini b/language/de-DE/de-DE.plg_vmshopper_ordernumber.ini
index f95a694..8181f61 100644
--- a/language/de-DE/de-DE.plg_vmshopper_ordernumber.ini
+++ b/language/de-DE/de-DE.plg_vmshopper_ordernumber.ini
@@ -2,6 +2,7 @@
 ; Copyright (C)  2012-2014 Reinhold Kainhofer. All rights reserved.
 ; License http://www.gnu.org/licenses/gpl.html GNU/GPL
 ; Note : All ini files need to be saved as UTF-8 - No BOM
+
 VMSHOPPER_ORDERNUMBER="Erweiterte Auftragsnummern für VirtueMart"
 VMSHOPPER_ORDERNUMBER_DESC=" <div style='font-weight: normal; text-align:left; background: #EEEEEE;'><h2>Ordernumber plugin für Virtuemart (2.x und 3.x)</h2><p style='font-weight: normal'>Dieses Plugin erlaubt die Anpassung des Formats von Auftrags-, Rechnungs- und Kundennummern in VirtueMart 2.x und 3.0.</p><p>Das Format der Auftrags-, Rechnungs- und Kundennummern ist ein einfacher Text, wobei <tt>#</tt> die laufende Nummer anzeigt und <tt>[variable]</tt> als Variable interpretiert und durch deren Wert ersetzt wird.</p><p>Die vollständige Dokumentation ist zu finden auf: <a href='http://open-tools.net/documentation/ordernumber-plugin-for-virtuemart.html'>http://open-tools.net/documentation/ordernumber-plugin-for-virtuemart.html</a></p>	</div>"
 
@@ -43,3 +44,38 @@ PLG_ORDERNUMBER_CUSTOMERNR_COUNTER="Zähler"
 PLG_ORDERNUMBER_CUSTOMERNR_COUNTER_DESC="Wählen Sie aus, ob der Zähler global oder pro Formatwert laufen soll. Z.B. beginnt bei einem Format '[year]-#' und einem Zähler pro Formatwert der Zähler jedes Jahr bei 1."
 PLG_ORDERNUMBER_CUSTOMERNR_PADDING="Mindestziffern für den Zähler"
 PLG_ORDERNUMBER_CUSTOMERNR_PADDING_DESC="Wählen Sie hier die Mindestzahl von Ziffern, die der Zähler anzeigt. Ist der Wert des Zählers kleiner, werden entsprechend viele führende Nullen vorangestellt."
+
+PLG_ORDERNUMBER_ORDERNR_ALLCOUNTERS="Alle Zählerstände"
+PLG_ORDERNUMBER_COUNTERLIST_GLOBAL="<i>Globaler Zähler</i>"
+PLG_ORDERNUMBER_COUNTERLIST_HEADER_COUNTER="Zählerformat/-name"
+PLG_ORDERNUMBER_COUNTERLIST_HEADER_VALUE="Zählerstand"
+PLG_ORDERNUMBER_COUNTERLIST_ADD="Neuen Zähler hinzufügen"
+PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Zähler '%s' existiert bereits."
+
+PLG_ORDERNUMBER_REPLACEMENTS_DESC="Hier können - abhängig von den Werten bereits bestehender Variablen - neue Variablen definiert werden, die dann im Nummernformat benutzt werden können."
+
+PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Auftragsnummern"
+PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Rechnungsnummern"
+PLG_ORDERNUMBER_FIELDSET_CUSTOMERNUMBER="Kundennummern"
+PLG_ORDERNUMBER_FIELDSET_REPLACEMENTS="Selbstdefinierte Variablen"
+
+PLG_ORDERNUMBER_JS_NOT_AUTHORIZED="Sie sind nicht berechtigt, Zählerstände zu bearbeiten."
+PLG_ORDERNUMBER_JS_NEWCOUNTER="Bitte geben Sie den Namen (Format) des neuen Zählers ein:"
+PLG_ORDERNUMBER_JS_DELETECOUNTER="Zähler '{0}' mit Wert '{1}' wirklich löschen?"
+PLG_ORDERNUMBER_JS_EDITCOUNTER="{0}Bitte geben Sie den neuen Wert für den Zähler '{1}' ein (aktueller Wert: {2}):"
+PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE="Ungültiger Wert für den Zählerstand.\n\n"
+PLG_ORDERNUMBER_JS_MODIFY_FAILED="Konnte den Zähler {0} nicht bearbeiten."
+PLG_ORDERNUMBER_JS_DELETE_FAILED="Konnte den Zähler {0} nicht löschen."
+PLG_ORDERNUMBER_JS_ADD_FAILED="Konnte den Zähler {0} nicht hinzufügen."
+PLG_ORDERNUMBER_JS_JSONERROR="Fehler beim Lesen der Antwort des Servers:"
+
+PLG_ORDERNUMBER_REPL_IFVAR="Wenn Variable..."
+PLG_ORDERNUMBER_REPL_IFVAL="Wert"
+PLG_ORDERNUMBER_REPL_SETVAR="Setze Variable ..."
+PLG_ORDERNUMBER_REPL_TOVAL="auf Wert ..."
+
+PLG_ORDERNUMBER_REPL_NOCUSTOMVARS="Es wurden noch keine selbstdefinierten Variablen erstellt."
+PLG_ORDERNUMBER_REPL_ADDVAR="Selbstdefinierte Variable erstellen"
+PLG_ORDERNUMBER_REPL_OP_CONTAINS="enthält"
+PLG_ORDERNUMBER_REPL_OP_STARTS="beginnt mit"
+PLG_ORDERNUMBER_REPL_OP_ENDS="endet mit"
diff --git a/language/de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini b/language/de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini
index f95a694..8181f61 100644
--- a/language/de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini
+++ b/language/de-DE/de-DE.plg_vmshopper_ordernumber.sys.ini
@@ -2,6 +2,7 @@
 ; Copyright (C)  2012-2014 Reinhold Kainhofer. All rights reserved.
 ; License http://www.gnu.org/licenses/gpl.html GNU/GPL
 ; Note : All ini files need to be saved as UTF-8 - No BOM
+
 VMSHOPPER_ORDERNUMBER="Erweiterte Auftragsnummern für VirtueMart"
 VMSHOPPER_ORDERNUMBER_DESC=" <div style='font-weight: normal; text-align:left; background: #EEEEEE;'><h2>Ordernumber plugin für Virtuemart (2.x und 3.x)</h2><p style='font-weight: normal'>Dieses Plugin erlaubt die Anpassung des Formats von Auftrags-, Rechnungs- und Kundennummern in VirtueMart 2.x und 3.0.</p><p>Das Format der Auftrags-, Rechnungs- und Kundennummern ist ein einfacher Text, wobei <tt>#</tt> die laufende Nummer anzeigt und <tt>[variable]</tt> als Variable interpretiert und durch deren Wert ersetzt wird.</p><p>Die vollständige Dokumentation ist zu finden auf: <a href='http://open-tools.net/documentation/ordernumber-plugin-for-virtuemart.html'>http://open-tools.net/documentation/ordernumber-plugin-for-virtuemart.html</a></p>	</div>"
 
@@ -43,3 +44,38 @@ PLG_ORDERNUMBER_CUSTOMERNR_COUNTER="Zähler"
 PLG_ORDERNUMBER_CUSTOMERNR_COUNTER_DESC="Wählen Sie aus, ob der Zähler global oder pro Formatwert laufen soll. Z.B. beginnt bei einem Format '[year]-#' und einem Zähler pro Formatwert der Zähler jedes Jahr bei 1."
 PLG_ORDERNUMBER_CUSTOMERNR_PADDING="Mindestziffern für den Zähler"
 PLG_ORDERNUMBER_CUSTOMERNR_PADDING_DESC="Wählen Sie hier die Mindestzahl von Ziffern, die der Zähler anzeigt. Ist der Wert des Zählers kleiner, werden entsprechend viele führende Nullen vorangestellt."
+
+PLG_ORDERNUMBER_ORDERNR_ALLCOUNTERS="Alle Zählerstände"
+PLG_ORDERNUMBER_COUNTERLIST_GLOBAL="<i>Globaler Zähler</i>"
+PLG_ORDERNUMBER_COUNTERLIST_HEADER_COUNTER="Zählerformat/-name"
+PLG_ORDERNUMBER_COUNTERLIST_HEADER_VALUE="Zählerstand"
+PLG_ORDERNUMBER_COUNTERLIST_ADD="Neuen Zähler hinzufügen"
+PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Zähler '%s' existiert bereits."
+
+PLG_ORDERNUMBER_REPLACEMENTS_DESC="Hier können - abhängig von den Werten bereits bestehender Variablen - neue Variablen definiert werden, die dann im Nummernformat benutzt werden können."
+
+PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Auftragsnummern"
+PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Rechnungsnummern"
+PLG_ORDERNUMBER_FIELDSET_CUSTOMERNUMBER="Kundennummern"
+PLG_ORDERNUMBER_FIELDSET_REPLACEMENTS="Selbstdefinierte Variablen"
+
+PLG_ORDERNUMBER_JS_NOT_AUTHORIZED="Sie sind nicht berechtigt, Zählerstände zu bearbeiten."
+PLG_ORDERNUMBER_JS_NEWCOUNTER="Bitte geben Sie den Namen (Format) des neuen Zählers ein:"
+PLG_ORDERNUMBER_JS_DELETECOUNTER="Zähler '{0}' mit Wert '{1}' wirklich löschen?"
+PLG_ORDERNUMBER_JS_EDITCOUNTER="{0}Bitte geben Sie den neuen Wert für den Zähler '{1}' ein (aktueller Wert: {2}):"
+PLG_ORDERNUMBER_JS_INVALID_COUNTERVALUE="Ungültiger Wert für den Zählerstand.\n\n"
+PLG_ORDERNUMBER_JS_MODIFY_FAILED="Konnte den Zähler {0} nicht bearbeiten."
+PLG_ORDERNUMBER_JS_DELETE_FAILED="Konnte den Zähler {0} nicht löschen."
+PLG_ORDERNUMBER_JS_ADD_FAILED="Konnte den Zähler {0} nicht hinzufügen."
+PLG_ORDERNUMBER_JS_JSONERROR="Fehler beim Lesen der Antwort des Servers:"
+
+PLG_ORDERNUMBER_REPL_IFVAR="Wenn Variable..."
+PLG_ORDERNUMBER_REPL_IFVAL="Wert"
+PLG_ORDERNUMBER_REPL_SETVAR="Setze Variable ..."
+PLG_ORDERNUMBER_REPL_TOVAL="auf Wert ..."
+
+PLG_ORDERNUMBER_REPL_NOCUSTOMVARS="Es wurden noch keine selbstdefinierten Variablen erstellt."
+PLG_ORDERNUMBER_REPL_ADDVAR="Selbstdefinierte Variable erstellen"
+PLG_ORDERNUMBER_REPL_OP_CONTAINS="enthält"
+PLG_ORDERNUMBER_REPL_OP_STARTS="beginnt mit"
+PLG_ORDERNUMBER_REPL_OP_ENDS="endet mit"
diff --git a/language/en-GB/en-GB.plg_vmshopper_ordernumber.ini b/language/en-GB/en-GB.plg_vmshopper_ordernumber.ini
index 17d801d..5768cdb 100644
--- a/language/en-GB/en-GB.plg_vmshopper_ordernumber.ini
+++ b/language/en-GB/en-GB.plg_vmshopper_ordernumber.ini
@@ -52,7 +52,7 @@ PLG_ORDERNUMBER_COUNTERLIST_HEADER_VALUE="Counter value"
 PLG_ORDERNUMBER_COUNTERLIST_ADD="Add new counter"
 PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Counter '%s' already exists."
 
-PLG_ORDERNUMBER_REPLACEMENTS_DESC="Here you can define contingent custom variables, which you can then use in the number format like any pre-defined variable."
+PLG_ORDERNUMBER_REPLACEMENTS_DESC="<p>Here you can define contingent custom variables, which you can then use in the number format like any pre-defined variable. In addition to the variables that can be used in the number format strings, there are several list-values variables available: SKUs, Categories, Manufacturers, Vendors. If the variable name of the condition is left blank, the custom variable will be set unconditionally, otherwise the variable on the right side will only be set if the condition on the left side is fulfilled.<br />As a special case, one can set the variables order_number_format, order_password_format, invoice_number_format and customer_number_format to override the counter format when the condition holds. This allows e.g. to use a different order-/invoice number format for free orders or for orders that contain products of a particular category or manufacturer.</p>"
 
 PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Order Numbers"
 PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Invoice Numbers"
@@ -69,3 +69,12 @@ PLG_ORDERNUMBER_JS_DELETE_FAILED="Failed deleting counter {0}"
 PLG_ORDERNUMBER_JS_ADD_FAILED="Failed adding counter {0}"
 PLG_ORDERNUMBER_JS_JSONERROR="Error reading response from server:"
 
+PLG_ORDERNUMBER_REPL_IFVAR="If variable ..."
+PLG_ORDERNUMBER_REPL_IFVAL="Value"
+PLG_ORDERNUMBER_REPL_SETVAR="Set variable ..."
+PLG_ORDERNUMBER_REPL_TOVAL="to value ..."
+PLG_ORDERNUMBER_REPL_NOCUSTOMVARS="No custom variables have been defined."
+PLG_ORDERNUMBER_REPL_ADDVAR="Add new custom variable"
+PLG_ORDERNUMBER_REPL_OP_CONTAINS="contains"
+PLG_ORDERNUMBER_REPL_OP_STARTS="starts with"
+PLG_ORDERNUMBER_REPL_OP_ENDS="ends with"
diff --git a/language/en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini b/language/en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini
index 17d801d..5768cdb 100644
--- a/language/en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini
+++ b/language/en-GB/en-GB.plg_vmshopper_ordernumber.sys.ini
@@ -52,7 +52,7 @@ PLG_ORDERNUMBER_COUNTERLIST_HEADER_VALUE="Counter value"
 PLG_ORDERNUMBER_COUNTERLIST_ADD="Add new counter"
 PLG_ORDERNUMBER_COUNTERLIST_EXISTS="Counter '%s' already exists."
 
-PLG_ORDERNUMBER_REPLACEMENTS_DESC="Here you can define contingent custom variables, which you can then use in the number format like any pre-defined variable."
+PLG_ORDERNUMBER_REPLACEMENTS_DESC="<p>Here you can define contingent custom variables, which you can then use in the number format like any pre-defined variable. In addition to the variables that can be used in the number format strings, there are several list-values variables available: SKUs, Categories, Manufacturers, Vendors. If the variable name of the condition is left blank, the custom variable will be set unconditionally, otherwise the variable on the right side will only be set if the condition on the left side is fulfilled.<br />As a special case, one can set the variables order_number_format, order_password_format, invoice_number_format and customer_number_format to override the counter format when the condition holds. This allows e.g. to use a different order-/invoice number format for free orders or for orders that contain products of a particular category or manufacturer.</p>"
 
 PLG_ORDERNUMBER_FIELDSET_ORDERNUMBER="Order Numbers"
 PLG_ORDERNUMBER_FIELDSET_INVOICENUMBER="Invoice Numbers"
@@ -69,3 +69,12 @@ PLG_ORDERNUMBER_JS_DELETE_FAILED="Failed deleting counter {0}"
 PLG_ORDERNUMBER_JS_ADD_FAILED="Failed adding counter {0}"
 PLG_ORDERNUMBER_JS_JSONERROR="Error reading response from server:"
 
+PLG_ORDERNUMBER_REPL_IFVAR="If variable ..."
+PLG_ORDERNUMBER_REPL_IFVAL="Value"
+PLG_ORDERNUMBER_REPL_SETVAR="Set variable ..."
+PLG_ORDERNUMBER_REPL_TOVAL="to value ..."
+PLG_ORDERNUMBER_REPL_NOCUSTOMVARS="No custom variables have been defined."
+PLG_ORDERNUMBER_REPL_ADDVAR="Add new custom variable"
+PLG_ORDERNUMBER_REPL_OP_CONTAINS="contains"
+PLG_ORDERNUMBER_REPL_OP_STARTS="starts with"
+PLG_ORDERNUMBER_REPL_OP_ENDS="ends with"
diff --git a/ordernumber.php b/ordernumber.php
index 261aa67..ffc9999 100644
--- a/ordernumber.php
+++ b/ordernumber.php
@@ -192,6 +192,7 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
             $reps["[orderstatus]"] = $details->order_status;
             
         
+        // TODO: Make the shipping/billing address available for order numbers, too!
         $this->setupAddressReplacements($reps, "", $details, $nrtype);
     
 		if (isset($details->order_total))		$reps['[ordertotal]'] = $details->order_total;
@@ -256,6 +257,7 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
    
 
     protected function setupUserReplacements (&$reps, $details, $nrtype) {
+        // TODO: Implement shopper group!
         $reps["[userid]"]      = $details->virtuemart_user_id;
         if (isset($details->ip_address))     $reps["[ipaddress]"] = $details->ip_address;
         // Customer number:
@@ -412,6 +414,7 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
         $format = $this->doReplacements($format, $reps);
         $ctrsettings = $this->extractCounterSettings ($format, $type, $ctrsettings);
 
+// JFactory::getApplication()->enqueueMessage("<pre>Replacements for $type:".print_r($reps,1)."</pre>", 'error');
         // Increment the counter only if the format contains a placeholder for it!
         if (strpos($ctrsettings["${type}_format"], "#") !== false) {
             $countername = $ctrsettings["${type}_counter"];
diff --git a/ordernumber.script.php b/ordernumber.script.php
index 4e2fd10..6cd4de3 100644
--- a/ordernumber.script.php
+++ b/ordernumber.script.php
@@ -89,7 +89,6 @@ class plgVmShopperOrdernumberInstallerScript
             $db->setQuery('update `#__virtuemart_shopper_plg_ordernumber` SET `number_type`="'.$new.'" WHERE `number_type`='.(int)$old.';');
             $db->query();
         }
-    }
 //         jimport( 'joomla.filesystem.file' ); 
 //         $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "en-GB" . DS . "en-GB.plg_vmshopper_ordernumber.sys.ini";
 //         if (JFile::exists($file)) JFile::delete($file); 
diff --git a/ordernumber/assets/js/ordernumber.js b/ordernumber/assets/js/ordernumber.js
index 1fa21ea..c83dfb2 100644
--- a/ordernumber/assets/js/ordernumber.js
+++ b/ordernumber/assets/js/ordernumber.js
@@ -164,10 +164,12 @@ var ordernumberVariablesAddRow = function (template, element) {
 	// Enable all form controls
 	jQuery(cl).find('input,select,button,img').removeAttr('disabled');
 
-	// select boxes handled by the chosen juery plugin cannot simply be cloned,
-	// instead we need to re-initialize chosen!
-	jQuery(cl).find('select').removeClass("chzn-done").removeAttr("id").css("display", "block").next().remove();
-	jQuery(cl).find('select').chosen({width: "50px"});
+	if (jQuery.fn.chosen) {
+		// select boxes handled by the chosen juery plugin cannot simply be cloned,
+		// instead we need to re-initialize chosen!
+		jQuery(cl).find('select').removeClass("chzn-done").removeAttr("id").css("display", "block").next().remove();
+		jQuery(cl).find('select').chosen({width: "50px"});
+	}
 	// Now insert this new row into the table
 	jQuery(cl).appendTo("table#" + element + " tbody");
 	jQuery("tr#ordernumber-replacements-empty-row")
-- 
GitLab