Skip to content

Commit

Permalink
fix: set email on new vendor creation (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored Mar 2, 2020
1 parent 804836e commit dc8e366
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
14 changes: 7 additions & 7 deletions includes/REST/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,30 +679,30 @@ public function check_store_availability( $request ) {
}

// check whether email is available or not
if ( ! empty( $params['user_email'] ) ) {
$user_email = $params['user_email'];
if ( ! empty( $params['email'] ) ) {
$user_email = $params['email'];

if ( ! is_email( $user_email ) ) {
$response = [
'user_email' => $user_email,
'available' => false,
'message' => __( 'This email address is not valid', 'dokan-lite' )
'email' => $user_email,
'available' => false,
'message' => __( 'This email address is not valid', 'dokan-lite' )
];

return rest_ensure_response( $response );
}

if ( email_exists( $user_email ) ) {
$response = [
'user_email' => $user_email,
'email' => $user_email,
'available' => false
];

return rest_ensure_response( $response );
}

$response = [
'user_email' => $user_email,
'email' => $user_email,
'available' => true
];

Expand Down
12 changes: 8 additions & 4 deletions includes/Vendor/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public function create( $data = [] ) {
'user_pass' => wp_generate_password(),
];

if ( ! empty( $data['email'] ) ) {
$data['user_email'] = $data['email'];
unset( $data['email'] );
}

$vendor_data = wp_parse_args( $data, $defaults );
$vendor_id = wp_insert_user( $vendor_data );

Expand Down Expand Up @@ -252,16 +257,15 @@ public function update( $vendor_id, $data = [] ) {
);
}

if ( ! empty( $data['user_email'] ) ) {

if ( ! is_email( $data['user_email'] ) ) {
if ( ! empty( $data['email'] ) ) {
if ( ! is_email( $data['email'] ) ) {
return new WP_Error( 'invalid_email', __( 'Email is not valid', 'dokan-lite' ) );
}

wp_update_user(
array(
'ID' => $vendor->get_id(),
'user_email' => sanitize_email( $data['user_email'] ),
'user_email' => sanitize_email( $data['email'] ),
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/admin/pages/AddVendor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default {
user_pass: '',
store_url: '',
user_login: '',
user_email: '',
email: '',
user_nicename: '',
notify_vendor: true,
phone: '',
Expand Down Expand Up @@ -129,7 +129,7 @@ export default {
requiredFields: [
'store_name',
'user_login',
'user_email'
'email'
],
errors: [],
storeAvailable: false,
Expand Down
6 changes: 3 additions & 3 deletions src/admin/pages/VendorAccountFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@

<input type="email"
v-model="vendorInfo.email"
:class="{'dokan-form-input': true, 'has-error': getError('user_email')}"
:placeholder="getError( 'user_email' ) ? __( 'Email is required', 'dokan-lite' ) : __( '[email protected]', 'dokan-lite' )"
:class="{'dokan-form-input': true, 'has-error': getError('email')}"
:placeholder="getError( 'email' ) ? __( 'Email is required', 'dokan-lite' ) : __( '[email protected]', 'dokan-lite' )"
>

<div class="store-avaibility-info">
Expand Down Expand Up @@ -331,7 +331,7 @@ export default {
this.emailAvailabilityText = this.__( 'Searching...', 'dokan-lite' );
dokan.api.get( `/stores/check`, {
user_email: userEmail
email: userEmail
} ).then( ( response ) => {
if ( response.available ) {
this.emailAvailable = true;
Expand Down

0 comments on commit dc8e366

Please sign in to comment.