Asperience_DeleteAllOrders - Version 0.2.7

Version Notes

If you have ideas for improvements or find bugs, please send them to Jean-Sébastien Hederer at contact@asperience.fr, with ASPerience_DeleteAllOrders as part of the subject line.

Download this release

Release Info

Developer Magento Core Team
Extension Asperience_DeleteAllOrders
Version 0.2.7
Comparing to
See all releases


Code changes from version 0.2.6 to 0.2.7

app/code/community/Asperience/DeleteAllOrders/Helper/Data.php CHANGED
@@ -1,12 +1,11 @@
1
- <?php
2
- /**
3
- * @category ASPerience
4
- * @package Asperience_DeleteAllOrders
5
- * @author ASPerience - www.asperience.fr
6
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
- */
8
-
9
- class Asperience_DeleteAllOrders_Helper_Data extends Mage_Core_Helper_Data
10
  {
11
-
12
  }
1
+ <?php
2
+ /**
3
+ * @category ASPerience
4
+ * @package Asperience_DeleteAllOrders
5
+ * @author ASPerience - www.asperience.fr
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Asperience_DeleteAllOrders_Helper_Data extends Mage_Core_Helper_Data
10
  {
 
11
  }
app/code/community/Asperience/DeleteAllOrders/Model/Observer.php CHANGED
@@ -14,16 +14,13 @@ class Asperience_DeleteAllOrders_Model_Observer
14
 
15
  public function addOptionToSelect($observer)
16
  {
17
- if ($observer->getEvent()->getBlock()->getId() == 'sales_order_grid')
18
- {
19
  $massBlock = $observer->getEvent()->getBlock()->getMassactionBlock();
20
- if ($massBlock)
21
- {
22
- if(Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) &&
23
- Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/delete'))
24
- {
25
- if(Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL))
26
- {
27
  $massBlock->addItem('delete_order', array(
28
  'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
29
  'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
@@ -32,6 +29,7 @@ class Asperience_DeleteAllOrders_Model_Observer
32
  Warning: invoices/shipments/credit memos associated will be also deleted!'),
33
  ));
34
  } else {
 
35
  $massBlock->addItem('delete_order', array(
36
  'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
37
  'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
@@ -43,4 +41,4 @@ class Asperience_DeleteAllOrders_Model_Observer
43
  }
44
  }
45
  }
46
- }
14
 
15
  public function addOptionToSelect($observer)
16
  {
17
+ if ($observer->getEvent()->getBlock()->getId()=='sales_order_grid') {
 
18
  $massBlock = $observer->getEvent()->getBlock()->getMassactionBlock();
19
+ if ($massBlock) {
20
+ if (Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) &&
21
+ Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/delete')) {
22
+ if (Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL)) {
23
+ // Level 2: delete orders with other documents attached
 
 
24
  $massBlock->addItem('delete_order', array(
25
  'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
26
  'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
29
  Warning: invoices/shipments/credit memos associated will be also deleted!'),
30
  ));
31
  } else {
32
+ // Level 1: delete orders without documents attached
33
  $massBlock->addItem('delete_order', array(
34
  'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
35
  'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
41
  }
42
  }
43
  }
44
+ }
app/code/community/Asperience/DeleteAllOrders/Model/Order.php CHANGED
@@ -12,26 +12,30 @@ class Asperience_DeleteAllOrders_Model_Order extends Mage_Sales_Model_Order
12
  const XML_PATH_SALES_DELETE_ALL = 'sales/delete_order/delete_all';
13
  const XML_PATH_SALES_STATUS = 'sales/delete_order/order_status';
14
 
 
15
  public function getDeleteStatusIds()
16
  {
17
  return explode(',', Mage::getStoreConfig(self::XML_PATH_SALES_STATUS));
18
  }
19
-
20
  public function hasAvalaibleStatus()
21
  {
22
  return (in_array($this->getStatus(), $this->getDeleteStatusIds()));
23
  }
24
 
25
-
26
  public function hasNoOrdersRelated()
27
  {
28
  return (!$this->hasInvoices() && !$this->hasShipments() && !$this->hasCreditmemos());
29
  }
30
 
 
 
 
31
  public function canDelete()
32
  {
33
- return (Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) &&
34
- $this->hasAvalaibleStatus() &&
35
  (Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL) || $this->hasNoOrdersRelated()));
36
  }
37
- }
12
  const XML_PATH_SALES_DELETE_ALL = 'sales/delete_order/delete_all';
13
  const XML_PATH_SALES_STATUS = 'sales/delete_order/order_status';
14
 
15
+ // Status list
16
  public function getDeleteStatusIds()
17
  {
18
  return explode(',', Mage::getStoreConfig(self::XML_PATH_SALES_STATUS));
19
  }
20
+ // Check if order status is in list
21
  public function hasAvalaibleStatus()
22
  {
23
  return (in_array($this->getStatus(), $this->getDeleteStatusIds()));
24
  }
25
 
26
+ // Check for level 1 : check if order has documents attached
27
  public function hasNoOrdersRelated()
28
  {
29
  return (!$this->hasInvoices() && !$this->hasShipments() && !$this->hasCreditmemos());
30
  }
31
 
32
+ //Check delete conditions
33
+ // order without invoices/...
34
+ // or order with invoices/... but state that permits it
35
  public function canDelete()
36
  {
37
+ return (Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) &&
38
+ $this->hasAvalaibleStatus() &&
39
  (Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL) || $this->hasNoOrdersRelated()));
40
  }
41
+ }
app/code/community/Asperience/DeleteAllOrders/Model/Resource/Setup.php CHANGED
@@ -6,6 +6,6 @@
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
9
- class Asperience_DeleteAllOrders_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
10
-
11
  }
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
9
+ class Asperience_DeleteAllOrders_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
10
+ {
11
  }
app/code/community/Asperience/DeleteAllOrders/Model/Status.php CHANGED
@@ -10,7 +10,7 @@
10
  */
