Closed (works as designed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Product
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Jan 2012 at 23:39 UTC
Updated:
23 Feb 2013 at 18:35 UTC
Hello, guys.
First of all - thanks for a great job you're doing. [=
I've found myself confused a little when I was not able to delete a product with commerce_product_delete() inside hook_node_delete(). It just increase $product id by 1.
commerce_product_delete() is returning TRUE, so it works actually, but the product is not removed. I've walked thru the function's life path and didn't found anything suspicious.
But when commerce_product_delete() is used outside the hook (form submit as example) - everything is perfect.
Do I missed something?
Comments
Comment #1
amateescu commentedYou must have missed something :) I have tried this with two products, one that was referenced from a product display node and one that wasn't, and both worked just fine.
Comment #2
giorgio79 commentedI am getting this as well.
#1 How did you try to delete a product without a display with hook_node_delete? I don't think that is possible as hook_node_delete operates on the product display deletion. :)
Here ist he code I am using
PS: Even Rules fails, wow :)
Comment #3
rszrama commentedMy hunch is that the node relation here is incidental but not the main issue. The function commerce_product_delete() will fail if commerce_product_can_delete() returns FALSE, and the main implementation to consider is in the product reference module, commerce_product_reference_commerce_product_can_delete(). If a product is referenced by a line item (i.e. if you have ever added it to the cart), then the product cannot be deleted. You can still delete the node, and its product reference field data will be wiped just fine, but you cannot delete the product itself; you have to just disable it.
This should be covered in the documentation from a UI standpoint on drupalcommerce.org, and from an API standpoint you can look at the documentation for hook_commerce_product_can_delete() in commerce_product.api.php.
Comment #4
giorgio79 commentedThanks Ryan, much appreciated. will sniff around those functions. Re the product I tested was never added to a cart or anything.
Comment #5
rszrama commentedHmm, ok, then I'm going to need more information to go on if you can reproduce the issue.
Comment #6
giorgio79 commentedSure, thx Ryan. Don't want to waste your time, as this issue will become obsolete once Inline Entity Form matures.
I suspect the problem is that during http://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/... the node still exists in the db, and commerce product warns if it is deleted but still referenced.
So, the issue is consistent. I set up the usual stuff, a product, plus a random content type, with a product reference field in it. I hide the product ref field from the user, and I do Entity CRUD in the background with hook_nodes (inline entity form will do this but I had some styling issues with fieldsets that are still to be sorted..,).
In the code, ïtem is my display content type.
Pretty much this is it. Once deletion fails, I go to Store, and can delete it manually easily.
Comment #7
rszrama commentedI still don't get what in Commerce is preventing deletion. Is it an implementation of hook_commerce_product_can_delete() or just a warning in the Entity API?
Comment #8
giorgio79 commentedI revisited the issue, and the rule works now (after deleting hook_node_delete from my module). It works with a rule, so I wont be pursuing this. :)