private static function findAllAncestry($categoryId, $parentCategoriesArray = []) { $category = Category::findOne($categoryId); $parentCategoryId = $category->parent_id; if (!empty($parentCategoryId)) { $parentCategoriesArray[] = $parentCategoryId; return self::findAllAncestry($parentCategoryId, $parentCategoriesArray); } else { return $parentCategoriesArray; } }
/** * Creates a URL according to the given route and parameters. * @param UrlManager $manager the URL manager * @param string $route the route. It should not have slashes at the beginning or the end. * @param array $params the parameters * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL. */ public function createUrl($manager, $route, $params) { $pathInfo = ''; if ($route == $this->categoryRoute && empty($params['id'])) { $pathInfo = $this->prefix; } else { if (($route == $this->productRoute || $route == $this->categoryRoute) && !empty($params['id'])) { $id = $params['id']; $parentId = null; $language = Language::findOne(['lang_id' => $manager->language]); if ($route == $this->productRoute) { $product = Product::findOne($id); if (empty($product)) { return false; } if ($product->getTranslation($language->id) && $product->getTranslation($language->id)->seoUrl) { $pathInfo = $product->getTranslation($language->id)->seoUrl; $parentId = $product->category_id; } else { return false; } } else { if ($route == $this->categoryRoute) { $category = Category::findOne($id); if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) { $pathInfo = $category->getTranslation($language->id)->seoUrl; $parentId = $category->parent_id; } else { return false; } } } while ($parentId != null) { $category = Category::findOne($parentId); if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) { $pathInfo = $category->getTranslation($language->id)->seoUrl . '/' . $pathInfo; $parentId = $category->parent_id; } else { return false; } } if (!empty($this->prefix)) { $pathInfo = $this->prefix . '/' . $pathInfo; } unset($params['id']); } else { return false; } } return $pathInfo . '?' . http_build_query($params); }
/** * Shows or hides category * * @param integer $id * @return mixed * @throws ForbiddenHttpException */ public function actionSwitchShow($id) { $category = Category::findOne($id); if (!empty($category)) { $category->show = !$category->show; $category->save(); } return $this->actionIndex(); }