<?php

$path = '../../';
require_once $path . 'core/includes/header.inc.php';
use Mtc\Shop\Category;

$result_cats = [0 => "-- Select category --"];

error_reporting(E_ALL);
ini_set('display_errors', 1);

function appendCategory($id = 0, $level = '') {
    global $result_cats;
    $cat_array = CategoryHelper::getCategoryTree($id ,2);
    foreach ($cat_array as $cat) {
        if($cat['is_online_doctor'] == '1') {
            $result_cats[$cat['id']] = $level . $cat['name'];
            if (count($cat['sub_tree']) > 0) {
                appendCategory($cat['id'], $level . '-');
            }
        }
    }
}

appendCategory();

die(json_encode($result_cats));
