Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Add A Dispatch Rate Topic   - - - - -

 
  • lparodi
  • Member
  • Trial users
  • Join Date: 08-Dec 14
  • 46 posts

Posted 21 September 2015 - 10:44 AM #1

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.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21782 posts

Posted 21 September 2015 - 11:53 AM #2

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') {
....
}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • lparodi
  • Member
  • Trial users
  • Join Date: 08-Dec 14
  • 46 posts

Posted 21 September 2015 - 01:43 PM #3

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: