From 19025e1ad535eb125fed69e575a1d6a21cb661b3 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Sat, 2 Apr 2016 23:05:53 +0200
Subject: [PATCH] Make it work with the new VM Framework

---
 Makefile                      |  2 +-
 controllers/taxreport.php     |  2 +-
 taxreport.php                 | 18 +++++++++++++-----
 taxreport.xml                 | 10 +++++++---
 views/taxreport/view.html.php | 10 ++++++++--
 5 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index fad84c9..c3d42f3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 BASE=taxreport
 PLUGINTYPE=vmextended
-VERSION=0.1
+VERSION=0.2
 
 PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html 
 # $(BASE)/
diff --git a/controllers/taxreport.php b/controllers/taxreport.php
index b2dd9f1..2bedc00 100644
--- a/controllers/taxreport.php
+++ b/controllers/taxreport.php
@@ -9,7 +9,7 @@ class VirtuemartControllerTaxReport extends VmController {
 	function __construct(){
 		parent::__construct();
 		// Add the proper view pathes...
-		$this->addViewPath(JPATH_PLUGINS.DS . 'vmextended' . DS . 'taxreport' . DS . 'views');
+		$this->addViewPath(JPATH_PLUGINS.DS . 'vmextended' . DS . 'taxreport' . DS . 'views' . DS . 'taxreport');
 	}
 
 }
diff --git a/taxreport.php b/taxreport.php
index 2f886b9..f8fe1a1 100644
--- a/taxreport.php
+++ b/taxreport.php
@@ -9,16 +9,24 @@ class plgVmExtendedTaxReport extends vmExtendedPlugin {
 	public function __construct (&$subject, $config=array()) {
 		parent::__construct($subject, $config);
 		$this->_path = JPATH_PLUGINS.DS.'vmextended'.DS.$this->getName();
-		JPlugin::loadLanguage('plg_vmextended_'.$this->getName());
+		$this->loadLanguage('plg_vmextended_'.$this->getName());
 	}
 
 	public function onVmAdminController ($controller) {
 		if ($controller == 'taxreport'/*$this->getName()*/) {
-			VmModel::addIncludePath($this->_path . DS . 'models');
-			// TODO: Make sure the model exists. We probably should find a better way to load this automatically! 
-			//       Currently, some path config seems missing, so the model is not found by default.
-			require_once($this->_path.DS.'models'.DS.'taxreport.php');
+			VmModel::addIncludePath($this->_path . DS . 'models', 'VirtueMartModel');
 			require_once($this->_path.DS.'controllers'.DS.'taxreport.php');
+			
+			// In later VM versions, we can/should execute the controller here rather than letting virtuemart.php do the job:
+			$_class = 'VirtueMartController'.ucfirst($controller);
+			if(!class_exists($_class)){
+				vmError('Serious Error could not find controller '.$_class,'Serious error, unable to find class');
+				$app = vFactory::getApplication();
+				$app->redirect('index.php?option=com_virtuemart');
+			}
+			$controller = new $_class();
+			$controller->execute(vRequest::getCmd('task', $controller));
+			$controller->redirect();
 			return true;
 		}
 	}
diff --git a/taxreport.xml b/taxreport.xml
index 59c7944..ced2c1b 100644
--- a/taxreport.xml
+++ b/taxreport.xml
@@ -7,9 +7,9 @@
     <authorUrl>http://www.open-tools.net/</authorUrl>
     <copyright>Copyright (C) 2015 Reinhold Kainhofer. All rights reserved.</copyright>
     <license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3</license>
-    <version>0.1</version>
-    <releaseDate>2015-04-01</releaseDate>
-    <releaseType>Initial Release</releaseType>
+    <version>0.2</version>
+    <releaseDate>2016-04-02</releaseDate>
+    <releaseType>Update</releaseType>
     <downloadUrl>http://www.open-tools.net</downloadUrl>
 
     <description>VMEXT_TAXREPORT_DESC</description>
@@ -39,5 +39,9 @@
     <params addpath="/administrator/components/com_virtuemart/elements" >
         <param type="vmjpluginwarning" />
     </params>
+	
+	<updateservers>
+		<server type="extension" name="VM Tax Report Updates"><![CDATA[http://open-tools.net/UpdateServer/index.php?package=Joomla&amp;extension=TaxReport]]></server>
+	</updateservers>
 
 </extension>
diff --git a/views/taxreport/view.html.php b/views/taxreport/view.html.php
index 663dbc0..2806dce 100644
--- a/views/taxreport/view.html.php
+++ b/views/taxreport/view.html.php
@@ -13,7 +13,11 @@ if(!defined('VM_VERSION') or VM_VERSION < 3){
 class VirtuemartViewTaxReport extends VmViewAdmin {
 	function __construct(){
 		parent::__construct();
-		$this->_addPath('template', JPATH_PLUGINS.DS . 'vmextended' . DS . 'taxreport' . DS . 'views' . DS . $this->getName() . DS  . 'tmpl');
+		$nm = "taxreport";
+		$this->addLayoutPath($nm, JPATH_PLUGINS.DS . 'vmextended' . DS . 'taxreport' . DS . 'views' . DS . $nm . DS  . 'tmpl');
+// 		$this->_addPath('template', JPATH_PLUGINS.DS . 'vmextended' . DS . 'taxreport' . DS . 'views' . DS . $this->getName() . DS  . 'tmpl');
+// VmConfig::$echoDebug = 1;
+// vmdebug("<pre>VirtuemartViewTaxReport, pathes: ".print_r(self::$_paths,1)."</pre>");
 	}
 
 	function display($tpl = null){
@@ -24,7 +28,9 @@ class VirtuemartViewTaxReport extends VmViewAdmin {
 		vRequest::setvar('task','');
 		$this->SetViewTitle('TAXREPORT');
 
-		$model		= VmModel::getModel();
+		$model		= VmModel::getModel('taxreport');
+// VmConfig::$echoDebug = 1;
+// vmdebug("<pre>display, model=".print_r($model,1)."</pre>");
 		$this->addStandardDefaultViewLists($model);
 		$myCurrencyDisplay = CurrencyDisplay::getInstance();
 		
-- 
GitLab