Skip to content
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

[API PULL] Tweak WP Proxy Response to force the types of the price fields #2624

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Sep 25, 2024

Changes proposed in this Pull Request:

Context: p1726057670716979/1722414955.111429-slack-C02BB3F30TG

This PR forces the types of price fields (price, regular_price, sale_price) to be strings.

Detailed test instructions:

  1. Create a high-priority snippet to force the fields to be integers without checking out this PR
add_filter( 'woocommerce_rest_prepare_product_object', function ( $response, $object, $request ) {
    $response->data['price'] = intval( $response->data['price'] );
    $response->data['regular_price'] = intval( $response->data['regular_price'] );
    $response->data['sale_price'] = intval( $response->data['sale_price'] );

    return $response;
}, 999999, 3);
  1. Request GET wp-json/wc/v3/products
  2. See the prices as integers
  3. Checkout this PR
  4. Request GET wp-json/wc/v3/products
  5. See prices still as integers
  6. Request GET wp-json/wc/v3/products?gla_syncable=1
  7. See prices as strings

Additional details:

Changelog entry

Tweak - Adjust WP Proxy Response to force the string type for the price fields

@puntope puntope requested review from jorgemd24 and a team September 25, 2024 14:20
@puntope puntope self-assigned this Sep 25, 2024
@github-actions github-actions bot added type: bug The issue is a confirmed bug. changelog: fix Took care of something that wasn't working. labels Sep 25, 2024
Copy link
Contributor

@jorgemd24 jorgemd24 left a comment

Choose a reason for hiding this comment

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

Thanks @puntope for working on this. I tested locally and works as expected so LGTM.

@jorgemd24
Copy link
Contributor

Not related to this PR but the below tests is failing. We will need to look into it:

Automattic\WooCommerce\GoogleListingsAndAds\Tests\Unit\Product\SyncerHooksTest::test_delete_created_product_calls_notify_directly
Expectation failed for method name is "notify" when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.

@puntope puntope merged commit c93a26a into develop Sep 27, 2024
8 of 10 checks passed
@puntope puntope deleted the fix/api-pull-type-prices branch September 27, 2024 08:27
@tomalec tomalec mentioned this pull request Oct 2, 2024
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants