public function apply($productId) { $product = Product::find($productId); $preferedPartner = $product->preferedPartner->id; print_r($preferedPartner); exit; }
/** * Get tag list id of this article * * @return mixed */ public function getContentAttribute($content) { $content = unserialize($content); $items = []; foreach ($content as $value) { $product = Product::find($value['index']); $item['name'] = $product->name; $item['number'] = $value['number']; $item['unit'] = $product->getUnit->name; array_push($items, $item); } return $items; }
/** * * @param mixed $product * @return type */ public function indexProduct($productId) { $product = Product::find($productId); // check product if (!$product) { logger()->error(sprintf("Product %d not found.", $productId)); return; } logger()->info("Index started"); $indexedProduct = $this->esProduct($product); // print_r($indexedProduct); $params = ["index" => "amanda", "type" => "product", "id" => $product["id"], "body" => $indexedProduct]; $response = $this->esClient->index($params); logger()->info("Finishing indexing", ["id" => $product["id"]]); return $response; }
public function apply($productId) { // find a product $product = \App\Model\Product::find($productId); if (!$product) { // product not found logger()->error(sprintf("Product %d not found.", $productId)); // it should never happen return 0; } // product price $productPrice = $product->price; if ($productPrice) { logger()->debug(sprintf("Found product defined price %f for product %d", $productPrice, $productId)); return $productPrice; } }
public function update(Request $request, $id) { //echo "<pre>";print_r(Request::all());exit; if (Input::hasFile('image1')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image1')->getClientOriginalExtension(); // getting image extension $fileName1 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image1')->move($destinationPath, $fileName1); // uploading file to given path $this->obj->createThumbnail($fileName1, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName1, 109, 89, $destinationPath, $medium); } else { $fileName1 = Request::input('hidden_image1'); } if (Input::hasFile('image2')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image2')->getClientOriginalExtension(); // getting image extension $fileName2 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image2')->move($destinationPath, $fileName2); // uploading file to given path $this->obj->createThumbnail($fileName2, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName2, 109, 89, $destinationPath, $medium); } else { $fileName2 = Request::input('hidden_image2'); } if (Input::hasFile('image3')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image3')->getClientOriginalExtension(); // getting image extension $fileName3 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image3')->move($destinationPath, $fileName3); // uploading file to given path $this->obj->createThumbnail($fileName3, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName3, 109, 89, $destinationPath, $medium); } else { $fileName3 = Request::input('hidden_image3'); } if (Input::hasFile('image4')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image4')->getClientOriginalExtension(); // getting image extension $fileName4 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image4')->move($destinationPath, $fileName4); // uploading file to given path $this->obj->createThumbnail($fileName4, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName4, 109, 89, $destinationPath, $medium); } else { $fileName4 = Request::input('hidden_image4'); } if (Input::hasFile('image5')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image5')->getClientOriginalExtension(); // getting image extension $fileName5 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image5')->move($destinationPath, $fileName5); // uploading file to given path $this->obj->createThumbnail($fileName5, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName5, 109, 89, $destinationPath, $medium); } else { $fileName5 = Request::input('hidden_image5') != '' ? Request::input('hidden_image5') : ''; } if (Input::hasFile('image6')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image6')->getClientOriginalExtension(); // getting image extension $fileName6 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image6')->move($destinationPath, $fileName6); // uploading file to given path $this->obj->createThumbnail($fileName6, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName6, 109, 89, $destinationPath, $medium); } else { $fileName6 = Request::input('hidden_image6'); } $product = Product::find($id); $product['id'] = $id; $product['product_name'] = Request::input('product_name'); $product['product_slug'] = $this->obj->edit_slug($product['product_name'], 'products', 'product_slug', $id); $product['image1'] = $fileName1; $product['image2'] = $fileName2; $product['image3'] = $fileName3; $product['image4'] = $fileName4; $product['image5'] = $fileName5; $product['image6'] = $fileName6; $product['description1'] = htmlentities(Request::input('description1')); $product['description2'] = htmlentities(Request::input('description2')); $product['description3'] = htmlentities(Request::input('description3')); $product['tags'] = Request::input('tags'); $product['script_generated'] = '<a href="' . url() . '/product-details/' . $product['product_slug'] . '" style="color: #FFF;background: #78d5e5 none repeat scroll 0% 0%;padding: 10px 20px;font-weight: 400;font-size: 12px;line-height: 25px;text-shadow: none;border: 0px none;text-transform: uppercase;font-weight: 200;vertical-align: middle;box-shadow: none;display: block;float: left;" onMouseOver="this.style.backgroundColor=\'#afc149\'" onMouseOut="this.style.backgroundColor=\'#78d5e5\'">Buy Now</a>'; $product['created_at'] = date("Y-m-d H:i:s"); $product->save(); // Delete all ingredient before save new ProductIngredientGroup::where('product_id', '=', $id)->delete(); // Delete ingredient group ProductIngredient::where('product_id', '=', $id)->delete(); // Delete ingredient individual // Create Product Ingredient group if (NULL != Request::input('ingredient_group')) { foreach (Request::input('ingredient_group') as $key => $value) { $arr = array('product_id' => $id, 'group_name' => $value['group_name']); $pro_ing_grp = ProductIngredientGroup::create($arr); $group_id = $pro_ing_grp->id; if (NULL != $value['ingredient']) { foreach ($value['ingredient'] as $key1 => $next_value) { $arr_next = array('product_id' => $id, 'ingredient_id' => $next_value['ingredient_id'], 'weight' => $next_value['weight'], 'ingredient_price' => $next_value['ingredient_price'], 'ingredient_group_id' => $group_id); ProductIngredient::create($arr_next); } } } } // Create Product Ingredient foreach (Request::input('ingredient') as $key2 => $ing_value) { $arr_next = array('product_id' => $id, 'ingredient_id' => $ing_value['id'], 'weight' => $ing_value['weight'], 'ingredient_price' => $ing_value['ingredient_price'], 'ingredient_group_id' => 0); ProductIngredient::create($arr_next); } // Delete all Formfactor before save new ProductFormfactor::where('product_id', '=', $id)->delete(); // Add Ingredient form factor foreach (Request::input('formfactor') as $key3 => $formfactor_value) { $arr_pro_fac = array('product_id' => $id, 'formfactor_id' => $formfactor_value['formfactor_id'], 'servings' => $formfactor_value['servings'], 'min_price' => $formfactor_value['min_price'], 'recomended_price' => $formfactor_value['recomended_price'], 'actual_price' => $formfactor_value['actual_price']); ProductFormfactor::create($arr_pro_fac); } // Add Ingredient form factor for available form factor if (Request::input('excluded_val') != "") { $all_form_factor_ids = rtrim(Request::input('excluded_val'), ","); $all_ids = explode(",", $all_form_factor_ids); foreach ($all_ids as $key => $value) { $arr_pro_factor = array('product_id' => $id, 'formfactor_id' => $value); ProductFormfactor::create($arr_pro_factor); } } Session::flash('success', 'Product edit successfully'); return redirect('admin/product-list'); //echo "<pre>";print_r(Request::all());exit; }
public function delete_product($id) { // 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 delete products.'); return redirect('my-products'); } $product_update['id'] = $id; $product_update['discountinue'] = 1; $pro_result = Product::find($product_update['id']); $pro_result->update($product_update); Session::flash('success', 'Product deleted successfully'); return redirect('my-products'); }
/** * API or removing materials being called from js */ public function removeSubProduct(Request $request) { $prodId = $request->input('product_id'); $subProdId = $request->input('sub_product_id'); //delete sub product MainSubProduct::where('product_id', $prodId)->where('sub_product_id', $subProdId)->delete(); //get all subproducts associated $curSubProducts = array(); $curSubProductIds = array(); $subProducts = Product::find($prodId)->sub_products()->get(); foreach ($subProducts as $pm) { //gets the current set materials $subprodExtObject = SubProduct::where('is_active', true)->where('id', $pm->sub_product_id)->first(); array_push($curSubProducts, $subprodExtObject); array_push($curSubProductIds, $pm->sub_product_id); $subprodExtObject = null; } //get all the subproducts not in current main product $allSubProducts = SubProduct::whereNotIn('id', $curSubProductIds)->orderBy('sub_product_name', 'asc')->get(); //return current and all materials return json_encode(array('curSubProducts' => $curSubProducts, 'allSubProducts' => $allSubProducts)); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $article = Product::find($id); $article->update($request->except('id')); return redirect('/product'); }
/** * Get order info by info posted. * * @param Request $request * @return array */ private function getOrderInfo(Request $request, $key) { $order = $request->get($key, []); $items = []; $total['price'] = 0; $total['number'] = 0; foreach ($order as $o) { $product = Product::find($o['index']); $item['index'] = $o['index']; $item['name'] = $product->name; $item['price'] = $product->price * $product->discount * $o['number']; $item['unit'] = $product->getUnit->name; $item['number'] = $o['number']; array_push($items, $item); $total['price'] += $item['price']; $total['number'] += $o['number']; } return array($items, $total); }
public function fetch($productId) { return Product::find($productId); }
public function update(Request $request, $id) { //echo "<pre>";print_r(Request::all());exit; if (Input::hasFile('image1')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image1')->getClientOriginalExtension(); // getting image extension $fileName1 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image1')->move($destinationPath, $fileName1); // uploading file to given path $this->obj->createThumbnail($fileName1, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName1, 109, 89, $destinationPath, $medium); } else { $fileName1 = Request::input('hidden_image1'); } if (Input::hasFile('image2')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image2')->getClientOriginalExtension(); // getting image extension $fileName2 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image2')->move($destinationPath, $fileName2); // uploading file to given path $this->obj->createThumbnail($fileName2, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName2, 109, 89, $destinationPath, $medium); } else { $fileName2 = Request::input('hidden_image2'); } if (Input::hasFile('image3')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image3')->getClientOriginalExtension(); // getting image extension $fileName3 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image3')->move($destinationPath, $fileName3); // uploading file to given path $this->obj->createThumbnail($fileName3, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName3, 109, 89, $destinationPath, $medium); } else { $fileName3 = Request::input('hidden_image3'); } if (Input::hasFile('image4')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image4')->getClientOriginalExtension(); // getting image extension $fileName4 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image4')->move($destinationPath, $fileName4); // uploading file to given path $this->obj->createThumbnail($fileName4, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName4, 109, 89, $destinationPath, $medium); } else { $fileName4 = Request::input('hidden_image4'); } if (Input::hasFile('image5')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image5')->getClientOriginalExtension(); // getting image extension $fileName5 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image5')->move($destinationPath, $fileName5); // uploading file to given path $this->obj->createThumbnail($fileName5, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName5, 109, 89, $destinationPath, $medium); } else { $fileName5 = Request::input('hidden_image5') != '' ? Request::input('hidden_image5') : ''; } if (Input::hasFile('image6')) { $destinationPath = 'uploads/product/'; // upload path $thumb_path = 'uploads/product/thumb/'; $medium = 'uploads/product/medium/'; $extension = Input::file('image6')->getClientOriginalExtension(); // getting image extension $fileName6 = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image6')->move($destinationPath, $fileName6); // uploading file to given path $this->obj->createThumbnail($fileName6, 771, 517, $destinationPath, $thumb_path); $this->obj->createThumbnail($fileName6, 109, 89, $destinationPath, $medium); } else { $fileName6 = Request::input('hidden_image6'); } $product = Product::find($id); $product['id'] = $id; $product['product_name'] = Request::input('product_name'); $product['product_slug'] = $this->obj->edit_slug($product['product_name'], 'products', 'product_slug', $id); $product['image1'] = $fileName1; $product['image2'] = $fileName2; $product['image3'] = $fileName3; $product['image4'] = $fileName4; $product['image5'] = $fileName5; $product['image6'] = $fileName6; $product['description1'] = htmlentities(Request::input('description1')); $product['description2'] = htmlentities(Request::input('description2')); $product['description3'] = htmlentities(Request::input('description3')); $product['tags'] = Request::input('tags'); $product['script_generated'] = '<a href="' . url() . '/product-details/' . $product['product_slug'] . '" style="color: #FFF;background: #78d5e5 none repeat scroll 0% 0%;padding: 10px 20px;font-weight: 400;font-size: 12px;line-height: 25px;text-shadow: none;border: 0px none;text-transform: uppercase;font-weight: 200;vertical-align: middle;box-shadow: none;display: block;float: left;" onMouseOver="this.style.backgroundColor=\'#afc149\'" onMouseOut="this.style.backgroundColor=\'#78d5e5\'">Buy Now</a>'; $product['created_at'] = date("Y-m-d H:i:s"); $product->save(); echo "<pre>"; print_r(Request::all()); exit; }
public function change_related_status() { $product_id = Request::segment(3); $related = Request::segment(4); $pro = Product::find($product_id); $pro['related'] = $related; $pro->save(); Session::flash('success', 'Product updated successfully'); return redirect('admin/product-list/' . $pro['discountinue']); }
public function delete_product($id) { $product_update['id'] = $id; $product_update['discountinue'] = 1; $pro_result = Product::find($product_update['id']); $pro_result->update($product_update); Session::flash('success', 'Product deleted successfully'); return redirect('my-products'); }
function deleteProduct($id) { return Product::find($id)->delete(); }
public function orderCreate(Request $request) { $validator = Validator::make($request->all(), ['customer_id' => 'required|exists:customers,id', 'product_list' => 'required']); if ($validator->fails()) { return response()->json(['success' => false, 'error_code' => ErrorConstants::CUSTOMER_ORDER_CREATE_VALIDATOR_FAILS, 'error_message' => $validator->errors()->getMessages()]); } $customer_id = $request->input('customer_id'); $product_list = $request->input('product_list'); $order = new Order(); $order->order_state_id = 1; $order->customer_id = $customer_id; $order->order_date = Carbon::today(); $order->order_price = 0; $order->save(); $total_price = 0; foreach ($product_list as $product) { $stored_product = Product::find($product['product_id']); $order_item = new OrderItem(); $order_item->order_id = $order->id; $order_item->product_id = $stored_product->id; $order_item->order_item_state_id = 1; $order_item->count = $product['amount']; $order_item->price = $product['amount'] * $stored_product->price; $order_item->save(); $total_price += $order_item->price; } $order->order_price = $total_price; $order->save(); return response()->json(['success' => true]); }
public function delete($id) { Product::find($id)->delete(); return redirect("/products"); }