예제 #1
0
 /**
  * Render field template
  *
  * @param Request $request
  * @return string
  * @throws \Exception
  * @throws \Throwable
  */
 public function getCategoryFields(Request $request)
 {
     if ($request->has('category_id')) {
         $productId = $request->get('product_id', null);
         $category = Category::with('fields')->findOrFail($request->get('category_id'));
         $fields = $category->fields()->where('option_id', null)->get();
         $view = view('backend.shop.field.types', compact('fields', 'productId'));
         return $view->render();
     }
 }
예제 #2
0
 /**
  * Rebuilds the tree: update descendants and their order
  * @param type $categories
  * @return type
  */
 public static function rebuildTree($categories)
 {
     if (is_array($categories)) {
         foreach ($categories as $cat) {
             $node = Category::find($cat['id']);
             //$node->descendants->linknodes();
             //loop recursively through the children
             if (isset($cat['children']) && is_array($cat['children']) && count($cat['children'])) {
                 foreach ($cat['children'] as $child) {
                     //append the children to their (old/new)parents
                     $descendant = Category::find($child['id']);
                     $node->appendNode($descendant);
                     //shift the descendants to the bottom to get the right order at the end
                     $shift = count($descendant->getSiblings());
                     $descendant->down($shift);
                     Category::rebuildTree($cat['children']);
                 }
             }
         }
     }
 }
예제 #3
0
 /**
  * Product create form page
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function create()
 {
     $fields = Field::lists('name', 'id')->toArray();
     $categories = ['' => 'Выберите категорию'] + Category::lists('name', 'id')->toArray();
     return view('backend.shop.product.create', compact('categories', 'fields'));
 }
예제 #4
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $results = Category::get();
     $categories = $results->toTree();
     view()->share('categories', $categories);
 }
 /**
  * Reorder nestable
  *
  * @param ShopCategoryReorderRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function setReorder(ShopCategoryReorderRequest $request)
 {
     //@TODO Reorder need fix
     $categories = json_decode($request->get('data'), true);
     Category::updateTreeRoots($categories);
     Category::rebuildTree($categories);
     Category::fixTree();
     // Category::update($categories);
     return response()->json(['status' => 'ok']);
 }