Magento 1.9 – How to Manually Remove a Product from Database

deletemagento-1.9product

I have a product in the database that was created using an extension installed on a previous magento (1.6.2) installation (to the one I am running currently – 1.9.2). The extension is no longer in use, and has not been added to the new system. All relevant data (products, sales, accounts, etc etc etc) was ported over from magento 1.6.2 to my shiny new 1.9.2 installation. Unfortunately, I forgot about the product created with this extension (a booking product). And as that extension is no longer part of my system, any time it crops up, it causes a site error.

This error happens in the admin and on the front end.
The error is to do with a missing product type in the database

(Invalid backend model specified: booking/entity_attribute_backend_rangetype).

Which I take to mean there is no reference in the database for a "booking" product type, because the extension isn't installed to add that info to the system.

Looking at the catalog_… tables, I can find the EAV entity ID of the product in question, but wondered if there was an easier way to remove all references to that entity ID from all database tables other than trawling through them all one by one and manually removing the rows?

I created a script to loop through the products in order to try and delete them that way, the following is the meat of that script:

Once I have the collection created, I loop through it (there are 2 products of this type in total), but the system fails to delete the products. Here is the code for the loop through…

foreach ($collection as $product) {
    $thisProductID = $product->getId();

    try {
        $product = Mage::getModel("catalog/product")->load($thisProductID);
        if ($product) {
            $product->delete();
            echo '<p>'.$thisProductID.' - Deleted successfully'.'</p>'; 
        }
    }
    catch (Exception $e) {
        echo '<p>'.$thisProductID.' - Delete failed: ', $e->getMessage(), '</p>'; 
    }

}

And here is my output when I run this:

25712 – Delete failed: Invalid backend model specified: booking/entity_attribute_backend_rangetype

25713 – Delete failed: Invalid backend model specified: booking/entity_attribute_backend_rangetype

I'm really not sure how to get around this, as I do not want to install a module for the sake of these two products being in the database (and crashing the website if they get browsed frontend or admin).

Any suggestions more than welcome 🙂

Best Answer

Using delete() function,delete an product object's from database is better way.

As per as,your share, whenever you have try to delete product using this function then get error message

Delete failed: Invalid backend model specified: booking/entity_attribute_backend_rangetype

So, if you will resolve this issue then you will again delete the product using delete() that will better idea.

Let resolve invalid backend model specified:

This error occur when your system have an attribute and that attribute backend model is booking/entity_attribute_backend_rangetype and that backend model class has already delete from system.

So if we delete this attribute then $product->delete(),will work properly.

So run this query:

DELETE FROM `eav_attribute` WHERE `backend_model`='booking/entity_attribute_backend_rangetype'

Note: Before do this take a full backup of database

Now run your code $product->delete(); and see what happen

Related Topic