diff --git a/rules_shipping_framework_joomla.php b/rules_shipping_framework_joomla.php index 11eb008025f3ae29f047660744c103ac4f80c4db..8975a4620617cb204de6427d84130ee94591d0df 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'); - }