From 9211f997d0235dc9d1103726aa44a0ff66893086 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sat, 6 Feb 2016 23:20:10 +0100 Subject: [PATCH] Finish evaluate_for_subcategories function --- rules_shipping_framework_joomla.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rules_shipping_framework_joomla.php b/rules_shipping_framework_joomla.php index 11eb008..8975a46 100644 --- a/rules_shipping_framework_joomla.php +++ b/rules_shipping_framework_joomla.php @@ -336,6 +336,23 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework { JPluginHelper::importPlugin('vmshipmentrules'); JDispatcher::getInstance()->trigger('onVmShippingRulesGetCartValues',array(&$values, $cart, $products, $method)); } + + + protected function getCategoryTreeRecursive($catmodel, $parent_category_id, &$categories) { + if ($catmodel->hasChildren($parent_category_id)){ + // We need to call getCategories with vendorID=1, because the + // default "" will cause VM to check the current user for superuser + // access, which he usually does not have, and thus no child + // categories would be displayed. + $childCats = $catmodel->getCategories(/*$onlyPublished*/false, + $parent_category_id, /*child id*/false, /*$keyword*/"", + /*VendorID*/1); + foreach ($childCats as $key => $category) { + $categories[] = $category->virtuemart_category_id; + $this->getCategoryTreeRecursive($catmodel, $category->virtuemart_category_id, $categories); + } + } + } /** Filter the given array of products and return only those that belong to the categories, manufacturers, * vendors or products given in the $filter_conditions. The $filter_conditions is an array of the form: @@ -352,15 +369,9 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework { $catmodel = VmModel::getModel('category'); foreach ($filter_conditions['subcategories'] as $catid) { $subcategories[] = $catid; - // Get all child categories from the category model - $categories = $catmodel->getCategoryTree($catid,0,/*onlyPublished=*/false); - foreach ($categories as $subcat) { - $subcategories[] = $subcat->virtuemart_category_id; - } + $categories = $this->getCategoryTreeRecursive($catmodel, $catid, $subcategories); } $subcategories = array_unique($subcategories); -JFactory::getApplication()->enqueueMessage("<pre>Subcategories: ".print_r($subcategories,1)."</pre>", 'error'); - } -- GitLab