2018-07-20 15:07:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Customer\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-08-23 13:11:56 +00:00
|
|
|
use Webkul\Customer\Repositories\CustomerRepository;
|
2018-09-21 13:43:41 +00:00
|
|
|
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
|
2018-07-27 13:37:56 +00:00
|
|
|
use Webkul\Customer\Models\Customer;
|
2018-08-23 13:11:56 +00:00
|
|
|
use Auth;
|
2018-11-22 16:30:10 +00:00
|
|
|
use Hash;
|
2018-07-20 15:07:16 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* Customer controlller for the customer basically for the tasks of customers which will be done after customer authentication.
|
2018-07-20 15:07:16 +00:00
|
|
|
*
|
2019-08-12 01:26:21 +00:00
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com>
|
2018-07-20 15:07:16 +00:00
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class CustomerController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
2018-11-01 13:48:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CustomerRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2018-08-23 13:11:56 +00:00
|
|
|
protected $customer;
|
2018-07-20 15:07:16 +00:00
|
|
|
|
2018-09-21 13:43:41 +00:00
|
|
|
/**
|
|
|
|
|
* ProductReviewRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $productReview;
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* Create a new Repository instance.
|
2018-09-21 13:43:41 +00:00
|
|
|
*
|
2019-04-08 11:18:43 +00:00
|
|
|
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
|
|
|
|
|
* @param \Webkul\Product\Repositories\ProductReviewRepository $productReview
|
2018-09-21 13:43:41 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-11-01 13:48:59 +00:00
|
|
|
public function __construct(
|
|
|
|
|
CustomerRepository $customer,
|
|
|
|
|
ProductReview $productReview
|
|
|
|
|
)
|
2018-07-20 15:07:16 +00:00
|
|
|
{
|
2018-08-31 06:03:11 +00:00
|
|
|
$this->middleware('customer');
|
|
|
|
|
|
2018-07-20 15:07:16 +00:00
|
|
|
$this->_config = request('_config');
|
2018-08-31 06:03:11 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
$this->customer = $customer;
|
2018-09-21 13:43:41 +00:00
|
|
|
|
|
|
|
|
$this->productReview = $productReview;
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* Taking the customer to profile details page
|
|
|
|
|
*
|
2018-08-23 13:11:56 +00:00
|
|
|
* @return View
|
|
|
|
|
*/
|
2018-11-01 13:48:59 +00:00
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
$customer = $this->customer->find(auth()->guard('customer')->user()->id);
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-11-01 13:48:59 +00:00
|
|
|
return view($this->_config['view'], compact('customer'));
|
2018-07-27 13:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* For loading the edit form page.
|
2018-08-23 13:11:56 +00:00
|
|
|
*
|
|
|
|
|
* @return View
|
|
|
|
|
*/
|
2019-04-01 07:13:44 +00:00
|
|
|
public function edit()
|
2018-11-01 13:48:59 +00:00
|
|
|
{
|
|
|
|
|
$customer = $this->customer->find(auth()->guard('customer')->user()->id);
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-11-01 13:48:59 +00:00
|
|
|
return view($this->_config['view'], compact('customer'));
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|
2018-08-23 13:11:56 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* Edit function for editing customer profile.
|
2018-08-23 13:11:56 +00:00
|
|
|
*
|
|
|
|
|
* @return Redirect.
|
|
|
|
|
*/
|
2019-04-01 07:13:44 +00:00
|
|
|
public function update()
|
2018-11-01 13:48:59 +00:00
|
|
|
{
|
2018-08-23 13:11:56 +00:00
|
|
|
$id = auth()->guard('customer')->user()->id;
|
|
|
|
|
|
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
'first_name' => 'string',
|
|
|
|
|
'last_name' => 'string',
|
|
|
|
|
'gender' => 'required',
|
2018-12-31 11:57:32 +00:00
|
|
|
'date_of_birth' => 'date|before:today',
|
2018-08-23 13:11:56 +00:00
|
|
|
'email' => 'email|unique:customers,email,'.$id,
|
2019-01-29 11:38:02 +00:00
|
|
|
'oldpassword' => 'required_with:password',
|
|
|
|
|
'password' => 'confirmed|min:6'
|
2018-08-23 13:11:56 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$data = collect(request()->input())->except('_token')->toArray();
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if ($data['date_of_birth'] == "") {
|
2018-11-28 07:29:08 +00:00
|
|
|
unset($data['date_of_birth']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 11:38:02 +00:00
|
|
|
if ($data['oldpassword'] != "" || $data['oldpassword'] != null) {
|
|
|
|
|
if(Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
|
2018-11-22 16:30:10 +00:00
|
|
|
$data['password'] = bcrypt($data['password']);
|
|
|
|
|
} else {
|
2018-11-28 07:29:08 +00:00
|
|
|
session()->flash('warning', trans('shop::app.customer.account.profile.unmatch'));
|
2018-11-22 16:30:10 +00:00
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
2019-01-29 11:38:02 +00:00
|
|
|
} else {
|
|
|
|
|
unset($data['password']);
|
|
|
|
|
}
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2019-01-29 11:38:02 +00:00
|
|
|
if ($this->customer->update($data, $id)) {
|
|
|
|
|
Session()->flash('success', trans('shop::app.customer.account.profile.edit-success'));
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2019-04-01 07:13:44 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
2019-01-29 11:38:02 +00:00
|
|
|
} else {
|
|
|
|
|
Session()->flash('success', trans('shop::app.customer.account.profile.edit-fail'));
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2019-04-01 07:13:44 +00:00
|
|
|
return redirect()->back($this->_config['redirect']);
|
2018-08-23 13:11:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 10:33:57 +00:00
|
|
|
/**
|
|
|
|
|
* Load the view for the customer account panel, showing approved reviews.
|
|
|
|
|
*
|
|
|
|
|
* @return Mixed
|
|
|
|
|
*/
|
2018-11-01 13:48:59 +00:00
|
|
|
public function reviews()
|
|
|
|
|
{
|
2019-04-01 07:13:44 +00:00
|
|
|
$reviews = auth()->guard('customer')->user()->all_reviews;
|
2018-09-21 13:43:41 +00:00
|
|
|
|
2018-11-01 13:48:59 +00:00
|
|
|
return view($this->_config['view'], compact('reviews'));
|
2018-08-23 13:11:56 +00:00
|
|
|
}
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|