Jump to content

Delete all disable products with php script


erry91

Recommended Posts

Hi everyone,

i need to delete all disable products, the problem is that are more than 30k

 

I want to use a php scrip that i cron one a week, that delete this disable products only, and keep the active.

I fear that if i delete products just from table ps_product, then this can cause issue with website because same id are present on ps_lang, ps_image so on...

 

I know this script is simple for a developer(i'm not) so is there anybody can help me delete this disable products from website?

 

Greeting from Enrico.

Link to comment
Share on other sites

10 hours ago, hshaker said:

active

Hi man,

thanks so much for reply.

 

I need to delete disable so te corret one is this?

('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `disable` = 0 ORDER BY `id_product` DESC LIMIT 10 ').

 

Another question is, which table i have to delete to correct deleting products? only ps_product or other tables?

 

Regards from Enrico.

 

Link to comment
Share on other sites

il y a 15 minutes, erry91 a dit :

Hi man,

thanks so much for reply.

 

I need to delete disable so te corret one is this?

('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `disable` = 0 ORDER BY `id_product` DESC LIMIT 10 ').

 

Another question is, which table i have to delete to correct deleting products? only ps_product or other tables?

 

Regards from Enrico.

 

😬 You will go deleting all product NOT disable with this code 

Edited by hshaker (see edit history)
Link to comment
Share on other sites

ATTENTION !!!
Don't do this.
You will not delete pictures, etc.
I gave you a link to a ready-made solution, I don't understand why you are giving another solution here?

 

<?php
    require_once('./config/config.inc.php');

    $limit = 10;

    $res = Db::getInstance()->executeS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `active` = 0 ORDER BY `id_product` DESC LIMIT '.$limit);

    $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    $i = 0;

    if ($res) {

        foreach ($res as $row) {
            echo "<p>(".date('Y/m/d H:i:s').") Deleting product with ID <b>".$row['id_product']."</b>...";
            $p = new Product($row['id_product']);
            if(!$p->delete()) {
                echo " <span style='color: red'>Error deleting this product!</span></p>";
            } else {
                echo " <span style='color: green'>DELETED</span></p>";
            }

            $i++;
        }

    }

    if ($i == $limit) {
        echo '<script type="text/javascript">setTimeout(function(){window.top.location="'.$actual_link.'"} , 500);</script>';
    }

 

PHP file (save as Prestashop root folder) and call URL http://your-shop.com/masive-delete-inactive-product.php

 

masive-delete-inactive-product.php

Edited by WebSoft (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...