Skip to content

Conversation

@alishanvr
Copy link
Contributor

[Enhancement]: Allow searching by users/customers phone #36810

Submission Review Guidelines:

Closes #36810 .

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Apr 19, 2023
@woocommercebot woocommercebot requested review from a team and vedanshujain and removed request for a team April 19, 2023 14:45
Copy link
Contributor

@mdperez86 mdperez86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this @alishanvr!. I left one comment for your.

After testing this PR I had some problems with the resulting orders since there is no relation between the wp_wc_order_stats and the wp_usermeta tables.

cc: @louwie17

@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #37844 (5ccec5f) into trunk (c5285ec) will decrease coverage by 0.2%.
The diff coverage is 100.0%.

❗ Current head 5ccec5f differs from pull request most recent head b558ef1. Consider uploading reports for the commit b558ef1 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             trunk   #37844     +/-   ##
==========================================
- Coverage     51.5%    51.3%   -0.2%     
- Complexity   17283    17409    +126     
==========================================
  Files          430      440     +10     
  Lines        80037    80587    +550     
==========================================
+ Hits         41216    41304     +88     
- Misses       38821    39283    +462     
Impacted Files Coverage Δ
...udes/data-stores/class-wc-order-data-store-cpt.php 92.0% <100.0%> (+0.2%) ⬆️
...ion2/class-wc-rest-order-refunds-v2-controller.php 89.7% <100.0%> (ø)

... and 26 files with indirect coverage changes

@alishanvr
Copy link
Contributor Author

@mdperez86
Copy link
Contributor

Hey @alishanvr to keep things going please pay attention only to the 2 required checks. I'll let you know about the non required one once I have an answer from the expert team.

@alishanvr
Copy link
Contributor Author

Ok, @mdperez86!

I am a little busy today. But, I will fix those two by later tomorrow.

Kind Regards,

@alishanvr
Copy link
Contributor Author

Hi @mdperez86!

I fixed the PHPCS and also touched the changelog.

It's my first time to contributing to WooCommerce. So, please let me know if I did something wrong.

Thank You,

@mdperez86
Copy link
Contributor

Hi @alishanvr thank for your contribution here.
I just wanted to let you know that there are still some PHPCS problems

FILE: plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php
-----------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------
 611 | WARNING | Incorrect number of replacements passed to $wpdb->prepare(). Found 2 replacement parameters, expected 1. (WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber)
 613 | ERROR | Unsupported placeholder used in $wpdb->prepare(). Found: "%i". (WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder)

Also the changelog file you added here should be moved under plugins/woocommerce/changelog folder, that is because the file you touched with your changes plugins/woocommerce/includes/data-stores/class-wc-order-data-store-cpt.php is under the plugins/woocommerce directory.

You can move the changelog file manually or by running the following command pnpm --filter=woocommerce run changelog add. Remember not to keep a copy of that file at the root level of the project which is currently located.

Your help is always appreciated!

@alishanvr
Copy link
Contributor Author

Hi @mdperez86,

Thank you for updating.

I am not sure why there is an error in PHPCS, while the %i is also available in WordPress 6.2.
I request you to please check the following link https://make.wordpress.org/core/2022/10/08/escaping-table-and-field-names-with-wpdbprepare-in-wordpress-6-1/

And here is the screenshot as a reference:

image


If we still need to update (change) the %i, then please let me know and I will check it.

@mdperez86
Copy link
Contributor

Hi @alishanvr I was able to run the PHPCS without any problems after changing the query to

$wpdb->prepare(
  "SELECT DISTINCT os.order_id FROM {$wpdb->prefix}wc_order_stats os
  INNER JOIN {$wpdb->prefix}wc_customer_lookup cl ON os.customer_id = cl.customer_id
  INNER JOIN {$wpdb->usermeta} um ON cl.user_id = um.user_id
  WHERE (um.meta_key = 'billing_phone' OR um.meta_key = 'shipping_phone')
  AND um.meta_value = %s",
  wc_clean( $term )
)

The error you seen could happened due to the string concatenation like "..." . '...'. Note that in the prev example I just used the multi line representation "..."

@alishanvr
Copy link
Contributor Author

@mdperez86

Thank you for updating. I just updated both points.

@mdperez86
Copy link
Contributor

Thanks @alishanvr
The %i placeholder is new in WP since v6.2 so it seems like the PHPCS does not have a rule for that yet. So please could you not use it for now and keep the query with the previous interpolation way.

@alishanvr
Copy link
Contributor Author

Ok, I removed the %i and now used the older way.

Thank You,

@mdperez86
Copy link
Contributor

Thank you so much for your contribution @alishanvr. This PR looks good to me!

Copy link
Contributor

@mdperez86 mdperez86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!! Nice job @alishanvr

@mdperez86 mdperez86 merged commit 255d5f3 into woocommerce:trunk Apr 28, 2023
@github-actions github-actions bot added this to the 7.8.0 milestone Apr 28, 2023
lanej0 pushed a commit that referenced this pull request May 1, 2023
#37844)

* Order is search with the phone number and linked with the user account. #36810

* updated the query and tested on local env

* fixed the phpcs issue

* added the changelog

* updated the string concatenation issue and also moved the change log file to the correct path

* removed the %i placeholder from the query and used the old way to add the table name
@rodelgc
Copy link
Contributor

rodelgc commented May 24, 2023

Steps to test:

  1. Create a customer and make sure that it has a phone number saved.
  2. Create another customer and make sure that it has a different phone number saved.
  3. Create a new order using the first customer.
  4. Create another order using the second customer.
  5. In WooCommerce > Orders, search using the first customer's phone number. Verify that the first customer's order shows up, but the second customer's does not.
  6. In WooCommerce > Orders, search using the second customer's phone number. Verify that the second customer's order shows up, but the first customer's does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Allow searching by users/customers phone

4 participants