Commit 7a7b6a77 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 1.1: Fix category loading (use sql rather than the model, which only returns 15 categories)

parent 93d261f1
BASE=vmAutoParentCategories
PLUGINTYPE=system
VERSION=1.0
VERSION=1.1
PLUGINFILES=$(BASE).php $(BASE).xml index.html
# TRANSDIR=../../../administrator/language/
......
......@@ -8,8 +8,9 @@ VMAUTOCATEGORIES_DESCRIPTION="<h2>Virtuemart 2 automatische Produktkategorien Pl
VMAUTOCATEGORIES_RUN="Führe Plugin aus:"
VMAUTOCATEGORIES_RUN_DESC="Wählen Sie aus, wann das Plugin ausgeführt wird und die Kategorien der VirtueMart Produkte modifiziert."
VMAUTOCATEGORIES_RUN_NEVER="Nie"
VMAUTOCATEGORIES_RUN_BACKEND_LOGIN="Joomla Backend Login"
VMAUTOCATEGORIES_RUN_NEVER="Nie (nur manuell)"
VMAUTOCATEGORIES_RUN_BACKEND_LOGIN="Joomla Backend Administrator Login"
VMAUTOCATEGORIES_RUN_FRONTEND_LOGIN="Joomla Frontend Administrator Login"
VMAUTOCATEGORIES_RUN_VM_STARTPAGE="VirtueMart Startseite (Backend)"
VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE="VirtueMart Produktliste (Backend)"
......
......@@ -8,8 +8,9 @@ VMAUTOCATEGORIES_DESCRIPTION="<h2>Virtuemart 2 Auto Product Categories plugin</h
VMAUTOCATEGORIES_RUN="Run plugin on:"
VMAUTOCATEGORIES_RUN_DESC="Select when the plugin shall be run and automatically modify the VirtueMart categories of your products."
VMAUTOCATEGORIES_RUN_NEVER="Never"
VMAUTOCATEGORIES_RUN_BACKEND_LOGIN="Joomla Backend login"
VMAUTOCATEGORIES_RUN_NEVER="Never (only manual)"
VMAUTOCATEGORIES_RUN_BACKEND_LOGIN="Joomla Backend Administrator Login"
VMAUTOCATEGORIES_RUN_FRONTEND_LOGIN="Joomla Frontend Administrator Login"
VMAUTOCATEGORIES_RUN_VM_STARTPAGE="VirtueMart start page (Backend)"
VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE="VirtueMart product list page (Backend)"
......
<?php
/**
* @plugin VMAutoParentCategories
* Version 1.0, 2012-12-18
* @copyright Copyright (C) 2012 Reinhold Kainhofer - All rights reserved.
* Version 1.1, 2013-02-24
* @copyright Copyright (C) 2012-2013 Reinhold Kainhofer - All rights reserved.
* @Website : http://www.kainhofer.com
* @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
**/
......@@ -17,6 +17,15 @@ class plgSystemVMAutoParentCategories extends JPlugin {
var $_report = TRUE;
var $_debug = FALSE;
function onAfterRoute(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
if ($this->checkForRoutingTrigger()) {
$this->initSettings();
$this->updateCategories();
}
}
function initSettings() {
$this->_dbg = $this->params->get('debug','report_changes');
......@@ -43,7 +52,7 @@ class plgSystemVMAutoParentCategories extends JPlugin {
break;
}
}
function checkForTrigger() {
function checkForRoutingTrigger() {
$trigger = $this->params->get('run_trigger', 'never');
// Explicit call will ALWAYS trigger
if (JRequest::getCmd('vmAutoParentCategories') == 'run') {
......@@ -66,25 +75,15 @@ class plgSystemVMAutoParentCategories extends JPlugin {
}
return $run;
}
function onAfterRoute(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
if ($this->checkForTrigger()) {
$this->initSettings();
$this->updateCategories();
}
}
function debugMessage ($msg) {
if ($this->_debug) {
$app = JFactory::getApplication();
$app->enqueueMessage($msg, 'message');
JFactory::getApplication()->enqueueMessage($msg, 'message');
}
}
function progressMessage ($msg) {
if ($this->_report) {
$app = JFactory::getApplication();
$app->enqueueMessage($msg, 'message');
JFactory::getApplication()->enqueueMessage($msg, 'message');
}
}
......@@ -170,6 +169,16 @@ class plgSystemVMAutoParentCategories extends JPlugin {
}
}
}
function getCategoryTree () {
$q = 'SELECT `c`.`virtuemart_category_id` , `l`.`category_name` , `cc`.`category_parent_id`
FROM `#__virtuemart_categories` AS `c`
LEFT JOIN `#__virtuemart_categories_'.VMLANG.'` AS `l` ON ( `c`.`virtuemart_category_id` = `l`.`virtuemart_category_id` )
LEFT JOIN `#__virtuemart_category_categories` AS `cc` ON ( `c`.`virtuemart_category_id` = `cc`.`category_child_id` )';
$db = JFactory::getDbo ();
$db->setQuery ($q);
$categories = $db->loadObjectList ('virtuemart_category_id');
return $categories;
}
function updateCategories() {
......@@ -179,10 +188,7 @@ class plgSystemVMAutoParentCategories extends JPlugin {
$prodaction = $this->params->get('normal_products', 'nothing');
$childprodaction = $this->params->get('child_products', 'nothing');
$app = JFactory::getApplication();
$catmodel = VmModel::getModel('category');
$cattree = $catmodel->getCategoryTree();
$cattree = $this->getCategoryTree();
// Store the names and parents for each category id
foreach ($cattree as $cat) {
$catnames[$cat->virtuemart_category_id] = $cat->category_name;
......
......@@ -7,7 +7,7 @@
<license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license>
<authorEmail>reinhold@kainhofer.com/</authorEmail>
<authorUrl>http://kainhofer.com</authorUrl>
<version>1.0.0</version>
<version>1.1.0</version>
<description>VMAUTOCATEGORIES_DESCRIPTION</description>
<files>
......@@ -26,6 +26,7 @@
<field name="run_trigger" type="list" default="never" label="VMAUTOCATEGORIES_RUN" description ="VMAUTOCATEGORIES_RUN_DESC" >
<option value="never">VMAUTOCATEGORIES_RUN_NEVER</option>
<!-- <option value="backend-login">VMAUTOCATEGORIES_RUN_BACKEND_LOGIN</option> -->
<!-- <option value="frontend-login">VMAUTOCATEGORIES_RUN_FRONTEND_LOGIN</option> -->
<option value="virtuemart_startpage">VMAUTOCATEGORIES_RUN_VM_STARTPAGE</option>
<option value="virtuemart_products">VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE</option>
</field>
......
Supports Markdown
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