-4

I am using kickstart commerce and feeds import to import my products in a csv.

I need to delete some products and product displays using mysql in phpmyadmin because I had a bad import execution with mistakes, now they are in phpmyadmin, but they are not showing up in my backend admin views, I can't reimport again because it says "no new nodes" when I try to reimport althought I have checked replace items.

Please,, what mysql commands can I use to delete any products and products displays, that fits my condition, for example where title='%mypattern%'.

Thank you.

  • anytime you do something major like this, before doing that, you should backup your Database. – No Sssweat Jun 12 '16 at 0:59
2

You should not do that. Products are fieldable entities, and if you delete commerce products in database directly, you will have rubbish remaining there. You should use the api call commerce_product_delete(). http://www.drupalcontrib.org/api/drupal/contributions!commerce!modules!product!commerce_product.module/function/commerce_product_delete/7

Sample code (please note, that I have not actually tried it, use for reference: Entity queries: https://www.drupal.org/node/1343708):

<?php 

$pattern = 'mypattern%';

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'commerce_product')
  ->propertyCondition('title', $pattern, 'LIKE')

$result = $query->execute();

if (isset($result['commerce_product'])) {
  $ids = array_keys($result['commerce_product']);
  commerce_product_delete_multiple($ids);
  $news_items = entity_load('node', $news_items_nids);
}

?>
  • Thank you @Alexei Rayu, I am trying to do with mysql because just I am starter in module programming, please what would be the drupal code to delete products and product displays where title like '%sometitle%'? – bunset Jun 11 '16 at 21:56
  • Updated my response with the sample code. – Alexei Rayu Jun 12 '16 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.