Merge pull request #16401 from woocommerce/fix/16378

Use new CRUD actions to trigger Webhooks
This commit is contained in:
Mike Jolley 2017-08-11 10:35:23 +01:00 committed by GitHub
commit e124841cbf
6 changed files with 19 additions and 17 deletions

View File

@ -297,6 +297,7 @@ class WC_API_Coupons extends WC_API_Resource {
update_post_meta( $id, 'customer_email', array_filter( array_map( 'sanitize_email', $coupon_data['customer_emails'] ) ) );
do_action( 'woocommerce_api_create_coupon', $id, $data );
do_action( 'woocommerce_new_coupon', $id );
$this->server->send_status( 201 );
@ -432,6 +433,7 @@ class WC_API_Coupons extends WC_API_Resource {
}
do_action( 'woocommerce_api_edit_coupon', $id, $data );
do_action( 'woocommerce_update_coupon', $id );
return $this->get_coupon( $id );
} catch ( WC_API_Exception $e ) {

View File

@ -464,6 +464,7 @@ class WC_API_Orders extends WC_API_Resource {
wc_delete_shop_order_transients( $order );
do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
do_action( 'woocommerce_new_order', $order->get_id() );
wc_transaction_query( 'commit' );
@ -632,6 +633,7 @@ class WC_API_Orders extends WC_API_Resource {
wc_delete_shop_order_transients( $order );
do_action( 'woocommerce_api_edit_order', $order->get_id(), $data, $this );
do_action( 'woocommerce_update_order', $order->get_id() );
return $this->get_order( $id );

View File

@ -295,6 +295,7 @@ class WC_API_Coupons extends WC_API_Resource {
update_post_meta( $id, 'customer_email', array_filter( array_map( 'sanitize_email', $coupon_data['customer_emails'] ) ) );
do_action( 'woocommerce_api_create_coupon', $id, $data );
do_action( 'woocommerce_new_coupon', $id );
$this->server->send_status( 201 );
@ -430,6 +431,7 @@ class WC_API_Coupons extends WC_API_Resource {
}
do_action( 'woocommerce_api_edit_coupon', $id, $data );
do_action( 'woocommerce_update_coupon', $id );
return $this->get_coupon( $id );
} catch ( WC_API_Exception $e ) {

View File

@ -506,6 +506,7 @@ class WC_API_Orders extends WC_API_Resource {
wc_delete_shop_order_transients( $order );
do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
do_action( 'woocommerce_new_order', $order->get_id() );
wc_transaction_query( 'commit' );
@ -671,6 +672,7 @@ class WC_API_Orders extends WC_API_Resource {
wc_delete_shop_order_transients( $order );
do_action( 'woocommerce_api_edit_order', $order->get_id(), $data, $this );
do_action( 'woocommerce_update_order', $order->get_id() );
return $this->get_order( $id );
} catch ( WC_Data_Exception $e ) {

View File

@ -338,15 +338,13 @@ class WC_REST_Customers_V1_Controller extends WC_REST_Controller {
$customer->set_username( $request['username'] );
$customer->set_password( $request['password'] );
$customer->set_email( $request['email'] );
$this->update_customer_meta_fields( $customer, $request );
$customer->save();
if ( ! $customer->get_id() ) {
throw new WC_REST_Exception( 'woocommerce_rest_cannot_create', __( 'This resource cannot be created.', 'woocommerce' ), 400 );
}
$this->update_customer_meta_fields( $customer, $request );
$customer->save();
$user_data = get_userdata( $customer->get_id() );
$this->update_additional_fields_for_object( $user_data, $request );

View File

@ -610,11 +610,11 @@ class WC_Webhook {
$topic_hooks = array(
'coupon.created' => array(
'woocommerce_process_shop_coupon_meta',
'woocommerce_api_create_coupon',
'woocommerce_new_coupon',
),
'coupon.updated' => array(
'woocommerce_process_shop_coupon_meta',
'woocommerce_api_edit_coupon',
'woocommerce_update_coupon',
),
'coupon.deleted' => array(
'wp_trash_post',
@ -625,26 +625,22 @@ class WC_Webhook {
'customer.created' => array(
'user_register',
'woocommerce_created_customer',
'woocommerce_api_create_customer',
'woocommerce_new_customer',
),
'customer.updated' => array(
'profile_update',
'woocommerce_api_edit_customer',
'woocommerce_customer_save_address',
'woocommerce_update_customer',
),
'customer.deleted' => array(
'delete_user',
),
'order.created' => array(
'woocommerce_checkout_order_processed',
'woocommerce_process_shop_order_meta',
'woocommerce_api_create_order',
'woocommerce_new_order',
),
'order.updated' => array(
'woocommerce_process_shop_order_meta',
'woocommerce_api_edit_order',
'woocommerce_order_edit_status',
'woocommerce_order_status_changed',
'woocommerce_update_order',
),
'order.deleted' => array(
'wp_trash_post',
@ -654,13 +650,13 @@ class WC_Webhook {
),
'product.created' => array(
'woocommerce_process_product_meta',
'woocommerce_api_create_product',
'woocommerce_new_product',
'woocommerce_new_product_variation',
),
'product.updated' => array(
'woocommerce_process_product_meta',
'woocommerce_api_edit_product',
'woocommerce_product_quick_edit_save',
'woocommerce_product_bulk_edit_save',
'woocommerce_update_product',
'woocommerce_update_product_variation',
),
'product.deleted' => array(
'wp_trash_post',