Remove Drupal Commerce Empty Products

1k views Asked by At

I am getting empty products in my views recently after the first few rounds of having a crawler import the data for the products. Unfortunately, after deleting all but two products that existed beforehand, These "empty" products still exist. I also made sure there were no extra variation types, and cleared the commerce_line_item table. Does anybody know where I can find and get rid of these nameless products?

Here is a photo for reference: https://i.stack.imgur.com/7cLWS.png [1]

I noticed this title (this product was created by the) was able to be selected and edited. This is the only title that shows up: https://i.stack.imgur.com/zpk2z.png

Unfortunately, after trying to edit it, this is the error I get: https://i.stack.imgur.com/PDQus.png

After running @Clive's script, I couldn't flush the cache and I received these errors:

Notice: Undefined index: label in entity_views_field_definition() (line 191 of /home/accuairt/public_html/profiles/commerce_kickstart/modules/contrib/entity/views/entity.views.inc).
Notice: Undefined index: search_api_views_fulltext in views_handler_filter->accept_exposed_input() (line 1260 of /home/accuairt/public_html/profiles/commerce_kickstart/modules/contrib/views/handlers/views_handler_filter.inc).
Notice: Undefined index: table in entity_views_plugin_row_entity_view->init() (line 20 of /home/accuairt/public_html/profiles/commerce_kickstart/modules/contrib/entity/views/plugins/entity_views_plugin_row_entity_view.inc).
SearchApiException: Unknown or invalid item type node. in search_api_get_datasource_controller() (line 1506 of /home/accuairt/public_html/profiles/commerce_kickstart/modules/contrib/search_api/search_api.module).
STATUS MESSAGE Operating in maintenance mode. Go online.
The website encountered an unexpected error. Please try again later.

I restored a backup from a few hours ago to get the site back where it was.

edit: 12/18 Still looking for an answer. There has to be a table I can clear to get rid of this information.

1

There are 1 answers

4
Clive On

If you know for definite that all products without a title should be deleted you can try something like this:

$query = new \EntityFieldQuery();
$query->entityCondition('entity_type', 'commerce_product')
  ->propertyCondition('title', '');

$results = $query->execute();
if (!empty($results['commerce_product'])) {
  commerce_product_delete_multiple(array_keys($results['commerce_product']));
}

It might be wise to inspect the results of the query before you run the delete function, just to make sure you're not deleting anything you want to keep by mistake.