I removed a product from the shopping cart, then deleted the product, then removed the product type. And am now getting this error which makes the site unusable.
EntityMetadataWrapperException: Unable to load the commerce_product with the id 3. in EntityDrupalWrapper->value() (line 623 of /Users/henrique/Webroot/commerce/sites/all/modules/entity/includes/entity.wrapper.inc).
I think this problem is that the product display node is already there. So we should either remove the reference from the node display node. Or prevent from deleting products which were referenced by a product display node, just like we do with products that were already been ordered.
Comments
Comment #1
recidive commentedComment #2
rszrama commentedUse the strategy of the line item module to delete product IDs from product reference fields when products are deleted here.
Comment #3
recidive commentedI talked with Ryan on IRC and we agreed in doing two things:
If user go ahead and delete the product anyway, and a) if the product is the only one referenced by the node, and b) the product reference field is set to "Required". The user will end up with a broken/inconsistent node. There's a issue for dealing with that already: #1029950: Deleting a Product doesn't delete associated Product Display.
Comment #4
recidive commentedI committed the changes to my branch here:
https://github.com/recidive/drupalcommerce/tree/1035050
I also replaced the commerce_line_item_reference_delete() function with commerce_entity_reference_delete(), since I needed that function to work for product reference fields as well. That genericized functions was put into commerce.module as Ryan advised.
Comment #5
rszrama commentedCommitted this with the following fixes:
https://github.com/rszrama/drupalcommerce/commit/11e4c49fcaca80055cb169f...
I'm actually not sure to what extent you tested this patch before sending the pull request. At least w/ the Commerce Dev profile, delete was failing outright because commerce_entity_reference_delete() wouldn't work for single value references. I grant you may have had a product display node type with a multi-value reference... but even so the function commerce_product_reference_commerce_product_delete() was trying to pass $line_item->line_item_id to the function instead of $product->product_id.
I also changed my mind and went ahead and made the delete confirmation form show the different types of entities referencing the product... not a big deal, and I also went ahead and prevented submission for products referenced by line items since commerce_product_reference_commerce_product_can_delete() will prevent it anyways.