-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Add simple products to the Analytics orders query for the attributes filter #44901
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b1eb91
Add subquery for simple products
louwie17 34fdaf8
Update query to make use of product lookup instead
louwie17 8a6863a
Add changelog
louwie17 d966b74
Revert change
louwie17 80e423d
Update PHP tests and fix lint errors
louwie17 96f2b45
Move subquery out to its own variable to make it more readable
louwie17 6147225
Fix lint errors
octaedro File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
plugins/woocommerce/changelog/fix-32237_orders_simple_products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Include simple product support in the attributes filter within the analytics orders view. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,26 @@ public function test_product_attributes_filter() { | |
$order_variation_1 = wc_get_product( $product_variations[1] ); // Variation: size = large. | ||
$order_variation_2 = wc_get_product( $product_variations[3] ); // Variation: size = huge, colour = red, number = 2. | ||
|
||
// Create a simple product. | ||
$size_attr_id = wc_attribute_taxonomy_id_by_name( 'pa_size' ); | ||
$large_term = get_term_by( 'slug', 'large', 'pa_size' ); | ||
|
||
$global_attribute = new WC_Product_Attribute(); | ||
$global_attribute->set_id( $size_attr_id ); | ||
$global_attribute->set_name( 'pa_size' ); | ||
$global_attribute->set_options( array( $large_term->term_id ) ); // Set to small. | ||
$global_attribute->set_position( 1 ); | ||
$global_attribute->set_visible( true ); | ||
$global_attribute->set_variation( false ); | ||
$attributes['global-size'] = $global_attribute; | ||
|
||
$simple_product = WC_Helper_Product::create_simple_product( | ||
true, | ||
array( | ||
'attributes' => $attributes, | ||
) | ||
); | ||
|
||
// Create orders for variations. | ||
$variation_order_1 = WC_Helper_Order::create_order( $this->user, $order_variation_1 ); | ||
$variation_order_1->set_status( 'completed' ); | ||
|
@@ -156,6 +176,10 @@ public function test_product_attributes_filter() { | |
$variation_order_2->set_status( 'completed' ); | ||
$variation_order_2->save(); | ||
|
||
$simple_product_order_1 = WC_Helper_Order::create_order( $this->user, $simple_product ); | ||
$simple_product_order_1->set_status( 'completed' ); | ||
$simple_product_order_1->save(); | ||
|
||
// Create more orders for simple products. | ||
for ( $i = 0; $i < 10; $i++ ) { | ||
$order = WC_Helper_Order::create_order( $this->user ); | ||
|
@@ -172,25 +196,23 @@ public function test_product_attributes_filter() { | |
|
||
// Sanity check before filtering by attribute. | ||
$this->assertEquals( 200, $response->get_status() ); | ||
$this->assertEquals( 12, $response_orders['totals']['orders_count'] ); | ||
$this->assertEquals( 13, $response_orders['totals']['orders_count'] ); | ||
|
||
// Filter by the "size" attribute, with value "large". | ||
$size_attr_id = wc_attribute_taxonomy_id_by_name( 'pa_size' ); | ||
$small_term = get_term_by( 'slug', 'large', 'pa_size' ); | ||
$request = new WP_REST_Request( 'GET', $this->endpoint ); | ||
$request = new WP_REST_Request( 'GET', $this->endpoint ); | ||
$request->set_query_params( | ||
array( | ||
'attribute_is' => array( | ||
array( $size_attr_id, $small_term->term_id ), | ||
array( $size_attr_id, $large_term->term_id ), | ||
), | ||
) | ||
); | ||
$response = $this->server->dispatch( $request ); | ||
$response_orders = $response->get_data(); | ||
|
||
$this->assertEquals( 200, $response->get_status() ); | ||
$this->assertEquals( 1, $response_orders['totals']['orders_count'] ); | ||
$this->assertEquals( $variation_order_1->get_total(), $response_orders['totals']['total_sales'] ); | ||
$this->assertEquals( 2, $response_orders['totals']['orders_count'] ); | ||
$this->assertEquals( $variation_order_1->get_total() + $simple_product_order_1->get_total(), $response_orders['totals']['total_sales'] ); | ||
|
||
// Filter by excluding the "size" attribute, with value "large". | ||
$size_attr_id = wc_attribute_taxonomy_id_by_name( 'pa_size' ); | ||
|
@@ -207,8 +229,8 @@ public function test_product_attributes_filter() { | |
$response_orders = $response->get_data(); | ||
|
||
$this->assertEquals( 200, $response->get_status() ); | ||
$this->assertEquals( 1, $response_orders['totals']['orders_count'] ); | ||
$this->assertEquals( 11, $response_orders['totals']['orders_count'] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is |
||
// This should be the second variation order. | ||
$this->assertEquals( $variation_order_2->get_total(), $response_orders['totals']['total_sales'] ); | ||
$this->assertEquals( 11 * $variation_order_2->get_total(), $response_orders['totals']['total_sales'] ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$term_id
wasn't previously being used, but now it is, this makes sure it is set in both instances.