public function actionGetCategoryTree() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $getParams = Yii::$app->request->get(); $searchCri = array('product_category_parent_id' => ''); $allCategories = ProductCategory::findAll($searchCri); $jsonData = array(); foreach ($allCategories as $catLvl1) { $currObj = array(); $checked = false; if (!empty($getParams)) { if ($getParams['evalType'] == 'catParentId' && $getParams['evalVal'] == $catLvl1->product_category_id || $getParams['evalType'] == 'catId' && $getParams['evalVal'] == $catLvl1->product_category_id) { $checked = true; } } $currObj['item'] = array('id' => $catLvl1->product_category_id, 'label' => $catLvl1->product_category_name, 'checked' => $checked); if (!empty($catLvl1->subcategories)) { $subCats = $catLvl1->subcategories; foreach ($subCats as $catLvl2) { $checked2 = false; if (!empty($getParams)) { if ($getParams['evalType'] == 'catParentId' && $getParams['evalVal'] == $catLvl2->product_category_id || $getParams['evalType'] == 'catId' && $getParams['evalVal'] == $catLvl2->product_category_id) { $checked2 = true; } } $currObj['children'][]['item'] = array('id' => $catLvl2->product_category_id, 'label' => $catLvl2->product_category_name, 'checked' => $checked2); } } $jsonData[] = $currObj; } return $jsonData; }
public function getRelateCategories() { if ($this->_relateCategories === null) { $this->_relateCategories = []; if ($this->category && $this->category->parent) { $this->_relateCategories = ProductCategory::findAll(['parent_id' => $this->category->parent->id]); } } return $this->_relateCategories; }
public function actionGetCategoryTree() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $productCategoryKeys = $this->getProductCategoryKeys(Yii::$app->request->get('productId')); $productCategories = ProductCategory::findAll(['product_category_parent_id' => '']); return $this->buildCategoryTree($productCategoryKeys, $productCategories); }