Skip to content

Commit

Permalink
Merge pull request #2636 from woocommerce/release/2.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalec authored Oct 2, 2024
2 parents 6c6002c + 53f3043 commit dffee9c
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 278 deletions.
6 changes: 3 additions & 3 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ install_wc() {
if [ ! -f "$WC_VERSION_FILE" ]; then
# set up testing suite
rm -rf "$WC_DIR"
mkdir -p "$WC_DIR"
echo "Installing WooCommerce ($WC_VERSION)."
# Grab the necessary plugins.
WC_TMPDIR="${TMPDIR}/woocommerce-${WC_VERSION}"
rm -rf "${WC_TMPDIR}"
git clone --quiet --depth=1 --branch="${WC_VERSION}" https://github.com/woocommerce/woocommerce.git "${WC_TMPDIR}"
mv "${WC_TMPDIR}"/plugins/woocommerce/* "$WC_DIR"
touch "$WC_VERSION_FILE"

ln -s "${WC_TMPDIR}"/plugins/woocommerce "$WC_DIR"
touch "$WC_VERSION_FILE"

# Install composer for WooCommerce
cd "${WC_DIR}"
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** Google for WooCommerce Changelog ***

= 2.8.6 - 2024-10-02 =
* Dev - Fix missing blueprint dependency.
* Tweak - Adjust WP Proxy Response to force the string type for the price fields.
* Tweak - Logic for Delete notifications.

= 2.8.5 - 2024-09-05 =
* Break - Remove WooCommerce Navigation integration.
* Fix - Issue with syncing shipping rates with more than two decimals.
Expand Down
4 changes: 2 additions & 2 deletions google-listings-and-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Google for WooCommerce
* Plugin URL: https://wordpress.org/plugins/google-listings-and-ads/
* Description: Native integration with Google that allows merchants to easily display their products across Google’s network.
* Version: 2.8.5
* Version: 2.8.6
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: google-listings-and-ads
Expand All @@ -30,7 +30,7 @@

defined( 'ABSPATH' ) || exit;

define( 'WC_GLA_VERSION', '2.8.5' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_VERSION', '2.8.6' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_MIN_PHP_VER', '7.4' );
define( 'WC_GLA_MIN_WC_VER', '6.9' );

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-listings-and-ads",
"title": "Google for WooCommerce",
"version": "2.8.5",
"version": "2.8.6",
"description": "Google for WooCommerce",
"author": "Automattic",
"license": "GPL-3.0-or-later",
Expand Down
12 changes: 6 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 5.9
Tested up to: 6.6
Requires PHP: 7.4
Requires PHP Architecture: 64 Bits
Stable tag: 2.8.5
Stable tag: 2.8.6
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -140,6 +140,11 @@ To allow your products to appear in all relevant locations, make sure you’ve c

== Changelog ==

= 2.8.6 - 2024-10-02 =
* Dev - Fix missing blueprint dependency.
* Tweak - Adjust WP Proxy Response to force the string type for the price fields.
* Tweak - Logic for Delete notifications.

= 2.8.5 - 2024-09-05 =
* Break - Remove WooCommerce Navigation integration.
* Fix - Issue with syncing shipping rates with more than two decimals.
Expand All @@ -160,9 +165,4 @@ To allow your products to appear in all relevant locations, make sure you’ve c
* Tweak - Replace deprecated event.keyCode with event.code for the verification code inputs in the contact information setting.
* Tweak - Update the copy in the "Linked accounts" of the accounts connection setting to include Google Ads account.

= 2.8.3 - 2024-08-20 =
* Fix - Return empty array props as empty objects in WCOM Proxy responses.
* Tweak - Display additional context in error message when Google Ads account limit reached.
* Tweak - Upgrade readme details in WPORG.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/google-listings-and-ads/trunk/changelog.txt).
506 changes: 253 additions & 253 deletions src/Hooks/README.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/Integration/WPCOMProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ protected function register_object_types_filter( string $object_type ): void {
add_filter(
'woocommerce_rest_prepare_' . $object_type . '_object',
[ $this, 'filter_response_by_syncable_item' ],
1000, // Run this filter last to override any other response.
PHP_INT_MAX, // Run this filter last to override any other response.

Check warning on line 135 in src/Integration/WPCOMProxy.php

View check run for this annotation

Codecov / codecov/patch

src/Integration/WPCOMProxy.php#L135

Added line #L135 was not covered by tests
3
);

add_filter(
'woocommerce_rest_prepare_' . $object_type . '_object',
[ $this, 'prepare_response' ],
10,
PHP_INT_MAX - 1,

Check warning on line 142 in src/Integration/WPCOMProxy.php

View check run for this annotation

Codecov / codecov/patch

src/Integration/WPCOMProxy.php#L142

Added line #L142 was not covered by tests
3
);

Expand Down Expand Up @@ -338,6 +338,11 @@ public function prepare_response( WP_REST_Response $response, $item, WP_REST_Req
$attr = $this->attribute_manager->get_all_aggregated_values( $item );
// In case of empty array, convert to object to keep the response consistent.
$data['gla_attributes'] = (object) $attr;

// Force types and prevent user type change for fields as Google has strict type requirements.
$data['price'] = strval( $data['price'] ?? null );
$data['regular_price'] = strval( $data['regular_price'] ?? null );
$data['sale_price'] = strval( $data['sale_price'] ?? null );
}

foreach ( $data['meta_data'] ?? [] as $key => $meta ) {
Expand Down
19 changes: 9 additions & 10 deletions src/Product/SyncerHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ protected function handle_update_product_notification( WC_Product $product ) {
* @param int $product_id
*/
protected function handle_delete_product( int $product_id ) {
if ( $this->notifications_service->is_ready() ) {
/**
* For deletions, we do send directly the notification instead of scheduling it.
* This is because we want to avoid that the product is not in the database anymore when the scheduled action runs.
*/
$this->maybe_send_delete_notification( $product_id );
}

if ( isset( $this->delete_requests_map[ $product_id ] ) ) {
$product_id_map = BatchProductIDRequestEntry::convert_to_id_map( $this->delete_requests_map[ $product_id ] )->get();
if ( ! empty( $product_id_map ) && ! $this->is_already_scheduled_to_delete( $product_id ) ) {
Expand All @@ -331,8 +323,7 @@ protected function handle_delete_product( int $product_id ) {
* @param int $product_id
*/
protected function maybe_send_delete_notification( int $product_id ) {
$product = wc_get_product( $product_id );

$product = $this->wc->maybe_get_product( $product_id );
if ( $product instanceof WC_Product && $this->product_helper->has_notified_creation( $product ) ) {
$result = $this->notifications_service->notify( NotificationsService::TOPIC_PRODUCT_DELETED, $product_id, [ 'offer_id' => $this->product_helper->get_offer_id( $product_id ) ] );
if ( $result ) {
Expand Down Expand Up @@ -365,6 +356,14 @@ protected function schedule_delete_notification( $product ) {
* @param int $product_id
*/
protected function handle_pre_delete_product( int $product_id ) {
if ( $this->notifications_service->is_ready() ) {
/**
* For deletions, we do send directly the notification instead of scheduling it.
* This is because we want to avoid that the product is not in the database anymore when the scheduled action runs.
*/
$this->maybe_send_delete_notification( $product_id );
}

$product = $this->wc->maybe_get_product( $product_id );

// each variation is passed to this method separately so we don't need to delete the variable product
Expand Down
45 changes: 45 additions & 0 deletions tests/Unit/Integration/WPCOMProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,49 @@ public function test_get_empty_settings_for_shipping_zone_methods_as_object() {
$proxy->prepare_data( $data, $request )
);
}

public function test_product_types() {
add_filter( 'woocommerce_rest_prepare_product_object', [ $this, 'alter_product_price_types' ], 10, 3 );

$product = ProductHelper::create_simple_product();
$product_variable = ProductHelper::create_variation_product();
$variation = $product_variable->get_available_variations()[0];
$this->add_metadata( $product->get_id(), $this->get_test_metadata() );

$request = $this->do_request( '/wc/v3/products', 'GET', [ 'gla_syncable' => '1' ] );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['regular_price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['sale_price'] ) );

$request = $this->do_request( '/wc/v3/products/' . $product->get_id(), 'GET', [ 'gla_syncable' => '1' ] );
$this->assertEquals( 'string', gettype( $request->get_data()['price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()['regular_price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()['sale_price'] ) );

$request = $this->do_request( '/wc/v3/products/' . $product_variable->get_id() . '/variations', 'GET', [ 'gla_syncable' => '1' ] );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['regular_price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()[0]['sale_price'] ) );

$request = $this->do_request( '/wc/v3/products/' . $product_variable->get_id() . '/variations/' . $variation['variation_id'], 'GET', [ 'gla_syncable' => '1' ] );
$this->assertEquals( 'string', gettype( $request->get_data()['price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()['regular_price'] ) );
$this->assertEquals( 'string', gettype( $request->get_data()['sale_price'] ) );

// Doesn't apply if here is not 'gla_syncable'
$request = $this->do_request( '/wc/v3/products' );
$this->assertEquals( 'integer', gettype( $request->get_data()[0]['price'] ) );
$this->assertEquals( 'integer', gettype( $request->get_data()[0]['regular_price'] ) );
$this->assertEquals( 'integer', gettype( $request->get_data()[0]['sale_price'] ) );

remove_filter( 'woocommerce_rest_prepare_product_object', [ $this, 'alter_product_price_types' ] );
}

public function alter_product_price_types( $response ) {
$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;
}
}

0 comments on commit dffee9c

Please sign in to comment.