本文整理汇总了PHP中ProductCategory::insertGetId方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::insertGetId方法的具体用法?PHP ProductCategory::insertGetId怎么用?PHP ProductCategory::insertGetId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::insertGetId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCategory
public function addCategory($data_arr)
{
if (list($left_id, $right_id, $level) = $this->getNodeInfo($data_arr['parent_category_id'])) {
ProductCategory::where('category_right', '>=', $right_id)->update(array("category_left" => \DB::raw('IF(category_left > ' . $right_id . ',category_left + 2,category_left)'), "category_right" => \DB::raw('IF(category_right >= ' . $right_id . ',category_right + 2, category_right)')));
$data_input_arr['seo_category_name'] = $data_arr['seo_category_name'];
$data_input_arr['category_name'] = $data_arr['category_name'];
$data_input_arr['category_description'] = $data_arr['category_description'];
$data_input_arr['category_meta_title'] = $data_arr['category_meta_title'];
$data_input_arr['category_meta_description'] = $data_arr['category_meta_description'];
$data_input_arr['category_meta_keyword'] = $data_arr['category_meta_keyword'];
$data_input_arr['category_level'] = $this->getCategoryLevel($data_arr['parent_category_id']);
$data_input_arr['category_left'] = $right_id;
$data_input_arr['category_right'] = $right_id + 1;
// available sort by options
$available_sort_by_options = '';
if ($data_arr['use_all_available_sort_options'] == 'Yes') {
$available_sort_by_options = 'all';
}
$data_input_arr['available_sort_options'] = $available_sort_by_options;
$data_input_arr['date_added'] = \DB::raw('NOW()');
$data_input_arr['parent_category_id'] = $data_arr['parent_category_id'];
$data_input_arr['status'] = $data_arr['status'];
$img_arr = array();
if (\Input::hasFile('category_image')) {
$file = \Input::file('category_image');
$image_ext = $file->getClientOriginalExtension();
$image_name = \Str::random(20);
$destinationpath = \URL::asset(\Config::get("webshoppack::product_category_image_folder"));
$img_arr = $this->uploadCategoryImage($file, $image_ext, $image_name, $destinationpath, 0, 'add');
}
$category_id = ProductCategory::insertGetId(array_merge($data_input_arr, $img_arr));
return $category_id;
}
}
示例2: insertRootCategory
public function insertRootCategory()
{
$id = 0;
$root_count = ProductCategory::whereRaw('category_level = 0 AND parent_category_id = 0')->count();
if ($root_count > 0) {
$result = ProductCategory::Select('id')->whereRaw('category_level = 0 AND parent_category_id = 0')->first();
$id = $result['id'];
} else {
$arr['seo_category_name'] = "Root";
$arr['category_left'] = 1;
$arr['category_right'] = 2;
$arr['category_level'] = 0;
$id = ProductCategory::insertGetId($arr);
}
return $id;
}