Skip to content

Commit

Permalink
feat-update-product-type
Browse files Browse the repository at this point in the history
  • Loading branch information
benbenben2 committed Dec 27, 2024
1 parent 32d58e0 commit fbfda8d
Show file tree
Hide file tree
Showing 6 changed files with 938 additions and 874 deletions.
80 changes: 80 additions & 0 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,83 @@ sub compute_languages ($product_ref) {
return;
}

=head2 review_product_type ( $product_ref )
Reviews the product type based on the presence of specific tags in the categories field.
Updates the product type if necessary.
=head3 Arguments
=head4 Product reference $product_ref
A reference to a hash containing the product details.
=cut

sub review_product_type ($product_ref) {

my $error;

if ($product_ref->{product_type} eq "beauty") {
if (has_tag($product_ref, "categories", "en:non-beauty-products")) {
if (has_tag($product_ref, "categories", "en:open-food-facts")) {
$error = change_product_type($product_ref, "food");
}
elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) {
$error = change_product_type($product_ref, "petfood");
}
elsif (has_tag($product_ref, "categories", "en:open-products-facts")) {
$error = change_product_type($product_ref, "product");
}
}
}
elsif ($product_ref->{product_type} eq "food") {
if (has_tag($product_ref, "categories", "en:non-food-products")) {
if (has_tag($product_ref, "categories", "en:open-beauty-facts")) {
$error = change_product_type($product_ref, "beauty");
}
elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) {
$error = change_product_type($product_ref, "petfood");
}
elsif (has_tag($product_ref, "categories", "en:open-products-facts")) {
$error = change_product_type($product_ref, "product");
}
}
}
elsif ($product_ref->{product_type} eq "petfood") {
if (has_tag($product_ref, "categories", "en:non-pet-food-products")) {
if (has_tag($product_ref, "categories", "en:open-beauty-facts")) {
$error = change_product_type($product_ref, "beauty");
}
elsif (has_tag($product_ref, "categories", "en:open-food-facts")) {
$error = change_product_type($product_ref, "food");
}
elsif (has_tag($product_ref, "categories", "en:open-products-facts")) {
$error = change_product_type($product_ref, "product");
}
}
}
elsif ($product_ref->{product_type} eq "product") {
if (has_tag($product_ref, "categories", "en:non-food-products")) {
if (has_tag($product_ref, "categories", "en:open-beauty-facts")) {
$error = change_product_type($product_ref, "beauty");
}
elsif (has_tag($product_ref, "categories", "en:open-food-facts")) {
$error = change_product_type($product_ref, "food");
}
elsif (has_tag($product_ref, "categories", "en:open-pet-food-facts")) {
$error = change_product_type($product_ref, "petfood");
}
}
}

if ($error) {
$log->error("review_product_type - error", {error => $error, product_ref => $product_ref});
}

return;
}

=head2 process_product_edit_rules ($product_ref)
Process the edit_rules (see C<@edit_rules> in in Config file).
Expand Down Expand Up @@ -3678,6 +3755,9 @@ sub analyze_and_enrich_product_data ($product_ref, $response_ref) {

compute_languages($product_ref); # need languages for allergens detection and cleaning ingredients

# change the product type of non-food categorized products (issue #11094)
review_product_type($product_ref);

# Run special analysis, score calculations that it specific to the product type

if (($options{product_type} eq "food")) {
Expand Down
Loading

0 comments on commit fbfda8d

Please # to comment.