Posted by Delicious Simplicity on August 6, 2011 at 12:40am
1 follower
Jump to:
| Project: | UC Node Checkout |
| Version: | 6.x-2.0-beta8 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
For the sake of being tidy, it be nice to delete the associated checkout nodes if the order itself is deleted by an admin. As it is now an order with two checkout nodes would require three steps to fully remove the associated content from the database: (1) delete the order, (2) delete checkout node one, (3) delete checkout node two.
I've added the following to my installation inside the uc_node_checkout_order() call on line 812:
<?php
case 'delete':
foreach ($arg1->products as $product) {
// If it has a node checkout nid...
if (!empty($product->data['node_checkout_nid'])) {
node_delete($product->data['node_checkout_nid']);
watchdog('node checkout', 'deleted node ' . $node->uid . ' from the database');
}
}
break;
?>It is working well for my needs. When an admin deletes the order, it takes the two checkout nodes with it. It logs this event to watchdog (optional). Thoughts?
Comments
#1
ADDENDUM
I noticed that sometimes two orders can have the same checkout node associations. For example if a customer backs out of checkout before it is fully complete, then finishes it later, a duplicate order number is sometimes generated. For example order ID 1 and order ID 2, both show the same product and the same checkout node, however order ID is 'COMPLETE' and order ID 1 shows 'IN CHECKOUT'.
If an admin were to clean up the expired 'IN CHECKOUT' orders and delete order ID 1, the code above would delete the associated node, thereby leaving order ID 2 referencing a deleted checkout node -- not good.
The updated code (below) checks the relationship of the checkout node to the order (reverse, which is unique), if this doesn't match the order being deleted then it will not fire node_delete().
<?phpcase 'delete':
foreach ($arg1->products as $product) {
// If it has a node checkout nid...
if (!empty($product->data['node_checkout_nid'])) {
$node = node_load($product->data['node_checkout_nid']);
$ncOrderID = db_result(db_query('SELECT order_id FROM uc_order_products WHERE order_product_id = %d', $node->uc_order_product_id));
if ($arg1->order_id == $ncOrderID) {
node_delete($product->data['node_checkout_nid']);
watchdog('node checkout', 'deleted node ' . $node->uid . ' from the database');
}
}
}
break;
?>
#2