11
  class Asperience_DeleteAllOrders_Model_Status
12
  {
13
-
14
  public function toOptionArray()
15
  {
16
  $statuses = Mage::getSingleton('sales/order_config')->getStatuses();
@@ -27,4 +27,4 @@ class Asperience_DeleteAllOrders_Model_Status
27
  }
28
  return $options;
29
  }
30
- }
10
  */
11
  class Asperience_DeleteAllOrders_Model_Status
12
  {
13
+ //Format status list
14
  public function toOptionArray()
15
  {
16
  $statuses = Mage::getSingleton('sales/order_config')->getStatuses();
27
  }
28
  return $options;
29
  }
30
+ }
app/code/community/Asperience/DeleteAllOrders/controllers/IndexController.php CHANGED
@@ -5,6 +5,7 @@
5
  * @author ASPerience - www.asperience.fr
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
 
8
 
9
  class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_OrderController
10
  {
@@ -21,8 +22,7 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
21
  $orderIds = $this->getRequest()->getPost('order_ids', array());
22
 
23
  // Test if deletion active
24
- if (Mage::getStoreConfig(Asperience_DeleteAllOrders_Model_Order::XML_PATH_SALES_IS_ACTIVE))
25
- {
26
  $nbDelOrder = $nbDelInvoice = $nbDelShipment = $nbDelCreditmemo = 0;
27
  $nbDelOrderGrid = $nbDelInvoiceGrid = $nbDelShipmentGrid = $nbDelCreditmemoGrid = 0;
28
  $nbDelTax = $nbDelQuote = 0;
@@ -34,66 +34,52 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
34
  //Database connection for additional code when lack of integrity constraints
35
  $conn = Mage::getSingleton('core/resource')->getConnection('asperience/deleteallorders');
36
  try {
37
- foreach ($orderIds as $orderId)
38
- {
39
  //Load order
40
  $order = Mage::getModel('deleteallorders/order')->load($orderId);
41
- if($order->getIncrementId())
42
- {
43
  $orderLoaded = True;
44
- } else
45
- {
46
  $this->_getSession()->addWarning($this->__('No order loaded for id %s', $orderId));
47
  $orderLoaded = False;
48
  }
49
- $quoteId = False;
50
  //Regular delete
51
  $orderToDelete = False;
52
- if($orderLoaded)
53
- {
54
- //Check delete conditions
55
- // order without invoices/...
56
  // or order with invoices/... but state that permits it
57
- if ($order->canDelete())
58
- {
59
  $orderToDelete = True;
60
  // Delete linked invoices
61
- if ($order->hasInvoices())
62
- {
63
  $invoices = Mage::getResourceModel('sales/order_invoice_collection')
64
  ->setOrderFilter($orderId)->load();
65
- foreach($invoices as $invoice)
66
- {
67
- $id = $invoice->getId();
68
- $invoice = Mage::getModel('sales/order_invoice')->load($id);
69
  $invoicesDelete[] = $invoice->getIncrementId();
70
  $invoice->delete();
71
  $nbDelInvoice++;
72
  }
73
  }
74
  // Delete linked shipments
75
- if ($order->hasShipments())
76
- {
77
  $shipments = Mage::getResourceModel('sales/order_shipment_collection')
78
  ->setOrderFilter($orderId)->load();
79
- foreach($shipments as $shipment)
80
- {
81
- $id = $shipment->getId();
82
- $shipment = Mage::getModel('sales/order_shipment')->load($id);
83
  $shipmentsDelete[] = $shipment->getIncrementId();
84
  $shipment->delete();
85
  $nbDelShipment++;
86
  }
87
  }
88
  // Delete linked credit memos
89
- if ($order->hasCreditmemos())
90
- {
91
  $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
92
  ->setOrderFilter($orderId)->load();
93
- foreach($creditmemos as $creditmemo)
94
- {
95
- $id = $creditmemo->getId();
96
- $creditmemo = Mage::getModel('sales/order_creditmemo')->load($id);
97
  $creditsDelete[] = $creditmemo->getIncrementId();
98
  $creditmemo->delete();
99
  $nbDelCreditmemo++;
@@ -109,16 +95,14 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
109
  //Order is not deletable
110
  $ordersUndelete[] = $order->getIncrementId();
111
  }
112
- }
113
 
114
  //Additionnal code if lack of integrity constraints
115
- if($orderToDelete || !$orderLoaded)
116
- {
117
  // Delete grid linked invoices if not deleted by constraints
118
  $invoices = Mage::getModel('sales/resource_order_invoice_grid_collection')
119
  ->addFieldToFilter('order_id', $orderId);
120
- foreach($invoices as $invoice)
121
- {
122
  $invoicesGridDelete[] = $invoice->getIncrementId();
123
  $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/invoice_grid'),
124
  array('increment_id = ?' => (int) $invoice->getIncrementId()));
@@ -128,8 +112,7 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
128
  // Delete grid linked shipments if not deleted by constraints
129
  $shipments = Mage::getModel('sales/resource_order_shipment_grid_collection')
130
  ->addFieldToFilter('order_id', $orderId);
131
- foreach($shipments as $shipment)
132
- {
133
  $shipmentsGridDelete[] = $shipment->getIncrementId();
134
  $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/shipment_grid'),
135
  array('increment_id = ?' => (int) $shipment->getIncrementId()));
@@ -139,10 +122,9 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
139
  // Delete grid linked credit memos if not deleted by constraints
140
  $creditMemos = Mage::getResourceModel('sales/order_creditmemo_grid_collection')
141
  ->addFieldToFilter('order_id', $orderId);
142
- foreach($creditMemos as $creditMemo)
143
- {
144
  $creditsGridDelete[] = $creditMemo->getIncrementId();
145
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/creditmemo_grid'),
146
  array('increment_id = ?' => (int) $creditMemo->getIncrementId()));
147
  $nbDelCreditmemoGrid++;
148
  }
@@ -150,51 +132,46 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
150
  // Delete grid linked orders if not deleted by constraints
151
  $orders = Mage::getResourceModel('sales/order_grid_collection')
152
  ->addFieldToFilter('entity_id', $orderId);
153
- foreach($orders as $order)
154
- {
155
  $ordersGridDelete[] = $order->getIncrementId();
156
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/order_grid'),
157
  array('entity_id = ?' => (int) $order->getEntityId()));
158
  $nbDelOrderGrid++;
159
  }
160
 
161
- // Tables that should be deleted by constraints
162
- // downloadable_link_purchased
163
- // downloadable_link_purchased_item
164
- // sales_billing_agreement_order
165
- // sales_flat_order_address
166
- // sales_flat_order_payment
167
- // sales_flat_order_status_history
168
- // sales_flat_shipment_comment
169
- // sales_flat_order_item
170
- // sales_order_tax_item
171
- // sales_payment_transaction
172
- // sales_recurring_profile_order
 
173
 
174
  // Tables that are not deleted by constraints
175
- // sales_billing_agreement
176
  }
177
 
178
  //Additionnal code for tables without integrity constraints in regular version
179
- if($orderToDelete)
180
- {
181
  // Delete taxes
182
- $taxes = Mage::getModel('tax/sales_order_tax')->getCollection()
183
  ->addFieldToFilter('order_id', $orderId);
184
- foreach($taxes as $tax)
185
- {
186
- $id = $tax->getId();
187
  $taxesDelete[] = $tax->getTaxId();
188
- $tax = Mage::getModel('tax/sales_order_tax')->load($id);
189
- $tax->delete();
190
  $nbDelTax++;
191
  }
192
 
193
  // Delete quote
194
- $quote = Mage::getModel('sales/flat_quote')->load($quoteId);
195
- $quotesDelete[] = $quote->getId();
196
- $quote->delete();
197
- $nbDelQuote++;
198
  }
199
  }
200
  } catch (Exception $e){
@@ -202,79 +179,68 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
202
  $this->__('An error arose during the deletion. %s', $e));
203
  }
204
  // User messages format
205
- if ($nbDelOrder > 0)
206
- {
207
  $this->_getSession()->addSuccess(
208
- $this->__('%s order(s) was/were successfully deleted.',
209
  $nbDelOrder));
210
  $this->_getSession()->addSuccess(implode(" ", $ordersDelete));
211
  }
212
- if ($nbDelOrderGrid > 0)
213
- {
214
  $this->_getSession()->addSuccess(
215
- $this->__('%s order(s) was/were successfully deleted in grid.',
216
  $nbDelOrderGrid));
217
  $this->_getSession()->addSuccess(implode(" ", $ordersGridDelete));
218
  }
219
- if ($nbDelInvoice > 0)
220
- {
221
  $this->_getSession()->addSuccess(
222
- $this->__('%s invoice(s) was/were successfully deleted.',
223
  $nbDelInvoice));
224
  $this->_getSession()->addSuccess(implode(" ", $invoicesDelete));
225
  }
226
- if ($nbDelInvoiceGrid > 0)
227
- {
228
  $this->_getSession()->addSuccess(
229
- $this->__('%s invoice(s) was/were successfully deleted in grid.',
230
  $nbDelInvoiceGrid));
231
  $this->_getSession()->addSuccess(implode(" ", $invoicesGridDelete));
232
  }
233
- if ($nbDelShipment > 0)
234
- {
235
  $this->_getSession()->addSuccess(
236
- $this->__('%s shipment(s) was/were successfully deleted.',
237
  $nbDelShipment));
238
  $this->_getSession()->addSuccess(implode(" ", $shipmentsDelete));
239
  }
240
- if ($nbDelShipmentGrid > 0)
241
- {
242
  $this->_getSession()->addSuccess(
243
- $this->__('%s shipment(s) was/were successfully deleted in grid.',
244
  $nbDelShipmentGrid));
245
  $this->_getSession()->addSuccess(implode(" ", $shipmentsGridDelete));
246
  }
247
- if ($nbDelCreditmemo > 0)
248
- {
249
  $this->_getSession()->addSuccess(
250
- $this->__('%s credit memo(s) was/were successfully deleted.',
251
  $nbDelCreditmemo));
252
  $this->_getSession()->addSuccess(implode(" ", $creditsDelete));
253
  }
254
- if ($nbDelCreditmemoGrid > 0)
255
- {
256
  $this->_getSession()->addSuccess(
257
- $this->__('%s credit memo(s) was/were successfully deleted in grid.',
258
  $nbDelCreditmemoGrid));
259
  $this->_getSession()->addSuccess(implode(" ", $creditsGridDelete));
260
  }
261
- if($nbDelTax > 0)
262
- {
263
  $this->_getSession()->addSuccess(
264
- $this->__('%s order tax(es) was/were successfully deleted.',
265
  $nbDelTax));
266
  }
267
- if($nbDelQuote > 0)
268
- {
269
  $this->_getSession()->addSuccess(
270
- $this->__('%s quote(s) was/were successfully deleted.',
271
  $nbDelQuote));
272
  }
273
- if(count($ordersUndelete) > 0)
274
- {
275
  $this->_getSession()->addWarning(
276
- $this->__('Selected order(s) can not be deleted due to configuration: %s'),
277
- implode(" ", $ordersUndelete));
278
  }
279
  } else {
280
  // Deletion is deactivated
5
  * @author ASPerience - www.asperience.fr
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
+ require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
9
 
10
  class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_OrderController
11
  {
22
  $orderIds = $this->getRequest()->getPost('order_ids', array());
23
 
24
  // Test if deletion active
25
+ if (Mage::getStoreConfig(Asperience_DeleteAllOrders_Model_Order::XML_PATH_SALES_IS_ACTIVE)) {
 
26
  $nbDelOrder = $nbDelInvoice = $nbDelShipment = $nbDelCreditmemo = 0;
27
  $nbDelOrderGrid = $nbDelInvoiceGrid = $nbDelShipmentGrid = $nbDelCreditmemoGrid = 0;
28
  $nbDelTax = $nbDelQuote = 0;
34
  //Database connection for additional code when lack of integrity constraints
35
  $conn = Mage::getSingleton('core/resource')->getConnection('asperience/deleteallorders');
36
  try {
37
+ foreach ($orderIds as $orderId) {
 
38
  //Load order
39
  $order = Mage::getModel('deleteallorders/order')->load($orderId);
40
+ if ($order->getIncrementId()) {
 
41
  $orderLoaded = True;
42
+ } else {
 
43
  $this->_getSession()->addWarning($this->__('No order loaded for id %s', $orderId));
44
  $orderLoaded = False;
45
  }
46
+ $quoteId = False;
47
  //Regular delete
48
  $orderToDelete = False;
49
+ if ($orderLoaded) {
50
+ //Check delete conditions
51
+ // order without invoices/...
 
52
  // or order with invoices/... but state that permits it
53
+ if ($order->canDelete()) {
 
54
  $orderToDelete = True;
55
  // Delete linked invoices
56
+ if ($order->hasInvoices()) {
 
57
  $invoices = Mage::getResourceModel('sales/order_invoice_collection')
58
  ->setOrderFilter($orderId)->load();
59
+ foreach ($invoices as $invoice) {
60
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoice->getId());
 
 
61
  $invoicesDelete[] = $invoice->getIncrementId();
62
  $invoice->delete();
63
  $nbDelInvoice++;
64
  }
65
  }
66
  // Delete linked shipments
67
+ if ($order->hasShipments()) {
 
68
  $shipments = Mage::getResourceModel('sales/order_shipment_collection')
69
  ->setOrderFilter($orderId)->load();
70
+ foreach ($shipments as $shipment) {
71
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getId());
 
 
72
  $shipmentsDelete[] = $shipment->getIncrementId();
73
  $shipment->delete();
74
  $nbDelShipment++;
75
  }
76
  }
77
  // Delete linked credit memos
78
+ if ($order->hasCreditmemos()) {
 
79
  $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
80
  ->setOrderFilter($orderId)->load();
81
+ foreach ($creditmemos as $creditmemo) {
82
+ $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemo->getId());
 
 
83
  $creditsDelete[] = $creditmemo->getIncrementId();
84
  $creditmemo->delete();
85
  $nbDelCreditmemo++;
95
  //Order is not deletable
96
  $ordersUndelete[] = $order->getIncrementId();
97
  }
98
+ }
99
 
100
  //Additionnal code if lack of integrity constraints
101
+ if ($orderToDelete || !$orderLoaded) {
 
102
  // Delete grid linked invoices if not deleted by constraints
103
  $invoices = Mage::getModel('sales/resource_order_invoice_grid_collection')
104
  ->addFieldToFilter('order_id', $orderId);
105
+ foreach ($invoices as $invoice) {
 
106
  $invoicesGridDelete[] = $invoice->getIncrementId();
107
  $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/invoice_grid'),
108
  array('increment_id = ?' => (int) $invoice->getIncrementId()));
112
  // Delete grid linked shipments if not deleted by constraints
113
  $shipments = Mage::getModel('sales/resource_order_shipment_grid_collection')
114
  ->addFieldToFilter('order_id', $orderId);
115
+ foreach ($shipments as $shipment) {
 
116
  $shipmentsGridDelete[] = $shipment->getIncrementId();
117
  $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/shipment_grid'),
118
  array('increment_id = ?' => (int) $shipment->getIncrementId()));
122
  // Delete grid linked credit memos if not deleted by constraints
123
  $creditMemos = Mage::getResourceModel('sales/order_creditmemo_grid_collection')
124
  ->addFieldToFilter('order_id', $orderId);
125
+ foreach ($creditMemos as $creditMemo) {
 
126
  $creditsGridDelete[] = $creditMemo->getIncrementId();
127
+ $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/creditmemo_grid'),
128
  array('increment_id = ?' => (int) $creditMemo->getIncrementId()));
129
  $nbDelCreditmemoGrid++;
130
  }
132
  // Delete grid linked orders if not deleted by constraints
133
  $orders = Mage::getResourceModel('sales/order_grid_collection')
134
  ->addFieldToFilter('entity_id', $orderId);
135
+ foreach ($orders as $order) {
 
136
  $ordersGridDelete[] = $order->getIncrementId();
137
+ $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/order_grid'),
138
  array('entity_id = ?' => (int) $order->getEntityId()));
139
  $nbDelOrderGrid++;
140
  }
141
 
142
+ /* Tables that should be deleted by constraints
143
+ downloadable_link_purchased
144
+ downloadable_link_purchased_item
145
+ sales_billing_agreement_order
146
+ sales_flat_order_address
147
+ sales_flat_order_payment
148
+ sales_flat_order_status_history
149
+ sales_flat_shipment_comment
150
+ sales_flat_order_item
151
+ sales_order_tax_item
152
+ sales_payment_transaction
153
+ sales_recurring_profile_order
154
+ */
155
 
156
  // Tables that are not deleted by constraints
157
+ // sales_billing_agreement
158
  }
159
 
160
  //Additionnal code for tables without integrity constraints in regular version
161
+ if ($orderToDelete) {
 
162
  // Delete taxes
163
+ $taxes = Mage::getModel('tax/sales_order_tax')->getCollection()
164
  ->addFieldToFilter('order_id', $orderId);
165
+ foreach ($taxes as $tax) {
 
 
166
  $taxesDelete[] = $tax->getTaxId();
167
+ Mage::getModel('tax/sales_order_tax')->load($tax->getId())->delete();
 
168
  $nbDelTax++;
169
  }
170
 
171
  // Delete quote
172
+ $quotesDelete[] = $quoteId;
173
+ Mage::getModel('sales/quote')->load($quoteId)->delete();
174
+ $nbDelQuote++;
 
175
  }
176
  }
177
  } catch (Exception $e){
179
  $this->__('An error arose during the deletion. %s', $e));
180
  }
181
  // User messages format
182
+ if ($nbDelOrder > 0) {
 
183
  $this->_getSession()->addSuccess(
184
+ $this->__('%s order(s) was/were successfully deleted.',
185
  $nbDelOrder));
186
  $this->_getSession()->addSuccess(implode(" ", $ordersDelete));
187
  }
188
+ if ($nbDelOrderGrid > 0) {
 
189
  $this->_getSession()->addSuccess(
190
+ $this->__('%s order(s) was/were successfully deleted in grid.',
191
  $nbDelOrderGrid));
192
  $this->_getSession()->addSuccess(implode(" ", $ordersGridDelete));
193
  }
194
+ if ($nbDelInvoice > 0) {
 
195
  $this->_getSession()->addSuccess(
196
+ $this->__('%s invoice(s) was/were successfully deleted.',
197
  $nbDelInvoice));
198
  $this->_getSession()->addSuccess(implode(" ", $invoicesDelete));
199
  }
200
+ if ($nbDelInvoiceGrid > 0) {
 
201
  $this->_getSession()->addSuccess(
202
+ $this->__('%s invoice(s) was/were successfully deleted in grid.',
203
  $nbDelInvoiceGrid));
204
  $this->_getSession()->addSuccess(implode(" ", $invoicesGridDelete));
205
  }
