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

V0.2: Basics work, trigger might be improved

parent 6e49001f
Branches
Tags
No related merge requests found
BASE=vmProductAutoParentCategories
BASE=vmAutoParentCategories
PLUGINTYPE=system
VERSION=0.1
......
; @plugin VmAutoParentCategories
; @copyright Copyright (C) 2012 Reinhold Kainhofer.
; @Website : http://kainhofer.com
; @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
VMAUTOCATEGORIES_DESCRIPTION="<h2>Virtuemart 2 automatische Produktkategorien Plugin</h2><p style='font-weight: normal'>Dieses Plugin kann den VirtueMart Produkten automatische alle übergeordneten Kategorien des Produkts zuweisen, oder all übergeordneten Kategorien entfernen. Ebenso können bei Produktvarianten die Kategorien des übergeordneten Produkts zugeordnet, oder alle Kategorien entfernt werden.</p><p style='font-weight: normal'>Um das Plugin manuell auszuführen, <a href="_QQ_"?vmAutoParentCategories=run"_QQ_">klicken Sie hier</a>.</p>"
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_VM_STARTPAGE="VirtueMart Startseite (Backend)"
VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE="VirtueMart Produktliste (Backend)"
VMAUTOCATEGORIES_NORMAL_PRODUCTS="Normale Produkts"
VMAUTOCATEGORIES_NORMAL_PRODUCTS_DESC="Wählen Sie, wie normale Produkts (d.h. keine Produktvarianten) modifiziert werden sollen."
VMAUTOCATEGORIES_CHILD_PRODUCTS="Unterprodukte"
VMAUTOCATEGORIES_CHILD_PRODUCTS_DESC="Wählen Sie, wie die Kategorien von Produktvarianten modifiziert werden sollen."
VMAUTOCATEGORIES_DO_NOTHING="Nicht modifizieren"
VMAUTOCATEGORIES_ADD_PARENTS="Produkt zu allen Elternkategorien hinzufügen"
VMAUTOCATEGORIES_ADD_ONE_PARENT="Produkt nur zur unmittelbaren Elternkategorie hinzufügen."
VMAUTOCATEGORIES_REMOVE_EXCEPT_LEAF="Etferne alle Elternkategorien."
VMAUTOCATEGORIES_COPY_CATEGORIES_FROM_PARENT="Dupliziere Kategorien des übergeordneten Produkts."
VMAUTOCATEGORIES_REMOVE_ALL="Alle Kategorien entfernen."
VMAUTOCATEGORIES_DEBUG="Debug-Meldungen"
VMAUTOCATEGORIES_DEBUG_DESC="Wählen Sie, wie viel Information das Plugin ausgeben soll."
VMAUTOCATEGORIES_DBG_NO_OUTPUT="Keine Meldung"
VMAUTOCATEGORIES_DBG_REPORT_CHANGES="Änderungen melden"
VMAUTOCATEGORIES_DBG_REPORT_ALWAYS="Anzeigen, auch wenn nichts geändert wurde"
VMAUTOCATEGORIES_DBG_REPORT_NO_CHANGES="Änderungen melden, aber nicht anwenden"
VMAUTOCATEGORIES_DBG_DEBUG="Ausführliche Debugmeldungen"
VMAUTOCATEGORIES_DBG_DEBUG_NO_CHANGES="Ausführliche Debugmeldungen, Änderungen nicht anwenden"
VMAUTOCATEGORIES_PROGRESS_ARTICLES_MODIFIED="Kategorien von %d Top-Level Produkten modifiziert."
VMAUTOCATEGORIES_PROGRESS_ARTICLES_NO_MODIFICATIONS="Keine Modifikation der Kategorien von Top-Level Produkten nötig."
VMAUTOCATEGORIES_PROGRESS_CHILDREN_MODIFIED="Kategorien von %d Produktvarianten modifiziert."
VMAUTOCATEGORIES_PROGRESS_CHILDREN_NO_MODIFICATIONS="Keine Modifikation der Kategorien von Produktvarianten nötig."
VMAUTOCATEGORIES_PROGRESS_NOTAPPLIED="Änderungen aufgrund der Plugin-Einstellungen nicht angewendet."
VMAUTOCATEGORIES_DEBUG_LOADCATS="%s Kategorien geladen."
VMAUTOCATEGORIES_DEBUG_LOADPRODUCTS="%s Produkte geladen."
VMAUTOCATEGORIES_DEBUG_ARTICLE_MODIFIED="Produkt "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
VMAUTOCATEGORIES_DEBUG_ARTICLE_NOT_MODIFIED="Produkt "_QQ_"%s"_QQ_" (SKU %s) nicht modifiziert."
VMAUTOCATEGORIES_DEBUG_CHILD_MODIFIED="Produktvariante "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
VMAUTOCATEGORIES_DEBUG_CHILD_NOT_MODIFIED="Produktvariante "_QQ_"%s"_QQ_" (SKU %s) nicht modifiziert."
VMAUTOCATEGORIES_DEBUG_CATEGORYMODIFICATIONS=" Hinzugefügte Kategorien: %s. Entfernte Kategorien: %s."
; @plugin VmProductAutoParentCategories
; @copyright Copyright (C) 2012 Reinhold Kainhofer.
; @Website : http://kainhofer.com
; @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
VMPRODPARENTCATS_DESCRIPTION="<h2>Virtuemart 2 automatische Artikelkategorien Plugin</h2><p style='font-weight: normal'>Dieses Plugin kann den VirtueMart Artikel automatische alle übergeordneten Kategorien des Artikels zuweisen, oder all übergeordneten Kategorien entfernen. Ebenso können bei Kindartikeln die Kategorien des Elternartikels zugeordnet, oder alle Kategorien entfernt werden.</p>"
VMPRODPARENTCATS_RUN="Führe Plugin aus:"
VMPRODPARENTCATS_RUN_DESC="Wählen Sie aus, wann das Plugin ausgeführt wird und die Kategorien der VirtueMart Artikeln modifiziert. Beachten Sie, dass aktuell das Plugin nicht manuell ausgeführt werden kann."
VMPRODPARENTCATS_RUN_NEVER="Nie"
VMPRODPARENTCATS_RUN_BACKEND_LOGIN="Joomla Backend Login"
VMPRODPARENTCATS_NORMAL_PRODUCTS="Normale Artikel"
VMPRODPARENTCATS_NORMAL_PRODUCTS_DESC="Wählen Sie, wie normale Artikel (d.h. keine Unterartikel) modifiziert werden sollen."
VMPRODPARENTCATS_CHILD_PRODUCTS="Unterprodukte"
VMPRODPARENTCATS_CHILD_PRODUCTS_DESC="Wählen Sie, wie die Kategorien von Unterartikeln modifiziert werden sollen."
VMPRODPARENTCATS_DO_NOTHING="Nicht modifizieren"
VMPRODPARENTCATS_ADD_PARENTS="Artikel zu allen Elternkategorien hinzufügen"
VMPRODPARENTCATS_ADD_ONE_PARENT="Artikel nur zur unmittelbaren Elternkategorie hinzufügen."
VMPRODPARENTCATS_REMOVE_EXCEPT_LEAF="Etferne alle Elternkategorien."
VMPRODPARENTCATS_COPY_CATEGORIES_FROM_PARENT="Dupliziere Kategorien des übergeordneten Artikels."
VMPRODPARENTCATS_REMOVE_ALL="Alle Kategorien entfernen."
VMPRODPARENTCATS_DEBUG="Debug-Meldungen"
VMPRODPARENTCATS_DEBUG_DESC="Wählen Sie, wie viel Information das Plugin ausgeben soll."
VMPRODPARENTCATS_DBG_NO_OUTPUT="Keine Meldung"
VMPRODPARENTCATS_DBG_REPORT_CHANGES="Änderungen melden"
VMPRODPARENTCATS_DBG_REPORT_ALWAYS="Anzeigen, auch wenn nichts geändert wurde"
VMPRODPARENTCATS_DBG_REPORT_NO_CHANGES="Änderungen melden, aber nicht anwenden"
VMPRODPARENTCATS_DBG_DEBUG="Ausführliche Debugmeldungen"
VMPRODPARENTCATS_DBG_DEBUG_NO_CHANGES="Ausführliche Debugmeldungen, Änderungen nicht anwenden"
; VMPRODAUTOPARENTCATEGORIES="TEST Message!!!"
VMPRODPARENTCATS_DEBUG_LOADCATS="%s Kategorien geladen."
VMPRODPARENTCATS_DEBUG_LOADPRODUCTS="%s Produkte geladen."
VMPRODPARENTCATS_DEBUG_ARTICLE_MODIFIED="Artikel "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
VMPRODPARENTCATS_DEBUG_ARTICLE_NOT_MODIFIED="Artikel "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
; @plugin VmAutoParentCategories
; @copyright Copyright (C) 2012 Reinhold Kainhofer.
; @Website : http://kainhofer.com
; @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
VMAUTOCATEGORIES_DESCRIPTION="<h2>Virtuemart 2 Auto Product Categories plugin</h2><p style='font-weight: normal'>Automatically add VirtueMart products to all parent categories of the categories assigned to it, or remove all parent categories. Additionally, child products can also be adjusted with their parents' categories, or removed from all categories.</p><p style='font-weight: normal'>To call the plugin explicitly, <a href="_QQ_"?vmAutoParentCategories=run"_QQ_">click here</a>.</p>"
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_VM_STARTPAGE="VirtueMart start page (Backend)"
VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE="VirtueMart product list page (Backend)"
VMAUTOCATEGORIES_NORMAL_PRODUCTS="Normal products"
VMAUTOCATEGORIES_NORMAL_PRODUCTS_DESC="Choose how the categories of normal products (i.e. not child products) will be modified."
VMAUTOCATEGORIES_CHILD_PRODUCTS="Child products"
VMAUTOCATEGORIES_CHILD_PRODUCTS_DESC="Choose how the categories of child products will be modified."
VMAUTOCATEGORIES_DO_NOTHING="Do not modify"
VMAUTOCATEGORIES_ADD_PARENTS="Add product to all parent categories of assigned categories"
VMAUTOCATEGORIES_ADD_ONE_PARENT="Add product to leaf category and its parent, remove all others"
VMAUTOCATEGORIES_REMOVE_EXCEPT_LEAF="Remove from all but the lowest categories"
VMAUTOCATEGORIES_COPY_CATEGORIES_FROM_PARENT="Copy categories from parent product"
VMAUTOCATEGORIES_REMOVE_ALL="Remove all categories"
VMAUTOCATEGORIES_DEBUG="Debug Output"
VMAUTOCATEGORIES_DEBUG_DESC="Select how much information about its operation is displayed by the plugin"
VMAUTOCATEGORIES_DBG_NO_OUTPUT="No output"
VMAUTOCATEGORIES_DBG_REPORT_CHANGES="Report changes"
VMAUTOCATEGORIES_DBG_REPORT_ALWAYS="Report, even if nothing was changed"
VMAUTOCATEGORIES_DBG_REPORT_NO_CHANGES="Report changes, don't apply them"
VMAUTOCATEGORIES_DBG_DEBUG="Verbose debug output"
VMAUTOCATEGORIES_DBG_DEBUG_NO_CHANGES="Verbose debug output, don't apply changes"
VMAUTOCATEGORIES_PROGRESS_ARTICLES_MODIFIED="Modified categories of %d top-level products"
VMAUTOCATEGORIES_PROGRESS_ARTICLES_NO_MODIFICATIONS="No category modifications to top-level products needed."
VMAUTOCATEGORIES_PROGRESS_CHILDREN_MODIFIED="Modified categories of %d child products"
VMAUTOCATEGORIES_PROGRESS_CHILDREN_NO_MODIFICATIONS="No category modifications to child products needed."
VMAUTOCATEGORIES_PROGRESS_NOTAPPLIED="Changes not applied due to configuration settings."
VMAUTOCATEGORIES_DEBUG_LOADCATS="Loaded %s categories."
VMAUTOCATEGORIES_DEBUG_LOADPRODUCTS="Loaded %s products."
VMAUTOCATEGORIES_DEBUG_ARTICLE_MODIFIED="Product "_QQ_"%s"_QQ_" (SKU %s) modified: added %d categories, removed %d categories."
VMAUTOCATEGORIES_DEBUG_ARTICLE_NOT_MODIFIED="Product "_QQ_"%s"_QQ_" (SKU %s) was not modified."
VMAUTOCATEGORIES_DEBUG_CHILD_MODIFIED="Child product "_QQ_"%s"_QQ_" (SKU %s) modified: added %d categories, removed %d categories."
VMAUTOCATEGORIES_DEBUG_CHILD_NOT_MODIFIED="Child product "_QQ_"%s"_QQ_" (SKU %s) not modified."
VMAUTOCATEGORIES_DEBUG_CATEGORYMODIFICATIONS=" Hinzugefügte Kategorien: %s. Entfernte Kategorien: %s."
; @plugin VmProductAutoParentCategories
; @copyright Copyright (C) 2012 Reinhold Kainhofer.
; @Website : http://kainhofer.com
; @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
VMPRODPARENTCATS_DESCRIPTION="<h2>Virtuemart 2 Product Auto Parent Categories plugin</h2><p style='font-weight: normal'>Automatically add VirtueMart products to all parent categories of the categories assigned to it, or remove all parent categories. Similarly, child products can be adjusted with their parents' categories, or removed from all categories.</p>"
VMPRODPARENTCATS_RUN="Run plugin on:"
VMPRODPARENTCATS_RUN_DESC="Select when the plugin shall be run and automatically modify the VirtueMart categories of your products. Note that there is currently no way to run the plugin manually!"
VMPRODPARENTCATS_RUN_NEVER="Never"
VMPRODPARENTCATS_RUN_BACKEND_LOGIN="Joomla Backend login"
VMPRODPARENTCATS_NORMAL_PRODUCTS="Normal products"
VMPRODPARENTCATS_NORMAL_PRODUCTS_DESC="Choose how the categories of normal products (i.e. not child products) will be modified."
VMPRODPARENTCATS_CHILD_PRODUCTS="Child products"
VMPRODPARENTCATS_CHILD_PRODUCTS_DESC="Choose how the categories of child products will be modified."
VMPRODPARENTCATS_DO_NOTHING="Do not modify"
VMPRODPARENTCATS_ADD_PARENTS="Add product to all parent categories of assigned categories"
VMPRODPARENTCATS_ADD_ONE_PARENT="Add product to leaf category and its parent, remove all others"
VMPRODPARENTCATS_REMOVE_EXCEPT_LEAF="Remove from all but the lowest categories"
VMPRODPARENTCATS_COPY_CATEGORIES_FROM_PARENT="Copy categories from parent product"
VMPRODPARENTCATS_REMOVE_ALL="Remove all categories"
VMPRODPARENTCATS_DEBUG="Debug Output"
VMPRODPARENTCATS_DEBUG_DESC="Select how much information about its operation is displayed by the plugin"
VMPRODPARENTCATS_DBG_NO_OUTPUT="No output"
VMPRODPARENTCATS_DBG_REPORT_CHANGES="Report changes"
VMPRODPARENTCATS_DBG_REPORT_ALWAYS="Report, even if nothing was changed"
VMPRODPARENTCATS_DBG_REPORT_NO_CHANGES="Report changes, don't apply them"
VMPRODPARENTCATS_DBG_DEBUG="Verbose debug output"
VMPRODPARENTCATS_DBG_DEBUG_NO_CHANGES="Verbose debug output, don't apply changes"
VMPRODPARENTCATS_DEBUG_LOADCATS="Loaded %s categories."
<?php
/**
* @plugin VMProductAutoParentCategories
* @plugin VMAutoParentCategories
* @copyright Copyright (C) 2012 Reinhold Kainhofer - All rights reserved.
* @Website : http://www.kainhofer.com
* @license - http://www.gnu.org/licenses/gpl.html GNU/GPL
**/
defined( '_JEXEC' ) or die( 'Restricted access' );
JFactory::getLanguage()->load('plg_system_vmProductAutoParentCategories.sys');
JFactory::getLanguage()->load('plg_system_vmAutoParentCategories.sys');
jimport('joomla.event.plugin');
class plgSystemVMProductAutoParentCategories extends JPlugin {
class plgSystemVMAutoParentCategories extends JPlugin {
var $_dbg = 'report_changes';
var $_apply = TRUE;
var $_report = TRUE;
......@@ -41,25 +41,39 @@ class plgSystemVMProductAutoParentCategories extends JPlugin {
$this->_debug = TRUE;
break;
}
// print("Settings: _dbg=$this->_dbg, _prodaction=$this->_prodaction, _childprodaction=$this->_childprodaction, _apply=$this->_apply, _report=$this->_report, _debug=$this->_debug");
}
function onAfterRoute(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
function checkForTrigger() {
$trigger = $this->params->get('run_trigger', 'never');
// Explicit call will ALWAYS trigger
if (JRequest::getCmd('vmAutoParentCategories') == 'run') {
return TRUE;
}
if ($trigger == 'never')
return FALSE;
$option = JRequest::getCmd('option');
if($option != 'com_virtuemart') return;
$this->initSettings();
$this->updateCategories();
$view = JRequest::getCmd('view');
$task = JRequest::getCmd('task');
$run = FALSE;
if ($option == 'com_virtuemart') {
if ($trigger == 'virtuemart_startpage') {
$run |= (empty($view) or ($view=='virtuemart'));
}
if ($trigger == 'virtuemart_products') {
$run |= ($view=='product' and empty($task));
}
}
return $run;
}
function onLoginUser(){
function onAfterRoute(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
JFactory::getApplication()->enqueueMessage("onLoginUser", 'message');
$this->initSettings();
if ($this->checkForTrigger()) {
$this->initSettings();
$this->updateCategories();
}
}
function debugMessage ($msg) {
if ($this->_debug) {
$app = JFactory::getApplication();
......@@ -110,11 +124,52 @@ class plgSystemVMProductAutoParentCategories extends JPlugin {
function getProductTopParent($product, $products) {
$p = $product;
while ($p->product_parent_id) {
while ($p->product_parent_id>0) {
$p = $products[$p->product_parent_id];
}
return $p;
}
function getProductCategories ($virtuemart_product_id = 0) {
$categories = array();
if ($virtuemart_product_id > 0) {
$q = 'SELECT `virtuemart_category_id` FROM `#__virtuemart_product_categories` WHERE `virtuemart_product_id` = ' . (int)$virtuemart_product_id;
$db = JFactory::getDBO ();
$db->setQuery ($q);
$categories = $db->loadResultArray ();
}
return $categories;
}
function getAllProducts () {
$q = 'SELECT `virtuemart_product_id`, `product_parent_id`, `product_sku`, `l`.`product_name` as `product_name`, `l`.`slug` as `slug` from #__virtuemart_products JOIN `#__virtuemart_products_' . VMLANG . '` as `l` using (`virtuemart_product_id`);';
$db = JFactory::getDbo ();
$db->setQuery ($q);
$products = $db->loadObjectList ('virtuemart_product_id');
return $products;
}
function updateProductCategories($virtuemart_product_id, $added, $removed) {
$db = JFactory::getDbo ();
$sqladd = 'INSERT INTO `#__virtuemart_product_categories` (`virtuemart_product_id`, `virtuemart_category_id`) VALUES ("'.$virtuemart_product_id.'", "%d");';
foreach ($added as $c) {
$db->setQuery(sprintf($sqladd, $c));
$db->query ();
$err = $db->getErrorMsg ();
if (!empty($err)) {
vmError ("Database error: Unable to insert product category $c for product $virtuemart_product_id: " . $err);
}
}
$sqlremove = 'DELETE FROM `#__virtuemart_product_categories` WHERE `virtuemart_product_id`="'.$virtuemart_product_id.'" AND `virtuemart_category_id`="%d";';
foreach ($removed as $c) {
$db->setQuery(sprintf($sqlremove, $c));
$db->query ();
$err = $db->getErrorMsg ();
if (!empty($err)) {
vmError ('Database error: Unable to remove product category $c for product $virtuemart_product_id: ' . $err);
}
}
}
function updateCategories() {
if (!class_exists( 'VmConfig' ))
......@@ -132,21 +187,15 @@ class plgSystemVMProductAutoParentCategories extends JPlugin {
$catnames[$cat->virtuemart_category_id] = $cat->category_name;
$catparents[$cat->virtuemart_category_id] = $cat->category_parent_id;
}
$this->debugMessage(JText::sprintf('VMPRODPARENTCATS_DEBUG_LOADCATS', count($cattree)));
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_LOADCATS', count($cattree)));
$productmodel = VmModel::getModel('product');
$productmodel->_noLimit = true;
$products = [];
// Create an array of products, indexed by their VM id:
foreach ($productmodel->getProductListing() as $p) {
$products[$p->virtuemart_product_id] = $p;
}
$this->debugMessage(JText::sprintf('VMPRODPARENTCATS_DEBUG_LOADPRODUCTS', count($products)));
$products=$this->getAllProducts();
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_LOADPRODUCTS', count($products)));
// First, look only at parent products
$modified = 0;
foreach ($products as $p) {
if ($p->product_parent_id) continue;
$cats = $p->categories;
$cats = $this->getProductCategories($p->virtuemart_product_id);
$newcats = $cats;
switch ($prodaction) {
case 'nothing': continue;
......@@ -155,47 +204,64 @@ class plgSystemVMProductAutoParentCategories extends JPlugin {
case 'remove_except_leaf': $newcats = $this->getCategoriesOnlyLeaf($cats, $catparents); break;
}
$added=array_diff($newcats,$cats);
$removed=array_diff($cats,$newcat);
if (!empty($added) and !empty($removed)) {
$removed=array_diff($cats,$newcats);
if (!empty($added) or !empty($removed)) {
$modified++;
$p->categories = $newcats;
$productmodel->store($p);
VMPRODPARENTCATS_DEBUG_ARTICLE_MODIFIED="Artikel "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_ARTICLE_MODIFIED', $p->product_name, $p->product_sku, count($added), count($removed)));
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_CATEGORYMODIFICATIONS', implode(", ", $added), implode(", ", $removed)));
if ($this->_apply) {
$this->updateProductCategories($p->virtuemart_product_id, $added, $removed);
} else {
$this->progressMessage(JText::_('VMAUTOCATEGORIES_PROGRESS_NOTAPPLIED'));
}
} else {
VMPRODPARENTCATS_DEBUG_ARTICLE_MODIFIED="Artikel "_QQ_"%s"_QQ_" (SKU %s) modifiziert: %d Kategorien hinzugefügt, %d Kategorien entfernt."
print("Product: $p->product_name");
print("Added categories: ");print_r($added);
print("Removed categories: ");print_r($removed);
// TODO: Assign the new categories, print out debug statement, store the changes!
print("Old categories: "); print_r($cats);
print("New categories: "); print_r($newcats);
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_ARTICLE_NOT_MODIFIED', $p->product_name, $p->product_sku));
}
}
if ($modified>0) {
$this->progressMessage(JText::sprintf('VMAUTOCATEGORIES_PROGRESS_ARTICLES_MODIFIED', $modified));
} elseif (in_array ($this->_dbg, ['report_always', 'report_no_change', 'debug', 'debug_no_changes'])) {
$this->progressMessage(JText::sprintf('VMAUTOCATEGORIES_PROGRESS_ARTICLES_NO_MODIFICATIONS'));
}
$childrenmodified=0;
// Now look at the child products and modify them accordingly
foreach ($products as $p) {
if (!$p->product_parent_id) continue;
$topparent = $this->getProductTopParent($p, $products);
$cats = $p->categories;
$cats = $this->getProductCategories($p->virtuemart_product_id);
$newcats = $cats;
// print("Action: $prodaction");
switch ($childprodaction) {
case 'nothing': continue;
case 'add_parents': $newcats = $this->getCategoriesAllParents($cats, $catparents); break;
case 'add_two_leaves': $newcats = $this->getCategoriesOneParent($cats, $catparents); break;
case 'remove_except_leaf': $newcats = $this->getCategoriesOnlyLeaf($cats, $catparents); break;
case 'copy_parent': $newcats = $topparent->categories; break;
case 'copy_parent': $newcats = $this->getProductCategories($topparent->virtuemart_product_id); break;
case 'remove_all': $newcats = []; break;
}
print("Old categories: "); print_r($cats);
print("New categories: "); print_r($newcats);
// TODO: Assign the new categories, print out debug statement, store the changes!
$added=array_diff($newcats,$cats);
$removed=array_diff($cats,$newcats);
if (!empty($added) or !empty($removed)) {
$childrenmodified++;
$p->categories = $newcats;
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_CHILD_MODIFIED', $p->product_name, $p->product_sku, count($added), count($removed)));
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_CATEGORYMODIFICATIONS', implode(", ", $added), implode(", ", $removed)));
if ($this->_apply) {
$this->updateProductCategories($p->virtuemart_product_id, $added, $removed);
} else {
$this->progressMessage(JText::_('VMAUTOCATEGORIES_PROGRESS_NOTAPPLIED'));
}
} else {
$this->debugMessage(JText::sprintf('VMAUTOCATEGORIES_DEBUG_CHILD_NOT_MODIFIED', $p->product_name, $p->product_sku));
}
}
if ($childrenmodified>0) {
$this->progressMessage(JText::sprintf('VMAUTOCATEGORIES_PROGRESS_CHILDREN_MODIFIED', $childrenmodified));
} elseif (in_array ($this->_dbg, ['report_always', 'report_no_change', 'debug', 'debug_no_changes'])) {
$this->progressMessage(JText::sprintf('VMAUTOCATEGORIES_PROGRESS_CHILDREN_NO_MODIFICATIONS'));
}
$app->enqueueMessage(JText::_('VMPRODAUTOPARENTCATEGORIES'), 'message');
}
}
<?xml version="1.0" encoding="utf-8"?>
<install version="2.0" type="plugin" group="system" method="upgrade">
<name>System - VM Product Auto Parent Categories</name>
<creationDate>2012-12-16</creationDate>
<name>System - VM Auto Parent Categories</name>
<creationDate>2012-12-18</creationDate>
<author>Reinhold Kainhofer</author>
<copyright>Copyright (C) 2012 Reinhold Kainhofer.</copyright>
<license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license>
<authorEmail>reinhold@kainhofer.com/</authorEmail>
<authorUrl>http://kainhofer.com</authorUrl>
<version>0.0.1</version>
<description>VMPRODPARENTCATS_DESCRIPTION</description>
<version>0.0.2</version>
<description>VMAUTOCATEGORIES_DESCRIPTION</description>
<files>
<filename plugin="vmProductAutoParentCategories">vmProductAutoParentCategories.php</filename>
<filename plugin="vmProductAutoParentCategories">index.html</filename>
<filename plugin="vmAutoParentCategories">vmAutoParentCategories.php</filename>
<filename plugin="vmAutoParentCategories">index.html</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_system_vmProductAutoParentCategories.ini</language>
<language tag="de-DE">de-DE.plg_system_vmProductAutoParentCategories.ini</language>
<language tag="en-GB">en-GB.plg_system_vmAutoParentCategories.ini</language>
<language tag="de-DE">de-DE.plg_system_vmAutoParentCategories.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field name="run_trigger" type="list" default="never" label="VMPRODPARENTCATS_RUN" description ="VMPRODPARENTCATS_RUN_DESC" >
<option value="never">VMPRODPARENTCATS_RUN_NEVER</option>
<option value="backend-login">VMPRODPARENTCATS_RUN_BACKEND_LOGIN</option>
<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="virtuemart_startpage">VMAUTOCATEGORIES_RUN_VM_STARTPAGE</option>
<option value="virtuemart_products">VMAUTOCATEGORIES_RUN_VM_PRODUCTPAGE</option>
</field>
<field name="normal_products" type="list" default="nothing" label="VMPRODPARENTCATS_NORMAL_PRODUCTS" description ="VMPRODPARENTCATS_NORMAL_PRODUCTS_DESC" >
<option value="nothing">VMPRODPARENTCATS_DO_NOTHING</option>
<option value="add_parents">VMPRODPARENTCATS_ADD_PARENTS</option>
<option value="add_two_leaves">VMPRODPARENTCATS_ADD_ONE_PARENT</option>
<option value="remove_except_leaf">VMPRODPARENTCATS_REMOVE_EXCEPT_LEAF</option>
<field name="normal_products" type="list" default="nothing" label="VMAUTOCATEGORIES_NORMAL_PRODUCTS" description ="VMAUTOCATEGORIES_NORMAL_PRODUCTS_DESC" >
<option value="nothing">VMAUTOCATEGORIES_DO_NOTHING</option>
<option value="add_parents">VMAUTOCATEGORIES_ADD_PARENTS</option>
<option value="add_two_leaves">VMAUTOCATEGORIES_ADD_ONE_PARENT</option>
<option value="remove_except_leaf">VMAUTOCATEGORIES_REMOVE_EXCEPT_LEAF</option>
</field>
<field name="child_products" type="list" default="nothing" label="VMPRODPARENTCATS_CHILD_PRODUCTS" description ="VMPRODPARENTCATS_CHILD_PRODUCTS_DESC" >
<option value="nothing">VMPRODPARENTCATS_DO_NOTHING</option>
<option value="copy_parent">VMPRODPARENTCATS_COPY_CATEGORIES_FROM_PARENT</option>
<option value="remove_all">VMPRODPARENTCATS_REMOVE_ALL</option>
<option value="add_parents">VMPRODPARENTCATS_ADD_PARENTS</option>
<option value="add_two_leaves">VMPRODPARENTCATS_ADD_ONE_PARENT</option>
<option value="remove_except_leaf">VMPRODPARENTCATS_REMOVE_EXCEPT_LEAF</option>
<field name="child_products" type="list" default="nothing" label="VMAUTOCATEGORIES_CHILD_PRODUCTS" description ="VMAUTOCATEGORIES_CHILD_PRODUCTS_DESC" >
<option value="nothing">VMAUTOCATEGORIES_DO_NOTHING</option>
<option value="copy_parent">VMAUTOCATEGORIES_COPY_CATEGORIES_FROM_PARENT</option>
<option value="remove_all">VMAUTOCATEGORIES_REMOVE_ALL</option>
<option value="add_parents">VMAUTOCATEGORIES_ADD_PARENTS</option>
<option value="add_two_leaves">VMAUTOCATEGORIES_ADD_ONE_PARENT</option>
<option value="remove_except_leaf">VMAUTOCATEGORIES_REMOVE_EXCEPT_LEAF</option>
</field>
<field name="debug" type="list" default="report_changes" label="VMPRODPARENTCATS_DEBUG" description ="VMPRODPARENTCATS_DEBUG_DESC" >
<option value="no_output">VMPRODPARENTCATS_DBG_NO_OUTPUT</option>
<option value="report_changes">VMPRODPARENTCATS_DBG_REPORT_CHANGES</option>
<option value="report_always">VMPRODPARENTCATS_DBG_REPORT_ALWAYS</option>
<option value="report_no_change">VMPRODPARENTCATS_DBG_REPORT_NO_CHANGES</option>
<option value="debug">VMPRODPARENTCATS_DBG_DEBUG</option>
<option value="debug_no_changes">VMPRODPARENTCATS_DBG_DEBUG_NO_CHANGES</option>
<field name="debug" type="list" default="report_changes" label="VMAUTOCATEGORIES_DEBUG" description ="VMAUTOCATEGORIES_DEBUG_DESC" >
<option value="no_output">VMAUTOCATEGORIES_DBG_NO_OUTPUT</option>
<option value="report_changes">VMAUTOCATEGORIES_DBG_REPORT_CHANGES</option>
<option value="report_always">VMAUTOCATEGORIES_DBG_REPORT_ALWAYS</option>
<option value="report_no_change">VMAUTOCATEGORIES_DBG_REPORT_NO_CHANGES</option>
<option value="debug">VMAUTOCATEGORIES_DBG_DEBUG</option>
<option value="debug_no_changes">VMAUTOCATEGORIES_DBG_DEBUG_NO_CHANGES</option>
</field>
</fieldset>
</fields>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment