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

Initial checkin, plugin is installable and retrieves cats and products, but does nothing else

parents
No related branches found
No related tags found
No related merge requests found
Makefile 0 → 100644
BASE=vmProductAutoParentCategories
PLUGINTYPE=system
VERSION=0.1
PLUGINFILES=$(BASE).php $(BASE).xml index.html
# TRANSDIR=../../../administrator/language/
# TRANSLATIONS=$(call wildcard,$(TRANSDIR)/*/*.plg_$(PLUGINTYPE)_$(BASE).sys.ini)
TRANSLATIONS=$(call wildcard,*.plg_$(PLUGINTYPE)_$(BASE).*ini)
ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip
zip: $(PLUGINFILES) $(TRANSLATIONS)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES)
@zip -r --junk-paths $(ZIPFILE) $(TRANSLATIONS)
clean:
rm -f $(ZIPFILE)
; @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"
; @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."
VMPRODAUTOPARENTCATEGORIES="TEST Message!!!"
\ No newline at end of file
<html><body bgcolor="#FFFFFF"></body></html>
\ No newline at end of file
File added
<?php
/**
* @plugin VMProductAutoParentCategories
* @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' );
jimport('joomla.event.plugin');
class plgSystemVMProductAutoParentCategories extends JPlugin {
function onAfterRoute(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
$option = JRequest::getCmd('option');
if($option != 'com_virtuemart') return;
JFactory::getApplication()->enqueueMessage(JText::_('VMPRODAUTOPARENTCATEGORIES'), 'message');
$this->updateCategories();
}
function onLoginUser(){
/** Alternatively you may use chaining */
if(!JFactory::getApplication()->isAdmin()) return;
JFactory::getApplication()->enqueueMessage("onLoginUser", 'message');
}
function updateCategories() {
$app = JFactory::getApplication();
print_r($this->params);
$dbg = $this->params->get('debug','report_changes');
$apply = TRUE; // Whether to apply the changes at all
$report = TRUE; // Whether to report changes
$debug = FALSE; // Verbose debug output?
switch ($debug) {
case 'no_output': $report = FALSE; break;
case 'report_changes': break;
case 'report_always': break;
case 'report_no_change': $apply = FALSE; break;
case 'debug': $debug = TRUE; break;
case 'debug_no_changes': $apply = FALSE; $debug = FALSE; break;
}
if (!class_exists('VmConfig'))
require JPATH_ROOT.'/administrator/components/com_virtuemart/helpers/config.php';
if (!class_exists('VmImage'))
require JPATH_ROOT.'/administrator/components/com_virtuemart/helpers/image.php'; // needs to be loaded or receive "ensure that the class definition "VmImage" of the object you are trying to operate on was loaded..."
if (!class_exists('VirtueMartModelCategory'))
require JPATH_ROOT.'/administrator/components/com_virtuemart/models/category.php';
$catmodel = new VirtueMartModelCategory();
$cattree = $catmodel->getCategoryTree();
// Store the names and parents for each category id
foreach ($cattree as $cat) {
$catnames[$cat->virtuemart_category_id] = $cat->category_name;
$catparents[$cat->virtuemart_category_id] = $cat->category_parent_id;
}
if ($debug) {
$app->enqueueMessage(JText::sprintf('VMPRODPARENTCATS_DEBUG_LOADCATS', $cattree), 'message');
}
if (!class_exists('VirtueMartModelProduct'))
require JPATH_ROOT.'/administrator/components/com_virtuemart/models/product.php';
$productmodel = new VirtueMartModelProduct();
$productmodel->_noLimit = true;
$products = $productmodel->getProductListing();
// First, look only at parent products
foreach ($products as $p) {
if ($p->product_parent_id) continue;
$cats = $p->categories;
// foreach
print($p->product_name.'\n');
print($p->product_sku.'\n');
print($p->product_parent_id.'\n'); // Is Child?
print($p->categories.'\n');
print($p->virtuemart_category_id.'\n\n');
// [categories] => Array
// (
// [0] => 4
// )
//
// [virtuemart_category_id] => 4
//
}
// print_r($products);
$pp = $productmodel->sortSearchListQuery(FALSE, FALSE, FALSE, FALSE);
print_r($pp);
// sortSearchListQuery ($onlyPublished = TRUE, $virtuemart_category_id = FALSE, $group = FALSE, $nbrReturnProducts = FALSE)
// $var = $this->params->get($name,'');
$app->enqueueMessage(JText::_('VMPRODAUTOPARENTCATEGORIES'), 'message');
// if (!class_exists('VirtueMartCart'))
// require JPATH_ROOT.'/components/com_virtuemart/helpers/cart.php';
// $cart = VirtueMartCart::getCart();
// if(empty($cart->BT)) return;
// if (!class_exists('VirtueMartModelState'))
// require JPATH_ROOT.'/administrator/components/com_virtuemart/models/state.php';
// $db = JFactory::getDBO();
// $sql = 'SELECT category_parent_id, category_child_id FROM #__vm_user_info WHERE user_info_id="'.$ship_to_info_id.'"'
// : 'SELECT state,country FROM #__vm_user_info WHERE user_id='.$user->id.' AND address_type="BT"';
// $db->setQuery($sql);
// $tmp = $db->loadObject();
// if(empty($tmp)) return;
}
// function onAfterRouteVM2(){
// $option = JRequest::getCmd('option');
// if($option != 'com_virtuemart') return;
//
// if (!class_exists('VmConfig')) require JPATH_ROOT.'/administrator/components/com_virtuemart/helpers/config.php';
// if (!class_exists('VmImage')) require JPATH_ROOT.'/administrator/components/com_virtuemart/helpers/image.php'; // needs to be loaded or receive "ensure that the class definition "VmImage" of the object you are trying to operate on was loaded..."
// if (!class_exists('VirtueMartCart')) require JPATH_ROOT.'/components/com_virtuemart/helpers/cart.php';
// $cart = VirtueMartCart::getCart();
//
//
// if(empty($cart->BT)) return;
//
//
//
// if (!class_exists('VirtueMartModelCountry')) require JPATH_ROOT.'/administrator/components/com_virtuemart/models/country.php';
// if (!class_exists('VirtueMartModelState')) require JPATH_ROOT.'/administrator/components/com_virtuemart/models/state.php';
//
// $address = empty($cart->ST) ? $cart->BT : $cart->ST;
//
// $c_class = new VirtueMartModelCountry();
// $c_class->_id = $address['virtuemart_country_id'];
// $c_obj = $c_class->getData();
// $u_country = $c_obj->country_3_code;
//
// if(empty($u_country)) return;
//
// $s_class = new VirtueMartModelState();
// $s_class->_id = $address['virtuemart_state_id'];
// $s_obj = $s_class->getData();
// $u_state = $s_obj->state_2_code;
//
//
//
// $rules = array();
// for($i=0; $i<20; $i++) {
//
// $products = $this->_toarray('product'.($i+1));
// $countries = $this->_toarray('country'.($i+1));
// $states = $this->_toarray('state'.($i+1));
//
// if(empty($products) || empty($countries)) continue;
// if(!empty($states) && count($countries)>1) continue;
//
// foreach($products as $product) {
// foreach($countries as $country) {
// $product = strtolower($product);
// if(!empty($rules[$product][$country])) $rules[$product][$country] = array_merge($rules[$product][$country],$states);
// else $rules[$product][$country] = $states;
// }
// }
// }
// if(empty($rules)) return;
//
// $items_to_delete = array();
// foreach($cart->products as $product_cart_id=>$item) {
// //if(!isset($item->product_sku)) continue;
//
// $product_key = strtolower($item->product_sku);
// if(!isset($rules[$product_key][$u_country])) continue;
//
// if(empty($rules[$product_key][$u_country]) || in_array($u_state,$rules[$product_key][$u_country])) $items_to_delete[] = $product_cart_id;
// }
// if(!empty($items_to_delete)) {
// foreach($items_to_delete as $product_id) $cart->removeProductCart($product_id);
// JFactory::getLanguage()->load('plg_system_vmProductLocExclude',JPATH_ADMINISTRATOR);
// JFactory::getApplication()->enqueueMessage(JText::_('VMPRODUCTLOCEXCLUDE_WARNING'), 'error');
// }
//
// }
//
//
// function _toarray($name) {
// $var = $this->params->get($name,'');
// if(empty($var)) return array();
// $var = explode(',',$var);
//
// $o = array();
// foreach($var as $row) if(!empty($row)) $o[] = trim($row);
// return $o;
// }
//
}
<?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>
<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>
<files>
<filename plugin="vmProductAutoParentCategories">vmProductAutoParentCategories.php</filename>
<filename plugin="vmProductAutoParentCategories">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>
</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>
<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>
<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>
<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>
</fieldset>
</fields>
</config>
</install>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment