private function fillTree(&$categories, $rootCategoryId) { $tree = array(); $rootCategoryId = (int) $rootCategoryId; foreach ($categories[$rootCategoryId] as $category) { $categoryId = (int) $category['id_category']; $tree[$categoryId] = $category; if (Category::hasChildren($categoryId, $this->getLang(), false, $this->getShop()->id)) { $categoryChildren = Category::getChildren($categoryId, $this->getLang(), false, $this->getShop()->id); foreach ($categoryChildren as $index => $child) { $childId = (int) $child['id_category']; if (!array_key_exists('children', $tree[$categoryId])) { $tree[$categoryId]['children'] = array($childId => $child); } else { $tree[$categoryId]['children'][$childId] = $child; } $categories[$childId] = array($child); } foreach ($tree[$categoryId]['children'] as $childId => $child) { $subtree = $this->fillTree($categories, $childId); foreach ($subtree as $subcategoryId => $subcategory) { $tree[$categoryId]['children'][$subcategoryId] = $subcategory; } } } } return $tree; }
private function fillTree(&$categories, $id_category) { $tree = array(); foreach ($categories[$id_category] as $category) { $tree[$category['id_category']] = $category; if (!empty($categories[$category['id_category']])) { $tree[$category['id_category']]['children'] = $this->fillTree($categories, $category['id_category']); } elseif ($result = Category::hasChildren($category['id_category'], $this->getLang(), false, $this->getShop()->id)) { $tree[$category['id_category']]['children'] = array($result[0]['id_category'] => $result[0]); } } return $tree; }
private function fillTree(&$categories, $id_category) { $tree = array(); foreach ($categories[$id_category] as $category) { $tree[$category['id_category']] = $category; if (!empty($categories[$category['id_category']])) { $tree[$category['id_category']]['children'] = $this->fillTree($categories, $category['id_category']); } elseif ($result = Category::hasChildren($category['id_category'], $this->getLang(), false, (int) Configuration::get('PS_SHOP_DEFAULT'))) { $tree[$category['id_category']]['children'] = array($result[0]['id_category'] => $result[0]); } $sql = 'SELECT p.*, pl.`name` ' . 'FROM `' . _DB_PREFIX_ . 'product` p ' . 'LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $this->getLang() . ' AND pl.`id_shop` = ' . (int) Configuration::get('PS_SHOP_DEFAULT') . ') WHERE p.`id_category_default` = ' . (int) $category['id_category'] . ' AND p.`id_shop_default` = ' . (int) Configuration::get('PS_SHOP_DEFAULT') . ($this->useShopRestriction() ? ' AND p.`id_product` IN (SELECT ps.`id_product` FROM `' . _DB_PREFIX_ . 'product_shop` ps WHERE ps.`id_shop` = ' . (int) $this->getShop()->id . ') ' : '') . ($this->useActiveProducts() ? ' AND p.`active` = 1' : ''); $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false); $tree[$category['id_category']]['products'] = $products; } return $tree; }