예제 #1
0
 public static function generateRandomUniqueCode($prefix_code, $table_name, $field_name)
 {
     if ($table_name == 'users') {
         $unique_code = $prefix_code . mt_rand(10000000, 99999999);
     } else {
         $unique_code = $prefix_code . mt_rand(100000, 999999);
     }
     $code_count = \DB::table($table_name)->whereRaw($field_name . " = ? ", array($unique_code))->count();
     if ($code_count > 0) {
         return CUtil::generateRandomUniqueCode($prefix_code, $table_name, $field_name);
     } else {
         return $unique_code;
     }
     return $unique_code;
 }
예제 #2
0
 public function addProduct($input_arr)
 {
     $p_id = 0;
     if (count($input_arr) > 0) {
         $user_id = CUtil::getUserId($input_arr['user_code']);
         $product_code = CUtil::generateRandomUniqueCode('P', 'product', 'product_code');
         $url_slug = \Str::slug($input_arr['product_name']);
         $data_arr = array('product_code' => $product_code, 'product_name' => $input_arr['product_name'], 'product_description' => $input_arr['product_description'], 'meta_title' => '', 'meta_keyword' => '', 'meta_description' => '', 'product_highlight_text' => $input_arr['product_highlight_text'], 'demo_url' => $input_arr['demo_url'], 'demo_details' => $input_arr['demo_details'], 'product_tags' => $input_arr['product_tags'], 'user_section_id' => $input_arr['user_section_id'], 'product_preview_type' => $input_arr['product_preview_type'], 'product_status' => 'Draft', 'product_price_currency' => \Config::get('webshoppack::site_default_currency'), 'product_category_id' => $input_arr['my_category_id'], 'url_slug' => isset($input_arr['url_slug']) ? $input_arr['url_slug'] : $url_slug, 'product_added_date' => \DB::raw('NOW()'), 'last_updated_date' => \DB::raw('NOW()'), 'product_user_id' => $user_id);
         $p_id = Product::insertGetId($data_arr);
         //To add dumb data for product image
         $p_img_arr = array('product_id' => $p_id);
         $p_img_id = ProductImage::insertGetId($p_img_arr);
     }
     return $p_id;
 }