206
+ if ($nbDelShipment > 0) {
 
207
  $this->_getSession()->addSuccess(
208
+ $this->__('%s shipment(s) was/were successfully deleted.',
209
  $nbDelShipment));
210
  $this->_getSession()->addSuccess(implode(" ", $shipmentsDelete));
211
  }
212
+ if ($nbDelShipmentGrid > 0) {
 
213
  $this->_getSession()->addSuccess(
214
+ $this->__('%s shipment(s) was/were successfully deleted in grid.',
215
  $nbDelShipmentGrid));
216
  $this->_getSession()->addSuccess(implode(" ", $shipmentsGridDelete));
217
  }
218
+ if ($nbDelCreditmemo > 0) {
 
219
  $this->_getSession()->addSuccess(
220
+ $this->__('%s credit memo(s) was/were successfully deleted.',
221
  $nbDelCreditmemo));
222
  $this->_getSession()->addSuccess(implode(" ", $creditsDelete));
223
  }
224
+ if ($nbDelCreditmemoGrid > 0) {
 
225
  $this->_getSession()->addSuccess(
226
+ $this->__('%s credit memo(s) was/were successfully deleted in grid.',
227
  $nbDelCreditmemoGrid));
228
  $this->_getSession()->addSuccess(implode(" ", $creditsGridDelete));
229
  }
