public function getRootCategoryId() { $root_cat = ProductCategory::Select('id')->whereRaw('category_level = 0 AND parent_category_id = 0')->first(); if (count($root_cat) > 0) { $this->root_category_id = $root_cat['id']; } return $this->root_category_id; }
public function deleteCategory($del_category_id) { // check category exist or not if (!$this->isCategoryExists($del_category_id)) { $result_arr = array('err' => true, 'err_msg' => trans('webshoppack::admin/manageCategory.delete-category.category_not_found_msg')); return $result_arr; } // check products added for the selected category or its subcategories if ($this->isCategoryProductExists($del_category_id)) { $result_arr = array('err' => true, 'err_msg' => trans('webshoppack::admin/manageCategory.delete-category.category_in_use_msg')); return $result_arr; } // delete category details in all assigned attributes & category image. $cat_sub_category_ids = explode(',', $this->sub_category_ids); $cat_details = ProductCategory::whereIn('id', $cat_sub_category_ids)->get(array('id', 'image_name', 'image_ext')); if (count($cat_details) > 0) { foreach ($cat_details as $cat) { // Delete all attributes assigned to the selected category & its subcategories ProductCategoryAttributes::whereRaw('category_id = ?', array($cat->id))->delete(); // Delete category image $this->deleteImageFiles($cat->image_name, $cat->image_ext, \Config::get("webshoppack::product_category_image_folder")); } } //store the values of the left and right of the category to be deleted //delete all those cateogries b/w the above 2 // update the cateogies to the right of the deleted category - reduce left and right bu width of the deleted category $cat_info = ProductCategory::Select('category_left', 'category_right')->whereRaw('id = ?', array($del_category_id))->first(); if (count($cat_info) > 0) { $category_left = $cat_info['category_left']; $category_right = $cat_info['category_right']; $width = $category_right - $category_left + 1; ProductCategory::whereRaw(\DB::raw('category_left between ' . $category_left . ' AND ' . $category_right))->delete(); //To update category left ProductCategory::whereRaw(\DB::raw('category_left > ' . $category_right))->update(array("category_left" => \DB::raw('category_left - ' . $width))); //To update category right ProductCategory::whereRaw(\DB::raw('category_right > ' . $category_right))->update(array("category_right" => \DB::raw('category_right - ' . $width))); } $result_arr = array('err' => false, 'err_msg' => '', 'category_id' => $del_category_id); return $result_arr; }
public function getCategoryName($cat_id) { $category_name = ''; $cat_info = ProductCategory::Select('category_name')->whereRaw('id = ?', array($cat_id))->first(); if (count($cat_info) > 0) { $category_name = $cat_info['category_name']; } return $category_name; }