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

Fix Issue with intermediate parents status #2263

Merged
Show file tree
Hide file tree
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
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
Loading