Skip to content
Snippets Groups Projects
Commit 9a6cede7 authored by Ryan Szrama's avatar Ryan Szrama
Browse files

Apply a fix to product deletion by directly manipulating product reference...

Apply a fix to product deletion by directly manipulating product reference field data instead of depending on the entity_metadata_wrapper().
parent 361ab451
No related branches found
No related tags found
No related merge requests found
......@@ -176,7 +176,18 @@ function commerce_product_reference_commerce_product_delete($product) {
// Loop over each entity and remove the reference to the deleted product.
foreach ($entities as $entity_id => $entity) {
$entity = commerce_entity_reference_delete($entity_type, $entity, $field_name, $product->product_id);
foreach ($entity->{$field_name} as $langcode => $items) {
foreach ($items as $delta => $item) {
if ($item['product_id'] == $product->product_id) {
unset($entity->{$field_name}[$langcode][$delta]);
}
}
// If the reference field is empty, wipe its data altogether.
if (count($entity->{$field_name}[$langcode]) == 0) {
unset($entity->{$field_name}[$langcode]);
}
}
// Store the changes to the entity.
entity_save($entity_type, $entity);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment