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] Fix tests for Notifying delete products #2626

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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