function filter_get($categoryID = null) { global $mc; $price = null; $options = null; $products = null; $all_products = null; $offset = 0; if ($_POST['filter']) { extract($_POST['filter']); if ($price) { $conditions['price'] = $price; } } $categories = array($categoryID); $categories = array_merge($categories, getBranchID($mc, $categoryID)); $result = f_products($categories, $conditions); extract($result); if ($products && $options) { $conditions = f_options($options); $products = f_variants($products, $conditions); } $result = f_result($products, $all_products); $pagination = f_pagination(count($products), $offset); $result['pagination'] = $pagination; $result['data'] = f_data($products, $pagination); return $result; }
function getBranchID($tree, $parentId = 1) { $branch = array(); foreach ($tree as $id => $parent) { if ($parent == $parentId) { $children = getBranchID($tree, $id); if (!empty($children)) { foreach ($children as $k => $v) { $branch[] = $v; } } $branch[] = $id; } } return $branch; }