various code style improvements
This commit is contained in:
parent
d42236974d
commit
9524c78ad5
|
|
@ -20,25 +20,26 @@ class AddressController extends Controller
|
|||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
|
||||
/**
|
||||
* Customer Repository object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
|
||||
/**
|
||||
* CustomerAddress Repository object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
*/
|
||||
protected $customerAddress;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Customer\Repositories\CustomerAddressRepository $customerAddress
|
||||
* @param Webkul\Customer\Repositories\CustomerAddressRepository $customerAddress
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -59,7 +60,7 @@ class AddressController extends Controller
|
|||
* @return Mixed
|
||||
*/
|
||||
public function index($id)
|
||||
{
|
||||
{
|
||||
$customer = $this->customer->find($id);
|
||||
|
||||
return view($this->_config['view'], compact('customer'));
|
||||
|
|
@ -84,20 +85,22 @@ class AddressController extends Controller
|
|||
*/
|
||||
public function store()
|
||||
{
|
||||
request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]);
|
||||
request()->merge([
|
||||
'address1' => implode(PHP_EOL, array_filter(request()->input('address1')))
|
||||
]);
|
||||
|
||||
$data = collect(request()->input())->except('_token')->toArray();
|
||||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required'
|
||||
'phone' => 'required',
|
||||
]);
|
||||
|
||||
if ( $this->customerAddress->create($data) ) {
|
||||
if ($this->customerAddress->create($data)) {
|
||||
session()->flash('success', trans('admin::app.customers.addresses.success-create'));
|
||||
|
||||
return redirect()->route('admin.customer.addresses.index', ['id' => $data['customer_id']]);
|
||||
|
|
@ -132,18 +135,18 @@ class AddressController extends Controller
|
|||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required'
|
||||
'phone' => 'required',
|
||||
]);
|
||||
|
||||
$data = collect(request()->input())->except('_token')->toArray();
|
||||
|
||||
$address = $this->customerAddress->find($id);
|
||||
|
||||
if ( $address ) {
|
||||
if ($address) {
|
||||
|
||||
$this->customerAddress->update($data, $id);
|
||||
|
||||
|
|
@ -157,7 +160,8 @@ class AddressController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ class CustomerController extends Controller
|
|||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
/**
|
||||
* CustomerGroupRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customerGroupRepository;
|
||||
|
||||
/**
|
||||
/**
|
||||
* ChannelRepository object
|
||||
*
|
||||
* @var array
|
||||
|
|
@ -74,13 +74,13 @@ class CustomerController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view($this->_config['view']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
|
|
@ -91,10 +91,10 @@ class CustomerController extends Controller
|
|||
|
||||
$channelName = $this->channelRepository->all();
|
||||
|
||||
return view($this->_config['view'], compact('customerGroup','channelName'));
|
||||
return view($this->_config['view'], compact('customerGroup', 'channelName'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
|
|
@ -102,16 +102,16 @@ class CustomerController extends Controller
|
|||
public function store()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'gender' => 'required',
|
||||
'email' => 'required|unique:customers,email',
|
||||
'date_of_birth' => 'date|before:today'
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'gender' => 'required',
|
||||
'email' => 'required|unique:customers,email',
|
||||
'date_of_birth' => 'date|before:today',
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$password = rand(100000,10000000);
|
||||
$password = rand(100000, 10000000);
|
||||
|
||||
$data['password'] = bcrypt($password);
|
||||
|
||||
|
|
@ -133,7 +133,8 @@ class CustomerController extends Controller
|
|||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
|
|
@ -147,20 +148,21 @@ class CustomerController extends Controller
|
|||
return view($this->_config['view'], compact('customer', 'customerGroup', 'channelName'));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'gender' => 'required',
|
||||
'email' => 'required|unique:customers,email,'. $id,
|
||||
'date_of_birth' => 'date|before:today'
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'gender' => 'required',
|
||||
'email' => 'required|unique:customers,email,' . $id,
|
||||
'date_of_birth' => 'date|before:today',
|
||||
]);
|
||||
|
||||
$this->customerRepository->update(request()->all(), $id);
|
||||
|
|
@ -173,7 +175,8 @@ class CustomerController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
|
|
@ -186,7 +189,7 @@ class CustomerController extends Controller
|
|||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Customer']));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Customer']));
|
||||
}
|
||||
|
||||
|
|
@ -213,13 +216,13 @@ class CustomerController extends Controller
|
|||
public function storeNote()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'notes' => 'string|nullable'
|
||||
'notes' => 'string|nullable',
|
||||
]);
|
||||
|
||||
$customer = $this->customerRepository->find(request()->input('_customer'));
|
||||
|
||||
$noteTaken = $customer->update([
|
||||
'notes' => request()->input('notes')
|
||||
'notes' => request()->input('notes'),
|
||||
]);
|
||||
|
||||
if ($noteTaken) {
|
||||
|
|
@ -245,7 +248,7 @@ class CustomerController extends Controller
|
|||
$customer = $this->customerRepository->find($customerId);
|
||||
|
||||
$customer->update([
|
||||
'status' => $updateOption
|
||||
'status' => $updateOption,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +268,7 @@ class CustomerController extends Controller
|
|||
|
||||
foreach ($customerIds as $customerId) {
|
||||
$this->customerRepository->deleteWhere([
|
||||
'id' => $customerId
|
||||
'id' => $customerId,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@ class CustomerAddressImprovements extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::table('customer_addresses', function (Blueprint $table) {
|
||||
$table->string('company_name')->nullable()->after('company_id');
|
||||
$table->string('company_name')->nullable()->after('customer_id');
|
||||
$table->string('vat_id')->nullable()->after('company_name');
|
||||
});
|
||||
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->string('customer_vat_id')->nullable()->after('customer_last_name');
|
||||
$table->string('customer_company_name')->nullable()->after('customer_last_name');
|
||||
$table->string('customer_vat_id')->nullable()->after('customer_company_name');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ class CustomerAddressImprovements extends Migration
|
|||
});
|
||||
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->dropColumn('customer_company_name');
|
||||
$table->dropColumn('customer_vat_id');
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,8 +76,6 @@ class AddressController extends Controller
|
|||
$data = collect(request()->input())->except('_token')->toArray();
|
||||
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
|
|
@ -134,8 +132,6 @@ class AddressController extends Controller
|
|||
request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]);
|
||||
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use Webkul\Product\Repositories\ProductReviewRepository;
|
|||
* Customer controlller for the customer basically for the tasks of customers which will be
|
||||
* done after customer authentication.
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
|
|
@ -26,23 +26,24 @@ class CustomerController extends Controller
|
|||
* CustomerRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
* ProductReviewRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
*/
|
||||
protected $productReviewRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
|
||||
* @param \Webkul\Product\Repositories\ProductReviewRepository $productReview
|
||||
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
|
||||
* @param \Webkul\Product\Repositories\ProductReviewRepository $productReview
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
*/
|
||||
public function __construct(CustomerRepository $customerRepository, ProductReviewRepository $productReviewRepository)
|
||||
{
|
||||
$this->middleware('customer');
|
||||
|
|
@ -88,13 +89,13 @@ class CustomerController extends Controller
|
|||
$id = auth()->guard('customer')->user()->id;
|
||||
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'string',
|
||||
'last_name' => 'string',
|
||||
'gender' => 'required',
|
||||
'date_of_birth' => 'date|before:today',
|
||||
'email' => 'email|unique:customers,email,'.$id,
|
||||
'password' => 'confirmed|min:6|required_with:oldpassword',
|
||||
'oldpassword' => 'required_with:password',
|
||||
'first_name' => 'string',
|
||||
'last_name' => 'string',
|
||||
'gender' => 'required',
|
||||
'date_of_birth' => 'date|before:today',
|
||||
'email' => 'email|unique:customers,email,' . $id,
|
||||
'password' => 'confirmed|min:6|required_with:oldpassword',
|
||||
'oldpassword' => 'required_with:password',
|
||||
'password_confirmation' => 'required_with:password',
|
||||
]);
|
||||
|
||||
|
|
@ -104,7 +105,7 @@ class CustomerController extends Controller
|
|||
unset($data['date_of_birth']);
|
||||
|
||||
if ($data['oldpassword'] != "" || $data['oldpassword'] != null) {
|
||||
if(Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
|
||||
if (Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
} else {
|
||||
session()->flash('warning', trans('shop::app.customer.account.profile.unmatch'));
|
||||
|
|
@ -129,7 +130,8 @@ class CustomerController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
|
|
@ -160,7 +162,7 @@ class CustomerController extends Controller
|
|||
|
||||
return redirect()->back();
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Customer']));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
|
|
|
|||
|
|
@ -20,15 +20,6 @@ class CustomerServiceProvider extends ServiceProvider
|
|||
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register factories.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -13,16 +13,6 @@ use Webkul\Customer\Rules\VatValidator;
|
|||
*/
|
||||
class VatIdRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,13 +5,11 @@ use Webkul\Customer\Models\CustomerAddress;
|
|||
|
||||
class CustomerCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
}
|
||||
public $fields = [];
|
||||
|
||||
public function updateCustomerProfile(FunctionalTester $I)
|
||||
{
|
||||
$I->loginAsCustomer();
|
||||
$customer = $I->loginAsCustomer();
|
||||
|
||||
$I->amOnPage('/');
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ class CustomerCest
|
|||
|
||||
$I->click('Add Address');
|
||||
|
||||
$fields = [
|
||||
$this->fields = [
|
||||
'company_name' => $faker->company,
|
||||
'vat_id' => $faker->randomNumber(9),
|
||||
'address1[]' => $faker->streetAddress,
|
||||
|
|
@ -60,7 +58,7 @@ class CustomerCest
|
|||
'phone' => $faker->phoneNumber,
|
||||
];
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
foreach ($this->fields as $key => $value) {
|
||||
// the following fields are being rendered via javascript so we ignore them:
|
||||
if (! in_array($key, [
|
||||
'country',
|
||||
|
|
@ -76,37 +74,26 @@ class CustomerCest
|
|||
|
||||
// we need to use this css selector to hit the correct <form>. There is another one at the
|
||||
// page header (search)
|
||||
$I->submitForm($formCssSelector, $fields);
|
||||
$I->submitForm($formCssSelector, $this->fields);
|
||||
$I->seeInSource('The given vat id has a wrong format');
|
||||
|
||||
// valid vat id:
|
||||
$fields['vat_id'] = 'DE123456789';
|
||||
$this->fields['vat_id'] = 'DE123456789';
|
||||
|
||||
$I->submitForm($formCssSelector, $fields);
|
||||
$I->submitForm($formCssSelector, $this->fields);
|
||||
|
||||
$I->seeInSource('Address have been successfully added.');
|
||||
|
||||
$I->seeInSource('Address have been successfully added.');
|
||||
|
||||
$I->seeRecord(CustomerAddress::class, [
|
||||
'company_name' => $fields['company_name'],
|
||||
'vat_id' => $fields['vat_id'],
|
||||
'address1' => $fields['address1[]'],
|
||||
'country' => $fields['country'],
|
||||
'state' => $fields['state'],
|
||||
'city' => $fields['city'],
|
||||
'phone' => $fields['phone'],
|
||||
'postcode' => $fields['postcode'],
|
||||
]);
|
||||
$this->assertCustomerAddress($I);
|
||||
|
||||
$I->wantTo('Update the created customer address again');
|
||||
|
||||
$I->click('Edit');
|
||||
|
||||
$oldcompany = $fields['company_name'];
|
||||
$fields['company_name'] = $faker->company;
|
||||
$oldcompany = $this->fields['company_name'];
|
||||
$this->fields['company_name'] = $faker->company;
|
||||
|
||||
$I->submitForm($formCssSelector, $fields);
|
||||
$I->submitForm($formCssSelector, $this->fields);
|
||||
|
||||
$I->seeInSource('Address updated successfully.');
|
||||
|
||||
|
|
@ -114,9 +101,24 @@ class CustomerCest
|
|||
'company_name' => $oldcompany,
|
||||
]);
|
||||
|
||||
$this->assertCustomerAddress($I);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \FunctionalTester $I
|
||||
* @param array $fields
|
||||
*/
|
||||
private function assertCustomerAddress(FunctionalTester $I): void
|
||||
{
|
||||
$I->seeRecord(CustomerAddress::class, [
|
||||
'company_name' => $fields['company_name'],
|
||||
'postcode' => $fields['postcode'],
|
||||
'company_name' => $this->fields['company_name'],
|
||||
'vat_id' => $this->fields['vat_id'],
|
||||
'address1' => $this->fields['address1[]'],
|
||||
'country' => $this->fields['country'],
|
||||
'state' => $this->fields['state'],
|
||||
'city' => $this->fields['city'],
|
||||
'phone' => $this->fields['phone'],
|
||||
'postcode' => $this->fields['postcode'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue