/** * Creates a new Address model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Address(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'address_id' => $model->address_id, 'province_id' => $model->province_id, 'country_id' => $model->country_id, 'customer_id' => $model->customer_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @covers \App\Services\Factories\AddressFactory::modify() */ public function testModify() { $address = new Address(array('street_1' => 'Foo_street_1', 'street_2' => 'Foo_street_2', 'number' => 15, 'box' => 'Foo_box', 'district' => 'Foo_district', 'postal_code' => 'Foo_postal_code', 'city' => 'Foo_city', 'country' => 'us', 'latitude' => 'Foo_latitude', 'longitude' => 'Foo_longitude')); $address->save(); $input = array('street_1' => 'Bar_street_1', 'street_2' => 'Bar_street_2', 'number' => 17, 'box' => 'Bar_box', 'district' => 'Bar_district', 'postal_code' => 'Bar_postal_code', 'city' => 'Bar_city', 'country' => 'be', 'latitude' => 'Bar_latitude', 'longitude' => 'Bar_longitude'); $this->addressFactory->modify($address, $input); $addressRepository = App::make('\\App\\Repositories\\Eloquent\\EloquentAddressRepository'); $this->assertEquals(1, $addressRepository->all()->count()); $this->assertEquals('Bar_street_1', $addressRepository->all()->first()->street_1); }
/** * Creates a new Address model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Address(); $model->user_fk = Yii::$app->user->identity->user_id; $countries = ArrayHelper::map(Country::find()->all(), 'country_id', 'country'); $cities = ArrayHelper::map(City::find()->all(), 'city_id', 'city'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->address_id]); } else { return $this->render('create', ['model' => $model, 'countries' => $countries, 'cities' => $cities]); } }
public function actionAddaddress() { $model = new Address(); $post = Yii::$app->request->post(); $model->userid = Yii::$app->session['userid']; $model->location = $post['address']; $model->address = $post['detail']; $model->telephone = $post['phone']; $model->receiver = $post['name']; $model->code = $post['code']; if ($model->save()) { echo "0"; } }
/** * Creates a new Address model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Address(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->addFlash('success', "Запись \"{$model->fullName}\" успешно добавлена."); return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]); } else { if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) { Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null); } if (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } return $this->render('create', ['model' => $model]); } }
private function createAddress() { $address = new Address(); $address->region = ""; $address->city = ""; $address->district = ""; $address->street = ""; $address->home = ""; $address->housing = ""; $address->building = ""; $address->metro = ""; $address->latitude = 0; $address->longitude = 0; $address->save(); return $address->id; }
public function actionAddress($id = null) { if ($id) { $model = Address::findOne($id); if ($model === null) { throw new NotFoundHttpException('model does not exist.'); } } else { $model = new Address(); } if ($model->load(Yii::$app->request->post())) { $model->user_id = Yii::$app->user->id; if ($model->save()) { return $this->redirect(['cart/checkout']); } } return $this->render('address', ['model' => $model]); }
public function add_address() { $address = new Address(); //dd(Session::get("userId")); $address->user_id = Session::get('user')->id; $address->firstname = Input::get('cname'); $address->lastname = Input::get('lname'); $address->phone = Input::get('phone'); $address->address1 = Input::get('address1'); $address->address2 = Input::get('address2'); $address->address3 = Input::get('address3'); $address->pincode = Input::get('pincode'); $address->city = Input::get('city'); $address->country = Input::get('country'); $address->save(); $addid = $address->id; // dd($addid); return redirect()->back(); }
public function paymentDetails() { // $address = Address::find($user->addresses()->first()->id); $cart = Cart::instance('shopping')->content(); $cartTotal = Cart::instance('shopping')->total(); $address = new Address(); $address->user_id = Session::get('loggedinUserId'); $address->firstname = Input::get('shipping_first_name'); $address->lastname = Input::get('shipping_last_name'); $address->address1 = Input::get('shipping_address_1'); $address->address2 = Input::get('shipping_address_2'); $address->address = Input::get('shipping_landmark'); $address->postcode = Input::get('shipping_postcode'); $address->city = Input::get('shipping_landmark'); $address->country_id = Input::get('shipping_country'); $address->zone_id = Input::get('shipping_state'); $address->save(); $addressId = Session::put('addressId', $address->id); $address = Address::where('id', '=', $addressId)->get(); return view(Config('constants.frontendCheckoutView') . '.payment', compact('address', 'cart', 'cartTotal')); }
public function store(productRequest $request) { /*$validation = Validator::make($request->all(), [ 'name' => 'required', 'O-Shop' => 'required', 'short_description' => 'required', 'product_photo' => 'required', 'retail_price' => 'required', 'original_price' => 'required', 'available' => 'required', 'owarehouse_moq' => 'required', 'owarehouse_price' => 'required', 'product_details' => 'required', ]); if ($validation->fails()) { return redirect('create_new_product') ->withErrors($validation) ->withInput(); } else {*/ /* * Get product last id from product table */ $product_id = Product::orderBy('id', 'desc')->take(1)->get(); foreach ($product_id as $PI) { $Pid = $PI->id; } if (!isset($Pid)) { $Pid = 0; } $Pid = $Pid + 1; /* * Product table section */ $destination = 'public/images/product/' . $Pid . '/'; $image = $request->file('product_photo'); $image_name = $image->getClientOriginalName(); if ($image->move($destination, $image_name)) { //if image moved $pro_table = new Product(); $pro_table->name = $request->name; $pro_table->brand_id = $request->brand_id; $pro_table->category_id = $request->category_id; $pro_table->subcat_id = $request->subcat_id; $pro_table->photo_1 = $destination . $image_name; if (isset($request->free_delivery)) { $pro_table->free_delivery = $request->free_delivery; $pro_table->del_worldwide = 0; $pro_table->del_west_malaysia = 0; $pro_table->del_sabah_labuan = 0; $pro_table->del_sarawak = 0; } else { $pro_table->free_delivery = 0; $pro_table->del_worldwide = $request->del_worldwid; $pro_table->del_west_malaysia = $request->del_west_malaysia; $pro_table->del_sabah_labuan = $request->del_sabah_labuan; $pro_table->del_sarawak = $request->del_sarawak; } $pro_table->cov_country_id = $request->cov_country_id; $pro_table->cov_state_id = $request->cov_state_id; $pro_table->cov_city_id = $request->cov_city_id; $pro_table->retail_price = $request->retail_price; $pro_table->original_price = $request->original_price; $pro_table->available = $request->available; $pro_table->owarehouse_moq = $request->owarehouse_moq; $pro_table->owarehouse_price = $request->owarehouse_price; $pro_table->product_details = $request->product_details; $pro_table->type = 'product'; $pro_table->save(); /* * Unit and price section....Wholesaletable */ for ($i = 0; $i < count($request->wunit); $i++) { $wholwsale_table = new wholesale(); $wholwsale_table->product_id = $Pid; $wholwsale_table->unit = $request->wunit[$i]; $wholwsale_table->price = $request->wprice[$i]; $wholwsale_table->save(); } /* * Dealer section with speacial price....productdealer table */ for ($i = 0; $i < count($request->dealer); $i++) { $productdealer_table = new productdealer(); $productdealer_table->product_id = $Pid; $productdealer_table->dealer_id = $request->dealer[$i]; $productdealer_table->special_unit = $request->sunit[$i]; $productdealer_table->special_price = $request->sprice[$i]; $productdealer_table->save(); } /* * Product Specification section..specification table */ /* * get last spec id */ $spec_id = specification::orderBy('id', 'desc')->take(1)->get(); foreach ($spec_id as $SI) { $Sid = $SI->id; } if (!isset($Sid)) { $Sid = 1; } for ($i = 1; $i <= 6; $i++) { $spec_table = new specification(); $spec_table->name = $request->product_specification_name; $spec_table->description = $request->product_specification_[$i]; $spec_table->save(); //save into subcat_level_1 table; $subcat = new SubCatLevel1Spec(); $subcat->subcat_level_1_id = $request->category_id; $subcat->spec_id = $Sid; $subcat->save(); $Sid = $Sid + 1; } /* * Seller information section..address table */ $address_table = new Address(); $address_table->city_id = 0; $address_table->line1 = $request->SFA1; $address_table->line2 = $request->SFA3; $address_table->line3 = $request->SFA3; $address_table->save(); /* * get last enter adress id */ $address_id = Address::orderBy('id', 'desc')->take(1)->get(); foreach ($address_id as $AI) { $Aid = $AI->id; } /* * O-shop and shot-description section ....merchant table */ $merchant_table = new Merchant(); $merchant_table->User_id = 1; //here we get user id//Auth()::user()->id; $merchant_table->oshop_name = $request->O - Shop; $merchant_table->oshop_name = $request->description; $merchant_table->oshop_address_id = $Aid; $merchant_table->contact_person = $request->seller_name; $merchant_table->return_policy = $request->return_policy; $merchant_table->save(); return "Data saved into tables"; } //} }
/** * Save a model with it's relations. * * @param $data * @param null $id * * @return static */ public static function save($data, $id = null) { if ($id) { $employee = Employee::findOrFail($id); $employee->fill($data); } else { $employee = Employee::create($data); } Address::whereEmployeeId($employee->id)->delete(); // flush Course::whereEmployeeId($employee->id)->delete(); foreach (array_get($data, 'address', []) as $key => $d) { if (empty($d['city']) && empty($d['street']) && empty($d['number'])) { continue; } $address = new Address($d); $address->employee_id = $employee->id; $address->save(); } foreach (array_get($data, 'course', []) as $key => $d) { if (empty($d['title']) && empty($d['start']) && empty($d['end'])) { continue; } $course = new Course($d); $course->employee_id = $employee->id; $course->save(); } $employee->save(); return $employee; }
public function store(Request $request) { /*$validation = Validator::make($request->all(), [ 'name' => 'required', 'O-Shop' => 'required', 'short_description' => 'required', 'product_photo' => 'required', 'retail_price' => 'required', 'original_price' => 'required', 'available' => 'required', 'owarehouse_moq' => 'required', 'owarehouse_price' => 'required', 'product_details' => 'required', ]); if ($validation->fails()) { return redirect('create_new_product') ->withErrors($validation) ->withInput(); } else {*/ /* * Get product last id from product table */ $product_id = Product::orderBy('id', 'desc')->take(1)->get(); foreach ($product_id as $PI) { $Pid = $PI->id; } if (!isset($Pid)) { $Pid = 0; } $Pid = $Pid + 1; /* * Product table section */ $destination = 'public/images/product/' . $Pid . '/'; $image = $request->file('product_photo'); $image_name = $image->getClientOriginalName(); if ($image->move($destination, $image_name)) { //if image moved $pro_table = new Product(); $pro_table->name = $request->name; $pro_table->brand_id = $request->brand_id; $pro_table->category_id = $request->category_id; $pro_table->subcat_id = $request->subcat_id; $pro_table->photo_1 = $destination . $image_name; $pro_table->retail_price = $request->retail_price; $pro_table->original_price = $request->original_price; $pro_table->available = $request->Quantity; $pro_table->product_details = $request->product_details; $pro_table->type = 'voucher'; $pro_table->save(); /* * address table */ $address_table = new Address(); $address_table->city_id = 0; $address_table->line1 = $request->VL1; $address_table->line2 = $request->VL1; $address_table->line3 = $request->VL1; $address_table->save(); /* * get last enter adress id */ $address_id = Address::orderBy('id', 'desc')->take(1)->get(); foreach ($address_id as $AI) { $Aid = $AI->id; } /* * Voucher section....voucher table */ //for($i=0;$i<count($request->wholeweek);$i++) {if user chose multi checkboxs $voucher_table = new voucher(); $voucher_table->product_id = $Pid; $voucher_table->validity = $request->whole; $voucher_table->weekly_duration = $request->wholeweek; $voucher_table->start_duration = $request->start_duration; $voucher_table->end_duration = $request->years . '-' . $request->months . '-' . $request->days; $voucher_table->address_id = $Aid; $voucher_table->save(); //} /* * get last enter voucher id */ $voucher_id = voucher::orderBy('id', 'desc')->take(1)->get(); foreach ($voucher_id as $VI) { $Vid = $VI->id; } /* * Timealot section....timeslot table * timeslot may b many */ for ($i = 0; $i < count($request->from); $i++) { $timeslot_table = new timeslot(); $timeslot_table->voucher_id = Vid; $timeslot_table->from = $request->from[$i]; $timeslot_table->to = $request->to[$i]; $timeslot_table->price = $request->myrprice[$i]; $timeslot_table->pax_per_table = $request->fixedprice[$i]; $timeslot_table->save(); } /* * Unit and price section....Wholesaletable */ for ($i = 0; $i < count($request->wunit); $i++) { $wholwsale_table = new wholesale(); $wholwsale_table->product_id = $Pid; $wholwsale_table->unit = $request->wunit[$i]; $wholwsale_table->price = $request->wprice[$i]; $wholwsale_table->save(); } /* * Dealer section with speacial price....productdealer table */ for ($i = 0; $i < count($request->dealer); $i++) { $productdealer_table = new productdealer(); $productdealer_table->product_id = $Pid; $productdealer_table->dealer_id = $request->dealer[$i]; $productdealer_table->special_unit = $request->sunit[$i]; $productdealer_table->special_price = $request->sprice[$i]; $productdealer_table->save(); } /* * Product Specification section..specification table */ /* * get last spec id */ $spec_id = specification::orderBy('id', 'desc')->take(1)->get(); foreach ($spec_id as $SI) { $Sid = $SI->id; } if (!isset($Sid)) { $Sid = 1; } for ($i = 1; $i <= 6; $i++) { $spec_table = new specification(); $spec_table->name = $request->product_specification_name; $spec_table->description = $request->product_specification_[$i]; $spec_table->save(); //save into subcat_level_1 table; $subcat = new SubCatLevel1Spec(); $subcat->subcat_level_1_id = $request->category_id; $subcat->spec_id = $Sid; $subcat->save(); $Sid = $Sid + 1; } /* * Seller information section..address table */ $address_table = new Address(); $address_table->city_id = 0; $address_table->line1 = $request->SFA1; $address_table->line2 = $request->SFA3; $address_table->line3 = $request->SFA3; $address_table->save(); /* * get last enter adress id */ $address_id = Address::orderBy('id', 'desc')->take(1)->get(); foreach ($address_id as $AI) { $Aid = $AI->id; } /* * O-shop and shot-description section ....merchant table */ $merchant_table = new Merchant(); $merchant_table->user_id = 1; //here we get user id//Auth()::user()->id; $merchant_table->oshop_name = $request->O - Shop; $merchant_table->oshop_name = $request->description; $merchant_table->oshop_address_id = $Aid; $merchant_table->contact_person = $request->seller_name; $merchant_table->return_policy = $request->return_policy; $merchant_table->save(); return "Data saved into tables"; } //} }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $validator = Validator::make(Request::all(), ['name' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors()); } else { try { $person = new Person(); $person->name = Input::get('name'); $person->last_name = Input::get('last_name'); $person->document = Input::get('document') == '' ? null : Input::get('document'); $person->identity = Input::get('identity') == '' ? null : Input::get('identity'); $person->email = Input::get('email') == '' ? null : Input::get('email'); $person->birthdate = Input::get('birthdate'); $person->nationality = Input::get('nationality'); $person->gender = Input::get('gender'); $person->phone = Input::get('phone'); $person->phone_cel = Input::get('phone_cel'); $person->name = Input::get('name'); $person->name = Input::get('name'); $person->save(); $member = new Member(); $member->father = Input::get('father'); $member->mother = Input::get('mother'); $member->marital_status_id = Input::get('marital_status_id'); $member->date_baptism = Input::get('date_baptism'); $member->occupacion = Input::get('occupacion'); $member->function_id = Input::get('function_id'); $member->literacy_id = Input::get('literacy_id'); $member->person_id = $person->id; $member->save(); $address = new Address(); $address->address = Input::get('address'); $address->number = Input::get('number'); $address->complement = Input::get('complement'); $address->zip_code = Input::get('zip_code'); $address->reference = Input::get('reference'); $address->country = Input::get('country'); $address->state = Input::get('state'); $address->city = Input::get('city'); $address->person_id = $person->id; $address->save(); return redirect('members'); } catch (\Illuminate\Database\QueryException $e) { print_r($e->errorInfo); } } }
/** * Save user profile * @return boolean whether the user is created successfully */ public function saveProfile() { if (YII_DEBUG) { error_log("[ProfileForm::saveProfile]"); } if (YII_DEBUG) { error_log("[ProfileForm::saveProfile] attributes : " . json_encode($this->getAttributes())); } if ($this->isEditable) { $formData = Yii::$app->request->post('ProfileForm'); if ($formData) { $this->processFileField('photo', $this->_user); $_email = isset($formData['email']) ? strval($formData['email']) : null; if ($_email && $this->_user->email !== $_email) { $v = new EmailValidator(); $err = null; if ($v->validate($_email)) { $u = User::findOne(['email' => $_email]); if (null !== $u) { $err = 'Email already exists'; } else { $this->_user->email = $_email; } } else { $err = 'Not a valid email address'; } if ($err) { Yii::$app->session->addFlash('email', $err); } } $_phone = isset($formData['phone']) ? strval($formData['phone']) : null; if ($_phone && 0 == $this->_user->phone_verified && $this->_user->phone !== $_phone) { $err = User::validatePhone($_phone); if (true === $err) { $u = User::findOne(['phone' => $_phone]); if (null !== $u) { $err = 'Phone already exists'; } else { $this->_user->phone = $_phone; $this->_user->phone_verified = 0; $this->_user->generatePhoneToken(); } } if (is_string($err)) { Yii::$app->session->addFlash('phone', $err); } } $_address = isset($formData['address']) ? strval($formData['address']) : null; if ($_address && 0 < strlen($_address)) { $addr = Address::findOne(['address' => $_address]); if (!$addr) { $addr = new Address(); $addr->address = $_address; $addr->save(); } if (User::$_TYPE_CUSTOMER === $this->_user->user_type) { $rua = RelUserAddress::findOne(['user_id' => $this->_user->id, 'address_id' => $addr->id]); if (!$rua) { $rua = new RelUserAddress(); $rua->user_id = $this->_user->id; $rua->address_id = $addr->id; $rua->save(); } } else { $rua = RelUserAddress::findOne(['user_id' => $this->_user->id]); if (!$rua) { $rua = new RelUserAddress(); $rua->user_id = $this->_user->id; } $rua->address_id = $addr->id; $rua->save(); } } $_fName = isset($formData['firstName']) ? strval($formData['firstName']) : null; if (strlen($_fName) > 0 && $this->_user->first_name !== $_fName) { $this->_user->first_name = $_fName; } $_lName = isset($formData['lastName']) ? strval($formData['lastName']) : null; if (strlen($_lName) > 0 && $this->_user->last_name !== $_lName) { $this->_user->last_name = $_lName; } $_ccInfo = isset($formData['creditCardInfo']) ? strval($formData['creditCardInfo']) : null; if ($this->_user->ccard_info !== $_ccInfo) { $this->_user->ccard_info = $_ccInfo; } if (User::$_TYPE_DRIVER === $this->_user->user_type) { $this->_car = Car::findOne(['driver_id' => $this->_user->id]); if (!$this->_car) { $this->_car = new Car(); $this->_car->driver_id = $this->_user->id; $this->_car->save(); } $this->processFileField('car_photo', $this->_car); $this->processFileField('license_photo', $this->_user); $this->processFileField('insurance_photo', $this->_user); $_priceMile = isset($formData['priceMile']) ? strval($formData['priceMile']) : null; if (strlen($_priceMile) > 0 && $this->_car->price_mile !== $_priceMile) { $this->_car->price_mile = $_priceMile; } $_carMake = isset($formData['carMake']) ? strval($formData['carMake']) : null; if (strlen($_carMake) > 0 && $this->_car->make !== $_carMake) { $this->_car->make = $_carMake; } $_carModel = isset($formData['carModel']) ? strval($formData['carModel']) : null; if (strlen($_carModel) > 0 && $this->_car->model !== $_carModel) { $this->_car->model = $_carModel; } $_carYear = isset($formData['carYear']) ? strval($formData['carYear']) : null; if (strlen($_carYear) > 0 && $this->_car->year !== $_carYear) { $this->_car->year = $_carYear; } $_licensePlateNumber = isset($formData['licensePlateNumber']) ? strval($formData['licensePlateNumber']) : null; $_existing_car = Car::findOne(['license_plate' => $_licensePlateNumber]); if ($_existing_car) { Yii::$app->session->addFlash('license_plate', 'License plate number already registered'); } elseif (strlen($_licensePlateNumber) > 0 && $this->_car->license_plate !== $_licensePlateNumber) { $this->_car->license_plate = $_licensePlateNumber; } $this->_car->save(); } } $this->_user->save(); } $this->loadData(); return true; }
public function fb_details() { $user_email = Input::get('email'); $user_id = Input::get('user_id'); $firstname = Input::get('firstname'); $lastname = Input::get('lastname'); $user = User::where("email", "=", $user_email)->first(); if (!empty($user)) { Session::put('logged_in_user', $user->email); Session::put('loggedinUserId', $user->id); Session::put('userName', $user->first_name . " " . $user->last_name); Session::put('login_user_type', $user->user_type); Session::put('login_user_first_name', $user->first_name); Session::put('login_user_last_name', $user->last_name); $login = Auth::login(User::find($user->id)); redirect('home'); } else { $user = new User(); $user->email = $user_email; $user->first_name = $firstname; $user->last_name = $lastname; $user->user_type = 2; $user->fb_id = $user_id; $user->platform = "Facebook"; if ($user->save()) { $address = new Address(); $address->user_id = $user->id; $address->firstname = $firstname; $address->lastname = $lastname; $address->save(); Session::put('logged_in_user', $user_email); Session::put('loggedinUserId', $user->id); Session::put('login_user_type', 2); Session::put('userName', $firstname . " " . $lastname); Session::put('login_user_last_name', $lastname); Session::put('login_user_first_name', $firstname); $login = Auth::login(User::find($user->id)); redirect('myProfile'); } } }