how to remove specific products by code in a script

Hi!

I run a update script that loads all products into my cs-cart catalogue thru a csv. The problem is that such csv has many errors which my supplier won’t fix, no matter how many times I have pointed this out.

Anyway, I need that some good samaritan gives me a piece of code with which I can remove automatically or better, stop from uploading, specific product codes.

Having that piece of code which I can add somewhere in the update script (or outside) I will be able to add the conflictive product codes and they won’t be showing anymore in my store.

Can anyone help me with this?:confused:

If you take the following code and either create the file addons/my_changes/func.php or add the fn_register_hooks() function call and the 2 functions to an existing func.php, this should remove the product_codes listed in the first function from the “import stream”.



This is not tested in any way and strongly suggest you backup your database before trying this. Also suggest that you try it on a 2 line import. One line containing a code not in the excluded list and one that is. You should then see that one product was processed.


```php

fn_register_hooks( 'import_pre_moderation');

function excluded_product_codes() {
return array( 'product_code_1', 'product_code_2', 'etc');
}

function fn_my_changes_import_pre_moderation($pattern, &$import_data, $options, $processed_data) {
$excluded_upcs = excluded_product_codes();
if( !$excluded_upcs || empty($_REQUEST['pattern_id']) || $_REQUEST['pattern_id'] != 'products' )
return;

foreach($import_data as $idx => $row_data) {
if( in_array($row_data['product_code'], $excluded_upcs) )
unset($import_data[$idx]);
}
}
?>

```

Thank you, tbirnseth, who else but you would reply with a solution so fast?:smiley:

I’ll try what you suggest.

tbirnseth, i added the code with the corresponding product codes to addons/my_changes/func.php but it doesn’t seem to work.

I must comment that the catalogue is uploaded thru an update srcipt and a cron job, not thru importing it manually in admin panel. Does this info matters?

I ran the script and the “bad products” were uploaded inspite of the fix



extra note: I use version 2.0.14.

If it does not use the cart’s exim (export/import mechanism, then the hook would never be triggered.



Are you saying your script does it’s own import (I.e. updates the DB directly)? That would be pretty risky in trying to keep up with any changes that happen in the DB or fixes that occur to issues in product imports.

[quote name=‘tbirnseth’]

Are you saying your script does it’s own import (I.e. updates the DB directly)? That would be pretty risky in trying to keep up with any changes that happen in the DB or fixes that occur to issues in product imports.[/QUOTE]



yep, that’s what i’m saying, sent you a pm :wink:

I got your PM and your email. I responded to the email but have yet to receive a response. As stated, I will take a look with no commitment.

[quote name='mirnitagl' timestamp='1302942395' post='110198']

I run a update script that loads all products into my cs-cart catalogue thru a csv.

[/quote]



Can you post your update script, please.

It could be a solution for me an other users to automate the import process.