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: export obsolete products - draft #8397

Merged
merged 3 commits into from
May 11, 2023
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
21 changes: 3 additions & 18 deletions cgi/export_products.pl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

if ($action eq "display") {

my $template_data_ref = {lang => \&lang,};
my $template_data_ref = {};

# Query filters

Expand All @@ -95,25 +95,10 @@
}
}

# Number of products matching the optional query
my $count = count_products({}, $query_ref);

# Number of products matching the query with changes that have not yet been imported
$query_ref->{states_tags} = "en:to-be-exported";
my $count_to_be_exported = count_products({}, $query_ref);

$template_data_ref->{count} = $count;
$template_data_ref->{count_to_be_exported} = $count_to_be_exported;

if ($count == 0) {
$template_data_ref->{n_products_will_be_exported} = lang("no_products_to_export");
}
elsif ($count == 1) {
$template_data_ref->{n_products_will_be_exported} = lang("one_product_will_be_exported");
}
else {
$template_data_ref->{n_products_will_be_exported} = sprintf(lang("n_products_will_be_exported"), $count);
}
$template_data_ref->{count_to_be_exported} = count_products({}, $query_ref);
$template_data_ref->{count_obsolete_to_be_exported} = count_products({}, $query_ref, 1);

my $export_photos_value = "";
my $replace_selected_photos_value = "";
Expand Down
16 changes: 5 additions & 11 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,10 @@ sub display_index_for_producer ($request_ref) {
}

# Display a message if some product updates have not been published yet
# Updates can also be on obsolete products

my $count = count_products($request_ref, {states_tags => "en:to-be-exported"});

if ($count == 1) {
$template_data_ref->{products_to_be_exported} = lang("one_product_will_be_exported");
}
elsif ($count > 1) {
$template_data_ref->{products_to_be_exported} = sprintf(lang("n_products_will_be_exported"), $count);
}
$template_data_ref->{count_to_be_exported} = count_products({}, {states_tags => "en:to-be-exported"});
$template_data_ref->{count_obsolete_to_be_exported} = count_products({}, {states_tags => "en:to-be-exported"}, 1);

my $html;

Expand Down Expand Up @@ -4369,7 +4364,7 @@ sub add_country_and_owner_filters_to_query ($request_ref, $query_ref) {
return;
}

sub count_products ($request_ref, $query_ref) {
sub count_products ($request_ref, $query_ref, $obsolete = 0) {

add_country_and_owner_filters_to_query($request_ref, $query_ref);

Expand All @@ -4379,8 +4374,7 @@ sub count_products ($request_ref, $query_ref) {
$log->debug("Counting MongoDB documents for query", {query => $query_ref}) if $log->is_debug();
$count = execute_query(
sub {
return get_products_collection({obsolete => request_param($request_ref, "obsolete")})
->count_documents($query_ref);
return get_products_collection({obsolete => $obsolete})->count_documents($query_ref);
}
);
};
Expand Down
Loading