public function edit($id)
 {
     // Get All Ingredient whose status != 2
     $ingredients = DB::table('ingredients')->whereNotIn('status', [2])->get();
     // Get All Form factors
     $formfac = FormFactor::all();
     // Get Product details regarding to slug
     $products = DB::table('products')->where('id', $id)->first();
     // Get Ingredient group and their individual ingredients
     $ingredient_group = DB::table('product_ingredient_group')->where('product_id', $products->id)->get();
     $check_arr = $weight_check_arr = $arr = $ing_form_ids = $all_ingredient = $group_ingredient = array();
     $total_count = $tot_price = $tot_weight = 0;
     if (!empty($ingredient_group)) {
         $i = 0;
         foreach ($ingredient_group as $each_ing_gr) {
             $total_group_weight = 0;
             $group_ingredient[$i]['group_name'] = $each_ing_gr->group_name;
             $ingredient_lists = DB::table('product_ingredients')->select(DB::raw('product_ingredients.*,ingredients.price_per_gram,ingredients.name'))->Join('ingredients', 'ingredients.id', '=', 'product_ingredients.ingredient_id')->where('ingredient_group_id', $each_ing_gr->id)->get();
             if (!empty($ingredient_lists)) {
                 foreach ($ingredient_lists as $each_ingredient_list) {
                     $tot_weight += $each_ingredient_list->weight;
                     $total_group_weight += $each_ingredient_list->weight;
                     // collect total price
                     $tot_price += $each_ingredient_list->ingredient_price;
                     // put all ingredient in an array
                     $all_ingredient[$total_count]['id'] = $each_ingredient_list->ingredient_id;
                     $all_ingredient[$total_count]['name'] = $each_ingredient_list->name;
                     $group_ingredient[$i]['all_group_ing'][] = array('ingredient_id' => $each_ingredient_list->ingredient_id, 'weight' => $each_ingredient_list->weight, 'price_per_gram' => $each_ingredient_list->price_per_gram, 'ingredient_price' => $each_ingredient_list->ingredient_price);
                     $total_count++;
                 }
                 $group_ingredient[$i]['tot_weight'] = $total_group_weight;
             }
             $i++;
         }
     }
     //Get All individual ingredient
     $individual_ingredient_lists = DB::table('product_ingredients')->select(DB::raw('product_ingredients.*,ingredients.price_per_gram,ingredients.name'))->Join('ingredients', 'ingredients.id', '=', 'product_ingredients.ingredient_id')->where('ingredient_group_id', 0)->where('product_id', $products->id)->get();
     if (!empty($individual_ingredient_lists)) {
         foreach ($individual_ingredient_lists as $key => $value1) {
             $tot_weight += $value1->weight;
             $tot_price += $value1->ingredient_price;
             // put all ingredient in an array
             $all_ingredient[$total_count]['id'] = $value1->ingredient_id;
             $all_ingredient[$total_count]['name'] = $value1->name;
             $total_count++;
         }
     }
     // Ingredient and their form factors
     if (!empty($all_ingredient)) {
         foreach ($all_ingredient as $key => $value) {
             $arr = array();
             $ing_form_ids = DB::table('ingredients as I')->select(DB::raw('IFF.form_factor_id'))->Join('ingredient_formfactors as IFF', 'I.id', '=', 'IFF.ingredient_id')->where('I.id', $value['id'])->get();
             if (!empty($ing_form_ids)) {
                 foreach ($ing_form_ids as $key1 => $value1) {
                     $arr[] = $value1->form_factor_id;
                 }
             }
             $all_ingredient[$key]['factors'] = $arr;
         }
     }
     //Get All Form factors corresponding to that product
     $pro_form_factor = DB::table('product_formfactors as pff')->select(DB::raw('pff.*,ff.name,ff.price,ff.maximum_weight,ff.minimum_weight'))->Join('form_factors as ff', 'ff.id', '=', 'pff.formfactor_id')->where('product_id', $products->id)->get();
     // Get All formfactor available for this product
     $pro_form_factor_ids = array();
     if (!empty($pro_form_factor)) {
         $j = 0;
         foreach ($pro_form_factor as $key => $value) {
             $pro_form_factor_ids[$j]['formfactor_id'] = $value->formfactor_id;
             $pro_form_factor_ids[$j]['name'] = $value->name;
             $check_arr[] = $value->formfactor_id;
             $j++;
         }
     }
     // Get only those form factor which is created for this particular prouct
     $pro_form_factor = DB::table('product_formfactors as pff')->select(DB::raw('pff.*,ff.name,ff.price,ff.maximum_weight,ff.minimum_weight'))->Join('form_factors as ff', 'ff.id', '=', 'pff.formfactor_id')->where('product_id', $products->id)->where('min_price', '!=', 0)->get();
     // echo "<pre>";print_r($check_arr);exit;
     return view('admin.product.edit', compact('products', 'ingredients', 'all_ingredient', 'check_arr', 'tot_weight', 'tot_price', 'formfac', 'pro_form_factor', 'group_ingredient', 'individual_ingredient_lists', 'pro_form_factor_ids', 'total_count'), array('title' => 'Edit Product'));
 }
