Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vendor dashboard product edit page variation products #2336

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions includes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,22 +651,15 @@ public function json_search_product() {
wp_die();
}

$ids = dokan_search_seller_products( $term, $user_ids, '', true );

if ( ! empty( $_GET['exclude'] ) ) {
$ids = array_diff( $ids, (array) sanitize_text_field( wp_unslash( $_GET['exclude'] ) ) );
}

if ( ! empty( $_GET['include'] ) ) {
$ids = array_intersect( $ids, (array) sanitize_text_field( wp_unslash( $_GET['include'] ) ) );
}

if ( ! empty( $_GET['limit'] ) ) {
$ids = array_slice( $ids, 0, absint( $_GET['limit'] ) );
}
$product_objects = dokan()->product->get_linked_products(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the get_linked_products method exist?

$term,
$user_ids,
$_GET['exclude'] ?? '', // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$_GET['include'] ?? '', // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$_GET['limit'] ?? 0 // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
);

$product_objects = array_filter( array_map( 'wc_get_product', $ids ), 'dokan_products_array_filter_editable' );
$products = [];
$products = [];

foreach ( $product_objects as $product_object ) {
$products[ $product_object->get_id() ] = rawurldecode( $product_object->get_formatted_name() );
Expand Down
38 changes: 38 additions & 0 deletions includes/Product/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,42 @@ public function top_rated( $args = [] ) {

return $products;
}

/**
* Returns linked products.
*
* @since DOKAN_SINCE
*
* @param string $term
* @param boolean|integer|array $user_ids
* @param integer $exclude
* @param integer $included_id
Aunshon marked this conversation as resolved.
Show resolved Hide resolved
* @param integer $limit
*
* @return WC_Product[]
*/
public function get_linked_products( $term = '', $user_ids = false, $exclude = null, $included_id = null, $limit = 0 ) {
$term = ! empty( $term ) ? sanitize_text_field( wp_unslash( $term ) ) : '';
$user_ids = ! empty( $user_ids ) ? array_filter( array_map( 'absint', (array) wp_unslash( $user_ids ) ) ) : false;

if ( empty( $term ) ) {
wp_die();
Aunshon marked this conversation as resolved.
Show resolved Hide resolved
}

$ids = dokan_search_seller_products( $term, $user_ids, '', true );

if ( ! empty( $exclude ) ) {
$ids = array_diff( $ids, (array) sanitize_text_field( wp_unslash( $exclude ) ) );
}

if ( ! empty( $included_id ) ) {
$ids = array_intersect( $ids, (array) sanitize_text_field( wp_unslash( $included_id ) ) );
}

if ( ! empty( $limit ) ) {
$ids = array_slice( $ids, 0, absint( $limit ) );
}

return array_filter( array_map( 'wc_get_product', $ids ), 'dokan_products_array_filter_editable' );
}

This comment was marked as off-topic.

}
2 changes: 1 addition & 1 deletion includes/Product/ProductAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function get( $post_id ) {
*/
public function set( &$product, $needs_save = false ) {
// Stop if no attributes found.
if ( ! count( $this->request_attributes ) ) {
if ( ! is_array( $this->request_attributes ) ) {
return $product;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/REST/ProductAttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function update_product_attribute( $request ) {
return new WP_Error( 'product_bulk_attribute_terms_saved_failed', __( 'Failed to save product bulk attribute and terms. Please try again later.', 'dokan-lite' ), [ 'status' => 400 ] );
}

return rest_ensure_response( $is_saved );
return rest_ensure_response( $product_attribute->get( $product_id ) );
}

/**
Expand Down
Loading