* Fixed related orders problem

This commit fixes the related orders problem

* Fixed customer type query

* Fixed get_order_number filtering

* Added a default value to totalResults

This commit adds a default value to totalResults (in order to avoid errors)

* Added testing instructions

# Conflicts:
#	TESTING-INSTRUCTIONS.md

* Added changelog

# Conflicts:
#	readme.txt

* Fixed orders without products

* Added tests

Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
Fernando 2021-03-09 15:57:50 -03:00 committed by GitHub
parent 5b368f4227
commit 0ebccd674b
6 changed files with 94 additions and 4 deletions

View File

@ -212,6 +212,13 @@ wp db query 'SELECT status FROM wp_wc_admin_notes WHERE name = "wc-admin-add-fir
7. Create a user with permissions to see some but not all registered WooCommerce pages.
8. Check that a user without permission to access a menu item cannot see said menu item.
### Fixed associated Order Number for refunds #6428
1. In a store with refunded orders.
2. Go to `Analytics` > `Orders`
3. Set the `Date Range` filter in order to cover the refunded order date.
4. Verify that now the associated order number and the related products are visible.
### Remove CES actions for adding and editing a product and editing an order #6355
1. Add a product. The customer effort score survey should not appear.

View File

@ -323,7 +323,7 @@ const ReportTable = ( props ) => {
const isLoading =
isRequesting || tableData.isRequesting || primaryData.isRequesting;
const totals = get( primaryData, [ 'data', 'totals' ], {} );
const totalResults = items.totalResults;
const totalResults = items.totalResults || 0;
const downloadable = totalResults > 0;
// Search words are in the query string, not the table query.
const searchWords = getSearchWords( query );

View File

@ -100,6 +100,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Fix: Restore visual styles back to Analytics tabs. #5913
- Add: Add a "rather not say" option to revenue in the profile wizard. #6475
- Dev: Added warning when WC-Admin is active but not being used #6453
- Fix: Associated Order Number for refunds was hidden #6428
- Add: Remove Mollie promo note on install #6510
- Add: Remote Inbox Notifications rule to trigger when WooCommerce Admin is upgraded. #6040
- Feature: Increase target audience for business feature step. #6508

View File

@ -190,7 +190,7 @@ class Controller extends \WC_REST_Reports_Controller {
public function get_order_number( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order instanceof \WC_Order ) {
if ( ! $order instanceof \WC_Order && ! $order instanceof \WC_Order_Refund ) {
return null;
}

View File

@ -72,7 +72,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
'net_total' => "{$table_name}.net_total",
'total_sales' => "{$table_name}.total_sales",
'num_items_sold' => "{$table_name}.num_items_sold",
'customer_type' => "(CASE WHEN {$table_name}.returning_customer = 1 THEN 'returning' WHEN {$table_name}.returning_customer = 0 THEN 'new' ELSE '' END) as customer_type",
'customer_type' => "(CASE WHEN {$table_name}.returning_customer = 0 THEN 'new' ELSE 'returning' END) as customer_type",
);
}
@ -325,7 +325,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
*/
protected function include_extended_info( &$orders_data, $query_args ) {
$mapped_orders = $this->map_array_by_key( $orders_data, 'order_id' );
$products = $this->get_products_by_order_ids( array_keys( $mapped_orders ) );
$related_orders = $this->get_orders_with_parent_id( $mapped_orders );
$order_ids = array_merge( array_keys( $mapped_orders ), array_keys( $related_orders ) );
$products = $this->get_products_by_order_ids( $order_ids );
$coupons = $this->get_coupons_by_order_ids( array_keys( $mapped_orders ) );
$customers = $this->get_customers_by_orders( $orders_data );
$mapped_customers = $this->map_array_by_key( $customers, 'customer_id' );
@ -354,6 +356,11 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
}
$mapped_data[ $product['order_id'] ]['products'][] = $product_data;
// If this product's order has another related order, it will be added to our mapped_data.
if ( isset( $related_orders [ $product['order_id'] ] ) ) {
$mapped_data[ $related_orders[ $product['order_id'] ]['order_id'] ] ['products'] [] = $product_data;
}
}
foreach ( $coupons as $coupon ) {
@ -380,6 +387,22 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
}
}
/**
* Returns oreders that have a parent id
*
* @param array $orders Orders array.
* @return array
*/
protected function get_orders_with_parent_id( $orders ) {
$related_orders = array();
foreach ( $orders as $order ) {
if ( '0' !== $order['parent_id'] ) {
$related_orders[ $order['parent_id'] ] = $order;
}
}
return $related_orders;
}
/**
* Returns the same array index by a given key
*

View File

@ -115,4 +115,63 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
);
$this->assertEquals( $expected, $data );
}
/**
* Test that refunded orders in list have products.
*/
public function test_products_in_orders() {
global $wpdb;
WC_Helper_Reports::reset_stats_dbs();
$simple_product = new WC_Product_Simple();
$simple_product->set_name( 'Simple Product 2' );
$simple_product->set_regular_price( 25 );
$simple_product->save();
$order = WC_Helper_Order::create_order( 1, $simple_product );
$order->set_total( 25 );
$order->set_status( 'completed' );
$order->save();
wc_create_refund(
array(
'amount' => 25,
'order_id' => $order->get_id(),
)
);
WC_Helper_Queue::run_all_pending();
$data_store = new OrdersDataStore();
$start_time = gmdate( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = gmdate( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );
$args = array(
'after' => $start_time,
'before' => $end_time,
'extended_info' => 1,
);
// Retrieving orders with products through the data store.
$data = $data_store->get_data( $args );
$expected = array(
array(
'id' => $simple_product->get_id(),
'name' => $simple_product->get_name(),
'quantity' => '4',
),
);
$this->assertEquals( $expected, $data->data[0]['extended_info']['products'] );
$args = array(
'after' => $start_time,
'before' => $end_time,
'extended_info' => 1,
'status_is' => array(
'refunded',
),
);
// Retrieving an order with products (when receiving a single refunded order).
$data_2 = $data_store->get_data( $args );
$this->assertEquals( $expected, $data_2->data[0]['extended_info']['products'] );
}
}