Example #2
0
 public function edit_product($slug)
 {
     if (!Session::has('brand_userid')) {
         return redirect('brandLogin');
     }
     // Check if brand subscription expires show message
     $brand_details = Brandmember::find(Session::get('brand_userid'));
     if ($brand_details->subscription_status != "active") {
         Session::flash('error', 'Your subscription is over. Subscribe to edit products.');
         return redirect('my-products');
     }
     // Get All Ingredient whose status != 2
     $ingredients = DB::table('ingredients')->whereNotIn('status', [2])->get();
     // Get All Form factors
     $formfac = FormFactor::all();
     // Get Product details regarding to slug
     $products = DB::table('products')->where('product_slug', $slug)->first();
     // Get Ingredient group and their individual ingredients
     $ingredient_group = DB::table('product_ingredient_group')->where('product_id', $products->id)->get();
     $check_arr = $weight_check_arr = $arr = $ing_form_ids = $all_ingredient = $group_ingredient = array();
     $total_group_count = $total_count = $tot_price = $tot_weight = 0;
     if (!empty($ingredient_group)) {
         $i = 0;
         foreach ($ingredient_group as $each_ing_gr) {
             $total_group_weight = 0;
             $group_ingredient[$i]['group_name'] = $each_ing_gr->group_name;
             $ingredient_lists = DB::table('product_ingredients')->select(DB::raw('product_ingredients.*,ingredients.price_per_gram,ingredients.name'))->Join('ingredients', 'ingredients.id', '=', 'product_ingredients.ingredient_id')->where('ingredient_group_id', $each_ing_gr->id)->get();
             if (!empty($ingredient_lists)) {
                 foreach ($ingredient_lists as $each_ingredient_list) {
                     $tot_weight += $each_ingredient_list->weight;
                     $total_group_weight += $each_ingredient_list->weight;
                     // collect total price
                     $tot_price += $each_ingredient_list->ingredient_price;
                     // put all ingredient in an array
                     $all_ingredient[$total_count]['id'] = $each_ingredient_list->ingredient_id;
                     $all_ingredient[$total_count]['name'] = $each_ingredient_list->name;
                     $group_ingredient[$i]['all_group_ing'][] = array('ingredient_id' => $each_ingredient_list->ingredient_id, 'weight' => $each_ingredient_list->weight, 'price_per_gram' => $each_ingredient_list->price_per_gram, 'ingredient_price' => $each_ingredient_list->ingredient_price);
                     $total_count++;
                 }
                 $group_ingredient[$i]['tot_weight'] = $total_group_weight;
             }
             $total_group_count++;
             $i++;
         }
     }
     //Get All individual ingredient
     $individual_total_count = 0;
     $individual_ingredient_lists = DB::table('product_ingredients')->select(DB::raw('product_ingredients.*,ingredients.price_per_gram,ingredients.name'))->Join('ingredients', 'ingredients.id', '=', 'product_ingredients.ingredient_id')->where('ingredient_group_id', 0)->where('product_id', $products->id)->get();
     if (!empty($individual_ingredient_lists)) {
         foreach ($individual_ingredient_lists as $key => $value1) {
             $tot_weight += $value1->weight;
             $tot_price += $value1->ingredient_price;
             // put all ingredient in an array
             $all_ingredient[$total_count]['id'] = $value1->ingredient_id;
             $all_ingredient[$total_count]['name'] = $value1->name;
             $total_count++;
             $individual_total_count++;
         }
     }
     // Ingredient and their form factors
     if (!empty($all_ingredient)) {
         foreach ($all_ingredient as $key => $value) {
             $arr = array();
             $ing_form_ids = DB::table('ingredients as I')->select(DB::raw('IFF.form_factor_id'))->Join('ingredient_formfactors as IFF', 'I.id', '=', 'IFF.ingredient_id')->where('I.id', $value['id'])->get();
             if (!empty($ing_form_ids)) {
                 foreach ($ing_form_ids as $key1 => $value1) {
                     $arr[] = $value1->form_factor_id;
                 }
             }
             $all_ingredient[$key]['factors'] = $arr;
         }
     }
     //Get All Form factors corresponding to that product
     $pro_form_factor = DB::table('product_formfactors as pff')->select(DB::raw('pff.*,ff.name,ff.price,ff.maximum_weight,ff.minimum_weight'))->Join('form_factors as ff', 'ff.id', '=', 'pff.formfactor_id')->where('product_id', $products->id)->get();
     // Get All formfactor available for this product
     $pro_form_factor_ids = array();
     if (!empty($pro_form_factor)) {
         $j = 0;
         foreach ($pro_form_factor as $key => $value) {
             $pro_form_factor_ids[$j]['formfactor_id'] = $value->formfactor_id;
             $pro_form_factor_ids[$j]['name'] = $value->name;
             $check_arr[] = $value->formfactor_id;
             $j++;
         }
     }
     // Check whether this product owns by brand or miramix
     if ($products->own_product == 1) {
         $cnt = 0;
         foreach ($formfac as $key => $value) {
             $pro_form_factor_ids[$cnt]['formfactor_id'] = $value->id;
             $pro_form_factor_ids[$cnt]['name'] = $value->name;
             $cnt++;
         }
     }
     // Get only those form factor which is created for this particular prouct
     $pro_form_factor = DB::table('product_formfactors as pff')->select(DB::raw('pff.*,ff.name,ff.price,ff.maximum_weight,ff.minimum_weight'))->Join('form_factors as ff', 'ff.id', '=', 'pff.formfactor_id')->where('product_id', $products->id)->where('actual_price', '!=', 0)->get();
     // echo "<pre>";print_r($check_arr);exit;
     // Check Total COunt
     if ($total_count == 0) {
         $total_count++;
     }
     return view('frontend.product.edit', compact('products', 'ingredients', 'all_ingredient', 'check_arr', 'tot_weight', 'tot_price', 'formfac', 'pro_form_factor', 'group_ingredient', 'individual_ingredient_lists', 'pro_form_factor_ids', 'total_count', 'total_group_count', 'individual_total_count'), array('title' => 'Edit Product'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $formfactor = FormFactor::find($id);
     return view('admin.formfactor.edit', compact('formfactor'), array('title' => 'Edit Form Factor', 'module_head' => 'Edit Form Factor'));
 }
 public function edit($id)
 {
     $ingredient = Ingredient::find($id);
     $all_formfactors = FormFactor::all();
     $check_formfactors = DB::table('ingredient_formfactors')->select('form_factor_id')->where('ingredient_id', '=', $id)->get();
     $all_check_formfactors = array();
     foreach ($check_formfactors as $key => $value) {
         $all_check_formfactors[] = $value->form_factor_id;
     }
     //print_r($all_check_formfactors);exit;
     $components = DB::table('components')->where('ingredient_id', '=', $id)->get();
     //echo "<pre>";print_r($components);exit;
     $all_components = array();
     foreach ($components as $each_component) {
         $tmp['vitamins'] = array();
         $tmp['component_details'] = $each_component;
         $vitamins = DB::table('component_vitamins')->select('vitamin', 'weight', 'vitamin_weight')->where('component_id', '=', $each_component->id)->get();
         $m = 0;
         foreach ($vitamins as $key_vitamin => $each_vitamin) {
             $tmp['vitamins'][$m] = $each_vitamin->vitamin;
             $tmp['weights'][$m] = $each_vitamin->weight;
             $tmp['vitamin_weight'][$m] = $each_vitamin->vitamin_weight;
             $m++;
         }
         $all_components[] = $tmp;
     }
     //echo "<pre>";print_r($all_components); exit;
     return view('admin.ingredient.edit', compact('ingredient', 'all_formfactors', 'all_check_formfactors', 'all_components'), array('title' => 'Edit Ingredient', 'module_head' => 'Edit Ingredient'));
 }