Skip to content

Commit

Permalink
fix: vendor created by admin does not show in search result (#949)
Browse files Browse the repository at this point in the history
* fix: vendor created by admin shows in search result

fixed #936

* fix: phpcs error
  • Loading branch information
kapilpaul authored Nov 12, 2020
1 parent dedbaa1 commit db00d62
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions includes/Vendor/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public function all( $args = array() ) {
*
* @return array
*/
public function get_vendors( $args = array() ) {
$vendors = array();
public function get_vendors( $args = [] ) {
$vendors = [];

$defaults = array(
'role__in' => array( 'seller', 'administrator' ),
$defaults = [
'role__in' => [ 'seller', 'administrator' ],
'number' => 10,
'offset' => 0,
'orderby' => 'registered',
'order' => 'ASC',
'status' => 'approved',
'featured' => '', // yes or no
'meta_query' => array(),
);
'meta_query' => [],
];

$args = wp_parse_args( $args, $defaults );
$status = $args['status'];
Expand All @@ -62,23 +62,23 @@ public function get_vendors( $args = array() ) {
$status = $args['status'];
}

if ( in_array( $status, array( 'approved', 'pending' ) ) ) {
if ( in_array( $status, [ 'approved', 'pending' ] ) ) {
$operator = ( $status == 'approved' ) ? '=' : '!=';

$args['meta_query'][] = array(
$args['meta_query'][] = [
'key' => 'dokan_enable_selling',
'value' => 'yes',
'compare' => $operator
);
'compare' => $operator,
];
}

// if featured
if ( 'yes' == $args['featured'] ) {
$args['meta_query'][] = array(
$args['meta_query'][] = [
'key' => 'dokan_feature_seller',
'value' => 'yes',
'compare' => '='
);
'compare' => '=',
];
}

unset( $args['status'] );
Expand All @@ -101,7 +101,7 @@ public function get_vendors( $args = array() ) {
*
* @since 1.0.0
*
* @return void
* @return int
*/
public function get_total() {
return $this->total_users;
Expand Down Expand Up @@ -145,7 +145,7 @@ public function create( $data = [] ) {
}

// send vendor registration email to admin and vendor
if ( isset( $data['notify_vendor'] ) && dokan_validate_boolean( $data['notify_vendor' ] ) ) {
if ( isset( $data['notify_vendor'] ) && dokan_validate_boolean( $data['notify_vendor'] ) ) {
wp_send_new_user_notifications( $vendor_id, 'both' );
} else {
wp_send_new_user_notifications( $vendor_id, 'admin' );
Expand All @@ -154,7 +154,10 @@ public function create( $data = [] ) {
$store_data = apply_filters( 'dokan_vendor_create_data', [
'store_name' => ! empty( $data['store_name'] ) ? $data['store_name'] : '',
'social' => ! empty( $data['social'] ) ? $data['social'] : [],
'payment' => ! empty( $data['payment'] ) ? $data['payment'] : [ 'paypal' => [ 'email' ], 'bank' => [] ],
'payment' => ! empty( $data['payment'] ) ? $data['payment'] : [
'paypal' => [ 'email' ],
'bank' => [],
],
'phone' => ! empty( $data['phone'] ) ? $data['phone'] : '',
'show_email' => ! empty( $data['show_email'] ) ? $data['show_email'] : 'no',
'address' => ! empty( $data['address'] ) ? $data['address'] : [],
Expand All @@ -168,7 +171,7 @@ public function create( $data = [] ) {
'store_tnc' => ! empty( $data['store_tnc'] ) ? $data['store_tnc'] : '',
'show_min_order_discount' => ! empty( $data['show_min_order_discount'] ) ? $data['show_min_order_discount'] : 'no',
'store_seo' => ! empty( $data['store_seo'] ) ? $data['store_seo'] : [],
'dokan_store_time' => ! empty( $data['store_open_close'] ) ? $data['store_open_close'] : []
'dokan_store_time' => ! empty( $data['store_open_close'] ) ? $data['store_open_close'] : [],
] );

$vendor = dokan()->vendor->get( $vendor_id );
Expand Down Expand Up @@ -196,6 +199,7 @@ public function create( $data = [] ) {
}

$vendor->update_meta( 'dokan_profile_settings', $store_data );
$vendor->update_meta( 'dokan_store_name', $store_data['store_name'] );
$vendor->set_store_name( $store_data['store_name'] );
$vendor->save();

Expand Down Expand Up @@ -223,37 +227,37 @@ public function update( $vendor_id, $data = [] ) {
// default wp based user data
if ( ! empty( $data['user_pass'] ) ) {
wp_update_user(
array(
[
'ID' => $vendor->get_id(),
'user_pass' => $data['user_pass']
)
'user_pass' => $data['user_pass'],
]
);
}

if ( ! empty( $data['first_name'] ) ) {
wp_update_user(
array(
[
'ID' => $vendor->get_id(),
'first_name' => wc_clean( $data['first_name'] )
)
'first_name' => wc_clean( $data['first_name'] ),
]
);
}

if ( ! empty( $data['last_name'] ) ) {
wp_update_user(
array(
[
'ID' => $vendor->get_id(),
'last_name' => wc_clean( $data['last_name'] )
)
'last_name' => wc_clean( $data['last_name'] ),
]
);
}

if ( ! empty( $data['user_nicename'] ) ) {
wp_update_user(
array(
[
'ID' => $vendor->get_id(),
'user_nicename' => wc_clean( $data['user_nicename'] )
)
'user_nicename' => wc_clean( $data['user_nicename'] ),
]
);
}

Expand All @@ -263,10 +267,10 @@ public function update( $vendor_id, $data = [] ) {
}

wp_update_user(
array(
[
'ID' => $vendor->get_id(),
'user_email' => sanitize_email( $data['email'] ),
)
]
);
}

Expand Down Expand Up @@ -324,7 +328,7 @@ public function update( $vendor_id, $data = [] ) {

// for backward compatibility we'll allow both `enable_tnc` and `toc_enabled` to set store trams and condition settings
if ( ( isset( $data['enable_tnc'] ) && dokan_validate_boolean( $data['enable_tnc'] ) )
|| ( isset( $data['toc_enabled'] ) && dokan_validate_boolean( $data['toc_enabled'] ) ) ) {
|| ( isset( $data['toc_enabled'] ) && dokan_validate_boolean( $data['toc_enabled'] ) ) ) {
$vendor->set_enable_tnc( 'on' );
} else {
$vendor->set_enable_tnc( 'off' );
Expand Down Expand Up @@ -412,6 +416,9 @@ public function update( $vendor_id, $data = [] ) {
/**
* Delete vendor with reassign data
*
* @param $vendor_id
* @param null $reassign
*
* @since 2.9.11
*
* @return array
Expand All @@ -428,15 +435,17 @@ public function delete( $vendor_id, $reassign = null ) {
/**
* Get all featured Vendor
*
* @return object
* @param array $args
*
* @return array
*/
public function get_featured( $args = array() ) {
public function get_featured( $args = [] ) {

$defaults = array(
$defaults = [
'number' => 10,
'offset' => 0,
'featured' => 'yes',
);
];

$args = wp_parse_args( $args, $defaults );

Expand Down

0 comments on commit db00d62

Please sign in to comment.