230
+ if ($nbDelTax > 0) {
 
231
  $this->_getSession()->addSuccess(
232
+ $this->__('%s order tax(es) was/were successfully deleted.',
233
  $nbDelTax));
234
  }
235
+ if ($nbDelQuote > 0) {
 
236
  $this->_getSession()->addSuccess(
237
+ $this->__('%s quote(s) was/were successfully deleted.',
238
  $nbDelQuote));
239
  }
240
+ if (count($ordersUndelete) > 0) {
 
241
  $this->_getSession()->addWarning(
242
+ $this->__('Selected order(s) can not be deleted due to configuration:'));
243
+ $this->_getSession()->addWarning(implode(" ", $ordersUndelete));
244
  }
245
  } else {
246
  // Deletion is deactivated
app/code/community/Asperience/DeleteAllOrders/etc/config.xml CHANGED
@@ -10,7 +10,7 @@
10
  <config>
11
  <modules>
12
  <Asperience_DeleteAllOrders>
13
- <version>0.2.5</version>
14
  </Asperience_DeleteAllOrders>
15
  </modules>
16
 
10
  <config>
11
  <modules>
12
  <Asperience_DeleteAllOrders>
13
+ <version>0.2.7</version>
14
  </Asperience_DeleteAllOrders>
15
  </modules>
16
 
app/code/community/Asperience/DeleteAllOrders/sql/asperience_deleteallorders_setup/mysql4-install-0.2.4.php CHANGED
@@ -10,9 +10,7 @@
10
  Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
11
  (
12
  "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
13
- "Do not forget to configure the status you want to be able to delete. This module is provided by ASPerience (http://www.asperience.fr/)",
 
14
  "http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html"
15
- );
16
-
17
-
18
- ?>
10
  Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
11
  (
12
  "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
13
+ "Do not forget to configure the status you want to be able to delete. ".
14
+ "This module is provided by ASPerience (http://www.asperience.fr/)",
15
  "http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html"
16
+ );
 
 
 
app/code/community/Asperience/DeleteAllOrders/sql/asperience_deleteallorders_setup/mysql4-upgrade-0.2.3-0.2.4.php CHANGED
@@ -10,8 +10,7 @@
10
  Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
11
  (
12
  "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
13
- "Do not forget to configure the status you want to be able to delete. This module is provided by ASPerience (http://www.asperience.fr/)",
 
14
  "http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html"
15
- );
16
-
17
- ?>
10
  Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
11
  (
12
  "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
13
+ "Do not forget to configure the status you want to be able to delete. ".
14
+ "This module is provided by ASPerience (http://www.asperience.fr/)",
15
  "http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html"
16
+ );
 
 
app/etc/modules/Asperience_DeleteAllOrders.xml CHANGED
@@ -12,9 +12,6 @@
12
  <Asperience_DeleteAllOrders>
13
  <active>true</active>
14
  <codePool>community</codePool>
15
- <depends>
16
- <Asperience_Notificationmanager/>
17
- </depends>
18
  </Asperience_DeleteAllOrders>
19
  </modules>
20
  </config>
12
  <Asperience_DeleteAllOrders>
13
  <active>true</active>
14
  <codePool>community</codePool>
 
 
 
15
  </Asperience_DeleteAllOrders>
16
  </modules>
17
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Asperience_DeleteAllOrders</name>
4
- <version>0.2.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
@@ -9,12 +9,15 @@
9
  <summary>Extension allowing to delete orders</summary>
10
  <description>This extension allows to delete either selected sales orders WITHOUT invoices, shipments and credit memos or selected sales orders WITH invoices, shipments and credit memos.&#xD;
11
  You can set the status of orders you want to delete in the configuration section.&#xD;
12
- Warning: It's preferable to delete only the testing orders during the development of your local website. Orders deletion is at your own risk.</description>
 
 
 
13
  <notes>If you have ideas for improvements or find bugs, please send them to Jean-S&#xE9;bastien Hederer at contact@asperience.fr, with ASPerience_DeleteAllOrders as part of the subject line.</notes>
14
- <authors><author><name>Jean-S&#xE9;bastien Hederer</name><user>hedererjs</user><email>hedererjs@asperience.fr</email></author></authors>
15
- <date>2014-11-29</date>
16
- <time>13:42:49</time>
17
- <contents><target name="magecommunity"><dir name="Asperience"><dir name="DeleteAllOrders"><dir name="Helper"><file name="Data.php" hash="0729d914be45ecebf2db9e7a6fea00a2"/></dir><dir name="Model"><file name="Observer.php" hash="955197296d93ba87b500ccfb59537150"/><file name="Order.php" hash="b5c869462ac7ad35583e1758fbcc980b"/><dir name="Resource"><file name="Setup.php" hash="c1ad36387742288b9ded169283f5e2b1"/></dir><file name="Status.php" hash="b17aae3030d6d2b54b4a694e4bb1231a"/></dir><dir name="controllers"><file name="IndexController.php" hash="99619b947f0ebf7c64ccd48cc9ef2abb"/></dir><dir name="etc"><file name="config.xml" hash="802046fd2f367404526ca3bdd7aa4125"/><file name="system.xml" hash="a6ffdfefc94437bd6bf45453549aa389"/></dir><dir name="sql"><dir name="asperience_deleteallorders_setup"><file name="mysql4-install-0.2.4.php" hash="cec104e3a919cc9031d256eae69c4f4b"/><file name="mysql4-upgrade-0.2.3-0.2.4.php" hash="86cbc156b2b01c6d35b41fb3e56793e2"/></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="de_DE"><file name="Asperience_DeleteAllOrders.csv" hash="3b17c8b23f90a9ade272559da0bc3ce0"/></dir><dir name="en_US"><file name="Asperience_DeleteAllOrders.csv" hash="9529fa6e4e87db30bca48ce104cb0d05"/></dir><dir name="fr_FR"><file name="Asperience_DeleteAllOrders.csv" hash="25f0bf507116918d1862ce5a18035a15"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Asperience_DeleteAllOrders.xml" hash="c7b443af96e9f0e3447cf21f52a27f4f"/></dir></target></contents>
18
  <compatible/>
19
- <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Asperience_Notificationmanager</name><channel>community</channel><min>0.1.0</min><max></max></package></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Asperience_DeleteAllOrders</name>
4
+ <version>0.2.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
9
  <summary>Extension allowing to delete orders</summary>
10
  <description>This extension allows to delete either selected sales orders WITHOUT invoices, shipments and credit memos or selected sales orders WITH invoices, shipments and credit memos.&#xD;
11
  You can set the status of orders you want to delete in the configuration section.&#xD;
12
+ Warning: It's preferable to delete only the testing orders during the development of your local website. Orders deletion is at your own risk.&#xD;
13
+ &#xD;
14
+ This module is developed by ASPerience, french company. &#xD;
15
+ &lt;a target="_blank" url="http://www.asperience.fr"&gt;http://www.asperience.fr&lt;/a&gt;</description>
16
  <notes>If you have ideas for improvements or find bugs, please send them to Jean-S&#xE9;bastien Hederer at contact@asperience.fr, with ASPerience_DeleteAllOrders as part of the subject line.</notes>
17
+ <authors><author><name>Jean-S&#xE9;bastien Hederer</name><user>auto-converted</user><email>hedererjs@asperience.fr</email></author></authors>
18
+ <date>2014-12-04</date>
19
+ <time>18:18:48</time>
20
+ <contents><target name="magecommunity"><dir name="Asperience"><dir name="DeleteAllOrders"><dir name="Helper"><file name="Data.php" hash="99d64355c5282368f45f4066fd9d6f36"/></dir><dir name="Model"><dir name="Resource"><file name="Setup.php" hash="003c4441446ceee8fc7211efa0f8d0d0"/></dir><file name="Observer.php" hash="4fef7d309009f4376d4dffe0daf43f6a"/><file name="Order.php" hash="e3b0f70842ae828a8e5d3ee9949a5517"/><file name="Status.php" hash="fbd9c124ffaf85765e4fa9a96fe0e3bc"/></dir><dir name="controllers"><file name="IndexController.php" hash="0478226d510b9c2fae11880d6e2cfa06"/></dir><dir name="etc"><file name="config.xml" hash="49747fac8b2a0fc74afcdd55658092ae"/><file name="system.xml" hash="a6ffdfefc94437bd6bf45453549aa389"/></dir><dir name="sql"><dir name="asperience_deleteallorders_setup"><file name="mysql4-install-0.2.4.php" hash="18d2c7b4e5f37be0654b3eae5756647a"/><file name="mysql4-upgrade-0.2.3-0.2.4.php" hash="4749e0b8c0f0d5d0ebb59421c31483c9"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="de_DE"><file name="Asperience_DeleteAllOrders.csv" hash="3b17c8b23f90a9ade272559da0bc3ce0"/></dir><dir name="en_US"><file name="Asperience_DeleteAllOrders.csv" hash="9529fa6e4e87db30bca48ce104cb0d05"/></dir><dir name="fr_FR"><file name="Asperience_DeleteAllOrders.csv" hash="25f0bf507116918d1862ce5a18035a15"/></dir></target><target name="mageetc"><dir name="modules"><file name="Asperience_DeleteAllOrders.xml" hash="564d484d06362fee6d4f0b42660bfa85"/></dir></target></contents>
21
  <compatible/>
22
+ <dependencies><required><package><name>Asperience_Notificationmanager</name><channel>community</channel><min>0.1.1</min><max></max></package></required></dependencies>
23
  </package>