Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -706,7 +706,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
*
|
||||
* @param WC_Abstract_Order $order Order object.
|
||||
*/
|
||||
private function update_order_meta_from_object( $order ) {
|
||||
protected function update_order_meta_from_object( $order ) {
|
||||
if ( is_null( $order->get_meta() ) ) {
|
||||
return;
|
||||
}
|
||||
@@ -715,13 +715,24 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
|
||||
foreach ( $order->get_meta_data() as $meta_data ) {
|
||||
if ( isset( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
if ( $existing_meta_data[ $meta_data->key ] === $meta_data->value ) {
|
||||
// We don't know if the meta is single or array, so we assume it to be an array.
|
||||
$meta_value = is_array( $meta_data->value ) ? $meta_data->value : array( $meta_data->value );
|
||||
|
||||
if ( $existing_meta_data[ $meta_data->key ] === $meta_value ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
delete_post_meta( $order->get_id(), $meta_data->key );
|
||||
if ( is_array( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
$value_index = array_search( maybe_serialize( $meta_data->value ), $existing_meta_data[ $meta_data->key ], true );
|
||||
if ( false !== $value_index ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ][ $value_index ] );
|
||||
if ( 0 === count( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
add_post_meta( $order->get_id(), $meta_data->key, $meta_data->value, false );
|
||||
}
|
||||
@@ -735,7 +746,11 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
);
|
||||
|
||||
foreach ( $keys_to_delete as $meta_key ) {
|
||||
delete_post_meta( $order->get_id(), $meta_key );
|
||||
if ( isset( $existing_meta_data[ $meta_key ] ) ) {
|
||||
foreach ( $existing_meta_data[ $meta_key ] as $meta_value ) {
|
||||
delete_post_meta( $order->get_id(), $meta_key, maybe_unserialize( $meta_value ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->update_post_meta( $order );
|
||||
|
||||
@@ -203,7 +203,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
$changes = $product->get_changes();
|
||||
|
||||
// Only update the post when the post data changes.
|
||||
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order', 'date_created', 'date_modified', 'slug' ), array_keys( $changes ) ) ) {
|
||||
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order', 'date_created', 'date_modified', 'slug', 'post_password' ), array_keys( $changes ) ) ) {
|
||||
$post_data = array(
|
||||
'post_content' => $product->get_description( 'edit' ),
|
||||
'post_excerpt' => $product->get_short_description( 'edit' ),
|
||||
@@ -1180,9 +1180,10 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
* @todo Add to interface in 4.0.
|
||||
* @param WC_Product $product Variable product.
|
||||
* @param int $limit Limit the number of created variations.
|
||||
* @param array $default_values Key value pairs to set on created variations.
|
||||
* @return int Number of created variations.
|
||||
*/
|
||||
public function create_all_product_variations( $product, $limit = -1 ) {
|
||||
public function create_all_product_variations( $product, $limit = -1, $default_values = array() ) {
|
||||
$count = 0;
|
||||
|
||||
if ( ! $product ) {
|
||||
@@ -1211,6 +1212,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
continue;
|
||||
}
|
||||
$variation = wc_get_product_object( 'variation' );
|
||||
$variation->set_props( $default_values );
|
||||
$variation->set_parent_id( $product->get_id() );
|
||||
$variation->set_attributes( $possible_attribute );
|
||||
$variation_id = $variation->save();
|
||||
@@ -1864,6 +1866,12 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
'field' => 'slug',
|
||||
'terms' => $query_vars['category'],
|
||||
);
|
||||
} elseif ( ! empty( $query_vars['product_category_id'] ) ) {
|
||||
$wp_query_args['tax_query'][] = array(
|
||||
'taxonomy' => 'product_cat',
|
||||
'field' => 'term_id',
|
||||
'terms' => $query_vars['product_category_id'],
|
||||
);
|
||||
}
|
||||
|
||||
// Handle product tags.
|
||||
@@ -1874,6 +1882,12 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
'field' => 'slug',
|
||||
'terms' => $query_vars['tag'],
|
||||
);
|
||||
} elseif ( ! empty( $query_vars['product_tag_id'] ) ) {
|
||||
$wp_query_args['tax_query'][] = array(
|
||||
'taxonomy' => 'product_tag',
|
||||
'field' => 'term_id',
|
||||
'terms' => $query_vars['product_tag_id'],
|
||||
);
|
||||
}
|
||||
|
||||
// Handle shipping classes.
|
||||
@@ -2085,7 +2099,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
'onsale' => $sale_price && $price === $sale_price ? 1 : 0,
|
||||
'stock_quantity' => $stock,
|
||||
'stock_status' => get_post_meta( $id, '_stock_status', true ),
|
||||
'rating_count' => array_sum( (array) get_post_meta( $id, '_wc_rating_count', true ) ),
|
||||
'rating_count' => array_sum( array_map( 'intval', (array) get_post_meta( $id, '_wc_rating_count', true ) ) ),
|
||||
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
|
||||
'total_sales' => get_post_meta( $id, 'total_sales', true ),
|
||||
'tax_status' => get_post_meta( $id, '_tax_status', true ),
|
||||
@@ -2120,7 +2134,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
global $wpdb;
|
||||
return $wpdb->prepare(
|
||||
"
|
||||
SELECT COALESCE ( MAX( meta_value ), 0 ) FROM $wpdb->postmeta as meta_table
|
||||
SELECT COALESCE( MAX( meta_value ), 0 ) FROM $wpdb->postmeta as meta_table
|
||||
WHERE meta_table.meta_key = '_stock'
|
||||
AND meta_table.post_id = %d
|
||||
",
|
||||
|
||||
@@ -283,6 +283,7 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
|
||||
$date_created = '';
|
||||
$date_modified = '';
|
||||
$user_id = '';
|
||||
$api_version = '';
|
||||
|
||||
if ( ! empty( $args['include'] ) ) {
|
||||
$args['include'] = implode( ',', wp_parse_id_list( $args['include'] ) );
|
||||
@@ -312,6 +313,11 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
|
||||
$date_modified = "AND `date_modified_gmt` BETWEEN STR_TO_DATE('" . esc_sql( $args['modified_after'] ) . "', '%Y-%m-%d %H:%i:%s') and STR_TO_DATE('" . esc_sql( $args['modified_before'] ) . "', '%Y-%m-%d %H:%i:%s')";
|
||||
}
|
||||
|
||||
$api_version_value = $args['api_version'] ?? null;
|
||||
if ( is_numeric( $api_version_value ) ) {
|
||||
$api_version = 'AND `api_version`=' . esc_sql( $api_version_value );
|
||||
}
|
||||
|
||||
// Check for cache.
|
||||
$cache_key = WC_Cache_Helper::get_cache_prefix( 'webhooks' ) . 'search_webhooks' . md5( implode( ',', $args ) );
|
||||
$cache_value = wp_cache_get( $cache_key, 'webhook_search_results' );
|
||||
@@ -331,6 +337,7 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
|
||||
{$exclude}
|
||||
{$date_created}
|
||||
{$date_modified}
|
||||
{$api_version}
|
||||
{$user_id}
|
||||
{$order}
|
||||
{$limit}
|
||||
|
||||
Reference in New Issue
Block a user