예제 #1
0
 /**
  *
  * @param int $productId
  * @return type
  * @throws Exception
  */
 public function all()
 {
     $items = Category::all();
     $_items = [];
     foreach ($items as $item) {
         $_items[] = (object) ["id" => $item->id, "parent_id" => $item->parent_id, "title" => $item->name, "urlKey" => $item->slug, "slug" => $item->slug, "thumbPath" => $item->thumb_path];
     }
     $items = $_items;
     $childs = array();
     foreach ($items as &$item) {
         $childs[$item->parent_id][] =& $item;
     }
     unset($item);
     foreach ($items as &$item) {
         if (isset($childs[$item->id])) {
             $item->childs = $childs[$item->id];
         }
     }
     return $childs[0];
 }
예제 #2
0
 private function getCategory($categoryId)
 {
     $category = Category::find($categoryId);
     $_category = $category;
     $path = "[" . $category->slug . "|" . $category->name . "|" . $category->id . "]";
     $road = $category->slug;
     while ($category->parent_id != 0) {
         $category = Category::find($category->parent_id);
         $path = "[" . $category->slug . "|" . $category->name . "|" . $category->id . "]" . $path;
         $road = $category->slug . "/" . $road;
     }
     return ["name" => $category->name, "slug" => $category->slug, "path" => $path, "id" => $category->id, "road" => $road];
 }
예제 #3
0
 private function generateCategories()
 {
     $categoryId = 1;
     foreach ($this->categorySet as $category) {
         $newCategory = new Category();
         $newCategory->id = $categoryId;
         $newCategory->parent_id = $category["parentId"];
         $newCategory->name = $category["title"];
         $newCategory->slug = str_slug($category["title"]);
         $newCategory->status_id = self::DEFAULT_STATUS_ID;
         $newCategory->save();
         $categoryId++;
     }
 }