auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -1121,8 +1121,9 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
$response = array();
$product = wc_get_product( $product_id );
$default_values = isset( $request['default_values'] ) ? $request['default_values'] : array();
$meta_data = isset( $request['meta_data'] ) ? $request['meta_data'] : array();
$data_store = $product->get_data_store();
$response['count'] = $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ), $default_values );
$response['count'] = $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ), $default_values, $meta_data );
if ( isset( $request['delete'] ) && $request['delete'] ) {
$deleted_count = $this->delete_unmatched_product_variations( $product );

View File

@@ -62,6 +62,54 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
'schema' => array( $this, 'get_public_item_schema' ),
)
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\d]+)/duplicate',
array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'duplicate_product' ),
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}
/**
* Duplicate a product and returns the duplicated product.
* The product status is set to "draft" and the name includes a "(copy)" at the end by default.
*
* @param WP_REST_Request $request Request data.
* @return WP_REST_Response|WP_Error
*/
public function duplicate_product( $request ) {
$product_id = $request->get_param( 'id' );
$product = wc_get_product( $product_id );
if ( ! $product ) {
return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
}
// Creating product object from request data in preparation for copying.
$updated_product = $this->prepare_object_for_database( $request );
$duplicated_product = ( new WC_Admin_Duplicate_Product() )->product_duplicate( $updated_product );
if ( is_wp_error( $duplicated_product ) ) {
return new WP_Error( 'woocommerce_rest_product_duplicate_error', $duplicated_product->get_error_message(), array( 'status' => 400 ) );
}
$response_data = $duplicated_product->get_data();
return new WP_REST_Response( $response_data, 200 );
}
/**
@@ -325,7 +373,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
global $wpdb;
if ( ! empty( $this->search_sku_in_product_lookup_table ) ) {
$like_search = '%' . $wpdb->esc_like( $this->search_sku_in_product_lookup_table ) . '%';
$where .= ' AND ' . $wpdb->prepare( '(wc_product_meta_lookup.sku LIKE %s)', $like_search );
$where .= ' AND ' . $wpdb->prepare( '(wc_product_meta_lookup.sku LIKE %s)', $like_search );
}
return $where;
}
@@ -1112,7 +1160,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'low_stock_amount' => array(
'low_stock_amount' => array(
'description' => __( 'Low Stock amount for the product.', 'woocommerce' ),
'type' => array( 'integer', 'null' ),
'context' => array( 'view', 'edit' ),
@@ -1344,7 +1392,7 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
),
),
),
'has_options' => array(
'has_options' => array(
'description' => __( 'Shows if the product needs to be configured before it can be bought.', 'woocommerce' ),
'type' => 'boolean',
'context' => array( 'view', 'edit' ),

View File

@@ -8,6 +8,8 @@
* @since 3.5.0
*/
use Automattic\WooCommerce\Utilities\OrderUtil;
defined( 'ABSPATH' ) || exit;
/**
@@ -39,18 +41,18 @@ class WC_REST_Report_Orders_Totals_Controller extends WC_REST_Reports_Controller
* @return array
*/
protected function get_reports() {
$totals = wp_count_posts( 'shop_order' );
$totals = OrderUtil::get_count_for_type( 'shop_order' );
$data = array();
foreach ( wc_get_order_statuses() as $slug => $name ) {
if ( ! isset( $totals->$slug ) ) {
if ( ! array_key_exists( $slug, $totals ) ) {
continue;
}
$data[] = array(
'slug' => str_replace( 'wc-', '', $slug ),
'name' => $name,
'total' => (int) $totals->$slug,
'total' => (int) $totals[ $slug ],
);
}