public function AddLovedProduct($product_id, $list_id = 0) { if (Request::ajax()) { if (Auth::check()) { $customer_id = Auth::user()->id; //them vao danh sach mac dinh if ($list_id == 0) { /*lay id cua danh sach mac dinh*/ $default_list_id = customer::select(["default_list_id"])->where("id", $customer_id)->first(); $list_id = $default_list_id->default_list_id; } /*them san pham vao danh sach*/ /*Kiem tra san pham da co trong yeu thich*/ $array_list_id = LoveList::select(["id"])->where("customer_id", $customer_id)->get()->toArray(); $count = LoveListDetail::whereIn("list_id", $array_list_id)->where("product_id", $product_id)->count(); if ($count > 0) { return json_encode(["result" => "Sản phẩm đã trong yêu thích"]); } else { LoveListDetail::create(["list_id" => $list_id, "product_id" => $product_id]); return json_encode(["result" => "Thêm yêu thích thành công"]); } } else { return redirect()->route("login"); } } else { return redirect()->route("home"); } }
public function AddAddress(CustomerAddrRequest $request) { $firstname = ucfirst($request->get("firstname")); $lastname = ucfirst($request->get("lastname")); $phone = $request->get("phone"); $address = $request->get("address"); $provinceID = $request->get("provinceID"); $districtID = $request->get("districtID"); $wardID = $request->get("wardID"); if (Auth::check()) { $customerID = Auth::user()->id; $info_id = CustomerInfo::create(["customer_id" => $customerID, "first_name" => $firstname, "last_name" => $lastname, "address" => $address, "phone" => $phone, "district_id" => $districtID, "province_id" => $provinceID, "ward_id" => $wardID]); $customer_default_info_id = customer::select(["default_info_id"])->where("id", Auth::user()->id)->first(); if (is_null($customer_default_info_id->default_info_id)) { customer::where("id", Auth::user()->id)->update(["default_info_id" => $info_id->id]); } return redirect()->back(); } else { return redirect()->route("login"); } }