Add A Dispatch

Hello,
I'm trying to delete a big amount of products and to do that I thought to upload the product
codes to a custom table named "custom_products_to_delete" and then use the fn_delete_product
function to perform the deletion.

This is what I did:

I have added these lines of code in products.php

\app\controllers\backend\products.php

if($mode == "deleteobsolete")
{
$a = db_get_array("SELECT product_id FROM cscart_products,custom_products_to_delete WHERE custom_products_to_delete.product_code =cscart_products.product_code");
foreach($a as $v)
{
fn_delete_product($v['product_id']);
}
}


and then I have created an empty deleteobsolete.tpl file

\design\backend\templates\views\products\deleteobsolete.tpl


but When I call /admin.php?dispatch=products.deleteobsolete nothing happens. I don't receive any errors but the products are not being deleted.

Try

if($mode == "deleteobsolete")
{
      $a = db_get_array("SELECT product_id FROM cscart_products,custom_products_to_delete WHERE custom_products_to_delete.product_code =cscart_products.product_code");
  fn_echo('Products found: ' . count($a));

  foreach($a as $v)
  {
         fn_echo(' . ')
         fn_delete_product($v['product_id']);
  }

  fn_echo('Done');
  exit;

}

make sure that your code is not within the following condition:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
....
}

Thank you again !

The problem was that the code was inside the block if ($_SERVER['REQUEST_METHOD'] == 'POST') {
....
}

I owe at least a dozen beers :grin: