Skip to content

Commit

Permalink
Merge pull request #2263 from woocommerce/fix/issue-with-intermediate…
Browse files Browse the repository at this point in the history
…-parents-status

Fix Issue with intermediate parents status
  • Loading branch information
jorgemd24 authored Feb 22, 2024
2 parents a0aed9b + d7ecd99 commit 683c6d4
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 68 deletions.
26 changes: 24 additions & 2 deletions src/MerchantCenter/MerchantStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ protected function update_intermediate_product_statistics( &$products ): array {
MCStatus::PENDING => 0,
MCStatus::DISAPPROVED => 0,
MCStatus::NOT_SYNCED => 0,
'parents' => [],
];

// If the option is set, use it to sum the total quantity.
Expand Down Expand Up @@ -765,8 +766,27 @@ protected function update_intermediate_product_statistics( &$products ): array {
}
}

foreach ( $parent_statuses as $parent_status ) {
$product_statistics[ $parent_status ] += 1;
foreach ( $parent_statuses as $parent_id => $new_parent_status ) {
$current_parent_intermediate_data_status = $product_statistics_intermediate_data['parents'][ $parent_id ] ?? null;

if ( $current_parent_intermediate_data_status === $new_parent_status ) {
continue;
}

if ( ! $current_parent_intermediate_data_status ) {
$product_statistics[ $new_parent_status ] += 1;
$product_statistics['parents'][ $parent_id ] = $new_parent_status;
continue;
}

// Check if the new parent status has higher priority than the previous one.
if ( $product_statistics_priority[ $new_parent_status ] < $product_statistics_priority[ $current_parent_intermediate_data_status ] ) {
$product_statistics[ $current_parent_intermediate_data_status ] -= 1;
$product_statistics[ $new_parent_status ] += 1;
$product_statistics['parents'][ $parent_id ] = $new_parent_status;
} else {
$product_statistics['parents'][ $parent_id ] = $current_parent_intermediate_data_status;
}
}

$this->options->update( OptionsInterface::PRODUCT_STATUSES_COUNT_INTERMEDIATE_DATA, $product_statistics );
Expand Down Expand Up @@ -803,6 +823,8 @@ public function handle_complete_mc_statuses_fetching() {

if ( $intermediate_data ) {

unset( $intermediate_data['parents'] );

$total_synced_products = $this->calculate_total_synced_product_statistics( $intermediate_data );

/** @var ProductRepository $product_repository */
Expand Down
Loading

0 comments on commit 683c6d4

Please sign in to comment.