Asperience_DeleteAllOrders - Version 0.2.4

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 Jean-Sébastien Hederer
Extension Asperience_DeleteAllOrders
Version 0.2.4
Comparing to
See all releases


Code changes from version 0.2.3 to 0.2.4

app/code/community/Asperience/DeleteAllOrders/Helper/Data.php CHANGED
@@ -8,5 +8,5 @@
8
 
9
  class Asperience_DeleteAllOrders_Helper_Data extends Mage_Core_Helper_Data
10
  {
11
-
12
  }
8
 
9
  class Asperience_DeleteAllOrders_Helper_Data extends Mage_Core_Helper_Data
10
  {
11
+
12
  }
app/code/community/Asperience/DeleteAllOrders/Model/Observer.php CHANGED
@@ -6,34 +6,41 @@
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
9
-
10
  class Asperience_DeleteAllOrders_Model_Observer
11
  {
12
- const XML_PATH_SALES_IS_ACTIVE = 'sales/delete_order/is_active';
13
- const XML_PATH_SALES_DELETE_ALL = 'sales/delete_order/delete_all';
14
- const XML_PATH_SALES_STATUS = 'sales/delete_order/order_status';
15
-
16
- public function addOptionToSelect($observer)
17
  {
18
- if ($observer->getEvent()->getBlock()->getId() == 'sales_order_grid') {
19
- $massBlock = $observer->getEvent()->getBlock()->getMassactionBlock();
20
- if ($massBlock) {
21
- if(Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) && Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/delete')) {
22
- if(Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL)) {
23
- $massBlock->addItem('delete_order', array(
24
- 'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
25
- 'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
26
- 'confirm' => Mage::helper('deleteallorders')->__('Are you sure to delete the selected sales orders? Warning: invoices/shipments/credit memos associated will be also deleted!'),
27
- ));
28
- } else {
29
- $massBlock->addItem('delete_order', array(
30
- 'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
31
- 'url' => Mage::helper('adminhtml')->getUrl('deleteallorders'),
32
- 'confirm' => Mage::helper('deleteallorders')->__('Are you sure to delete the selected sales orders?'),
33
- ));
34
- }
35
- }
36
- }
37
- }
 
 
 
 
 
 
 
 
38
  }
39
- }
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
 
9
  class Asperience_DeleteAllOrders_Model_Observer
10
  {
11
+ const XML_PATH_SALES_IS_ACTIVE = 'sales/delete_order/is_active';
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 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'),
30
+ 'confirm' => Mage::helper('deleteallorders')
31
+ ->__('Are you sure to delete the selected sales orders?
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'),
38
+ 'confirm' => Mage::helper('deleteallorders')
39
+ ->__('Are you sure to delete the selected sales orders?'),
40
+ ));
41
+ }
42
+ }
43
+ }
44
+ }
45
  }
46
+ }
app/code/community/Asperience/DeleteAllOrders/Model/Order.php CHANGED
@@ -6,31 +6,32 @@
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
9
-
10
  class Asperience_DeleteAllOrders_Model_Order extends Mage_Sales_Model_Order
11
  {
12
- const XML_PATH_SALES_IS_ACTIVE = 'sales/delete_order/is_active';
13
- const XML_PATH_SALES_DELETE_ALL = 'sales/delete_order/delete_all';
14
- const XML_PATH_SALES_STATUS = 'sales/delete_order/order_status';
15
-
16
- public function getDeleteStatusIds()
17
- {
18
- return explode(',', Mage::getStoreConfig(self::XML_PATH_SALES_STATUS));
19
- }
20
-
21
  public function hasAvalaibleStatus()
22
  {
23
- return (in_array($this->getStatus(), $this->getDeleteStatusIds()));
24
  }
25
 
26
 
27
  public function hasNoOrdersRelated()
28
  {
29
- return (!$this->hasInvoices() && !$this->hasShipments() && !$this->hasCreditmemos());
30
  }
31
 
32
  public function canDelete()
33
  {
34
- return (Mage::getStoreConfig(self::XML_PATH_SALES_IS_ACTIVE) && $this->hasAvalaibleStatus() && (Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL) || $this->hasNoOrdersRelated()));
 
 
35
  }
36
- }
6
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
  */
8
 
 
9
  class Asperience_DeleteAllOrders_Model_Order extends Mage_Sales_Model_Order
10
  {
11
+ const XML_PATH_SALES_IS_ACTIVE = 'sales/delete_order/is_active';
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
+ }
app/code/community/Asperience/DeleteAllOrders/Model/Resource/Setup.php ADDED
@@ -0,0 +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_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
10
+
11
+ }
app/code/community/Asperience/DeleteAllOrders/Model/Status.php CHANGED
@@ -27,4 +27,4 @@ class Asperience_DeleteAllOrders_Model_Status
27
  }
28
  return $options;
29
  }
30
- }
27
  }
28
  return $options;
29
  }
30
+ }
app/code/community/Asperience/DeleteAllOrders/controllers/IndexController.php CHANGED
@@ -1,205 +1,285 @@
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
- require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
10
-
11
  class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_OrderController
12
  {
13
- protected function _construct()
14
- {
15
- $this->setUsedModuleName('Asperience_DeleteAllOrders');
16
- }
17
- /**
18
- * Delete selected orders
19
- */
20
- public function indexAction()
21
- {
22
- $orderIds = $this->getRequest()->getPost('order_ids', array());
23
- if (Mage::getStoreConfig(Asperience_DeleteAllOrders_Model_Order::XML_PATH_SALES_IS_ACTIVE)) {
24
- $countDeleteOrder = 0;
25
- $countDeleteOrderGrid = 0;
26
- $countDeleteOrderGridException = 0;
27
- $countDeleteInvoice = 0;
28
- $countDeleteInvoiceGrid = 0;
29
- $countDeleteInvoiceGridException = 0;
30
- $countDeleteShipment = 0;
31
- $countDeleteShipmentGrid = 0;
32
- $countDeleteShipmentGridException = 0;
33
- $countDeleteCreditmemo = 0;
34
- $countDeleteCreditmemoGrid = 0;
35
- $countDeleteCreditmemoGridException = 0;
36
- $countDeleteTax = 0;
37
- $orders_delete = array();
38
- $invoices_delete = array();
39
- $creditmemos_delete = array();
40
- $shipments_delete = array();
41
- $orders_grid_delete = array();
42
- $invoices_grid_delete = array();
43
- $creditmemos_grid_delete = array();
44
- $shipments_grid_delete = array();
45
- $taxes_delete = array();
46
- $orders_undelete = array();
47
- $conn = Mage::getSingleton('core/resource')->getConnection('asperience/deleteallorders');
48
- try {
49
- foreach ($orderIds as $orderId) {
50
- $order = Mage::getModel('deleteallorders/order')->load($orderId);
51
- if($order->getIncrementId()) {
52
- $order_loaded = True;
53
- } else {
54
- $this->_getSession()->addWarning($this->__('No order loaded for id %s', $orderId));
55
- $order_loaded = False;
56
- }
57
-
58
- $order_to_delete = False;
59
- if($order_loaded) {
60
- if ($order->canDelete()) {
61
- $order_to_delete = True;
62
-
63
- if ($order->hasInvoices()) {
64
- $invoices = Mage::getResourceModel('sales/order_invoice_collection')->setOrderFilter($orderId)->load();
65
- foreach($invoices as $invoice){
66
- $id = $invoice->getId();
67
- $invoice = Mage::getModel('sales/order_invoice')->load($id);
68
- $invoices_delete[] = $invoice->getIncrementId();
69
- $invoice->delete();
70
- $countDeleteInvoice++;
71
- }
72
- }
73
-
74
- if ($order->hasShipments()) {
75
- $shipments = Mage::getResourceModel('sales/order_shipment_collection')->setOrderFilter($orderId)->load();
76
- foreach($shipments as $shipment){
77
- $id = $shipment->getId();
78
- $shipment = Mage::getModel('sales/order_shipment')->load($id);
79
- $shipments_delete[] = $shipment->getIncrementId();
80
- $shipment->delete();
81
- $countDeleteShipment++;
82
- }
83
- }
84
-
85
- if ($order->hasCreditmemos()) {
86
- $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')->setOrderFilter($orderId)->load();
87
- foreach($creditmemos as $creditmemo){
88
- $id = $creditmemo->getId();
89
- $creditmemo = Mage::getModel('sales/order_creditmemo')->load($id);
90
- $creditmemos_delete[] = $creditmemo->getIncrementId();
91
- $creditmemo->delete();
92
- $countDeleteCreditmemo++;
93
- }
94
- }
95
- $order = Mage::getModel('sales/order')->load($orderId);
96
- $orders_delete[] = $order->getIncrementId();
97
- $order->delete();
98
- $countDeleteOrder++;
99
- } else {
100
- $orders_undelete[] = $order->getIncrementId();
101
- }
102
- }
103
-
104
- if($order_to_delete || !$order_loaded) {
105
-
106
- $invoices = Mage::getModel('sales/resource_order_invoice_grid_collection')
107
- ->addFieldToFilter('order_id', $orderId);
108
- foreach($invoices as $invoice){
109
- $invoices_grid_delete[] = $invoice->getIncrementId();
110
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/invoice_grid'),
111
- array('increment_id = ?' => (int) $invoice->getIncrementId()));
112
- $countDeleteInvoiceGrid++;
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- $shipments = Mage::getModel('sales/resource_order_shipment_grid_collection')
116
- ->addFieldToFilter('order_id', $orderId);
117
- foreach($shipments as $shipment){
118
- $shipments_grid_delete[] = $shipment->getIncrementId();
119
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/shipment_grid'),
120
- array('increment_id = ?' => (int) $shipment->getIncrementId()));
121
- $countDeleteShipmentGrid++;
122
- }
123
-
124
- $credit_memos = Mage::getResourceModel('sales/order_creditmemo_grid_collection')
125
- ->addFieldToFilter('order_id', $orderId);
126
- foreach($credit_memos as $credit_memo){
127
- $creditmemos_grid_delete[] = $credit_memo->getIncrementId();
128
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/creditmemo_grid'),
129
- array('increment_id = ?' => (int) $credit_memo->getIncrementId()));
130
- $countDeleteCreditmemoGrid++;
131
- }
 
 
 
 
132
 
133
- $orders = Mage::getResourceModel('sales/order_grid_collection')
134
- ->addFieldToFilter('entity_id', $orderId);
135
- foreach($orders as $order){
136
- $orders_grid_delete[] = $order->getIncrementId();
137
- $conn->delete(Mage::getSingleton('core/resource')->getTableName('sales/order_grid'),
138
- array('entity_id = ?' => (int) $order->getEntityId()));
139
- $countDeleteOrderGrid++;
140
- }
141
- }
142
- if($order_to_delete) {
143
- /*$conn->delete(Mage::getSingleton('core/resource')->getTableName('tax/sales_order_tax'),
144
- array('order_id = ?' => (int) $tax->getOrderId()));*/
145
- $taxes = Mage::getModel('tax/sales_order_tax')->getCollection()
146
- ->addFieldToFilter('order_id', $orderId);
147
- foreach($taxes as $tax){
148
- $id = $tax->getId();
149
- //Mage::log($tax->getData());
150
- $taxes_delete[] = $tax->getTaxId();
151
- $tax = Mage::getModel('tax/sales_order_tax')->load($id);
152
- $tax->delete();
153
- $countDeleteTax++;
154
- }
155
- }
156
- }
157
- } catch (Exception $e){
158
- $this->_getSession()->addError($this->__('An error arose during the deletion. %s', $e));
159
- }
160
 
161
- if ($countDeleteOrder > 0) {
162
- $this->_getSession()->addSuccess($this->__('%s order(s) was/were successfully deleted.', $countDeleteOrder));
163
- $this->_getSession()->addSuccess(implode(" ",$orders_delete));
164
- }
165
- if ($countDeleteOrderGrid > 0) {
166
- $this->_getSession()->addSuccess($this->__('%s order(s) was/were successfully deleted in grid.', $countDeleteOrderGrid));
167
- $this->_getSession()->addSuccess(implode(" ",$orders_grid_delete));
168
- }
169
- if ($countDeleteInvoice > 0) {
170
- $this->_getSession()->addSuccess($this->__('%s invoice(s) was/were successfully deleted.', $countDeleteInvoice));
171
- $this->_getSession()->addSuccess(implode(" ",$invoices_delete));
172
- }
173
- if ($countDeleteInvoiceGrid > 0) {
174
- $this->_getSession()->addSuccess($this->__('%s invoice(s) was/were successfully deleted in grid.', $countDeleteInvoiceGrid));
175
- $this->_getSession()->addSuccess(implode(" ",$invoices_grid_delete));
176
- }
177
- if ($countDeleteShipment > 0) {
178
- $this->_getSession()->addSuccess($this->__('%s shipment(s) was/were successfully deleted.', $countDeleteShipment));
179
- $this->_getSession()->addSuccess(implode(" ",$shipments_delete));
180
- }
181
- if ($countDeleteShipmentGrid > 0) {
182
- $this->_getSession()->addSuccess($this->__('%s shipment(s) was/were successfully deleted in grid.', $countDeleteShipmentGrid));
183
- $this->_getSession()->addSuccess(implode(" ",$shipments_grid_delete));
184
- }
185
- if ($countDeleteCreditmemo > 0) {
186
- $this->_getSession()->addSuccess($this->__('%s credit memo(s) was/were successfully deleted.', $countDeleteCreditmemo));
187
- $this->_getSession()->addSuccess(implode(" ",$creditmemos_delete));
188
- }
189
- if ($countDeleteCreditmemoGrid > 0) {
190
- $this->_getSession()->addSuccess($this->__('%s credit memo(s) was/were successfully deleted in grid.', $countDeleteCreditmemoGrid));
191
- $this->_getSession()->addSuccess(implode(" ",$creditmemos_grid_delete));
192
- }
193
- if(count($countDeleteTax) > 0) {
194
- $this->_getSession()->addSuccess($this->__('%s order tax(es) was/were successfully deleted.', $countDeleteTax));
195
- }
196
- if(count($orders_undelete) > 0) {
197
- $this->_getSession()->addWarning($this->__('Selected order(s) can not be deleted due to configuration:').implode(" ",$orders_undelete));
198
- }
199
-
200
- } else {
201
- $this->_getSession()->addError($this->__('This feature was deactivated.'));
202
- }
203
- $this->_redirect('adminhtml/sales_order/', array());
204
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  }
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_IndexController extends Mage_Adminhtml_Sales_OrderController
10
  {
11
+ protected function _construct()
12
+ {
13
+ $this->setUsedModuleName('Asperience_DeleteAllOrders');
14
+ }
15
+ /**
16
+ * Delete selected orders
17
+ */
18
+ public function indexAction()
19
+ {
20
+ // Get orders to delete in grid
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;
29
+ $ordersDelete = $invoicesDelete = $creditsDelete = $shipmentsDelete = array();
30
+ $ordersGridDelete = $invoicesGridDelete = $creditsGridDelete = $shipmentsGridDelete = array();
31
+ $taxesDelete = array();
32
+ $quotesDelete = array();
33
+ $ordersUndelete = array();
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++;
100
+ }
101
+ }
102
+ // Delete order
103
+ $order = Mage::getModel('sales/order')->load($orderId);
104
+ $ordersDelete[] = $order->getIncrementId();
105
+ $quoteId = $order->getQuoteId();
106
+ $order->delete();
107
+ $nbDelOrder++;
108
+ } else {
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()));
125
+ $nbDelInvoiceGrid++;
126
+ }
127
 
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()));
136
+ $nbDelShipmentGrid++;
137
+ }
138
+
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
+ }
149
 
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){
201
+ $this->_getSession()->addError(
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
281
+ $this->_getSession()->addError($this->__('This feature was deactivated.'));
282
+ }
283
+ $this->_redirect('adminhtml/sales_order/', array());
284
+ }
285
  }
app/code/community/Asperience/DeleteAllOrders/etc/config.xml CHANGED
@@ -8,64 +8,72 @@
8
  */
9
  -->
10
  <config>
11
- <modules>
12
- <Asperience_DeleteAllOrders>
13
- <version>0.2.3</version>
14
- </Asperience_DeleteAllOrders>
15
- </modules>
16
 
17
- <global>
18
- <helpers>
19
  <deleteallorders>
20
  <class>Asperience_DeleteAllOrders_Helper</class>
21
  </deleteallorders>
22
  </helpers>
23
- <models>
24
- <deleteallorders>
25
- <class>Asperience_DeleteAllOrders_Model</class>
26
- </deleteallorders>
27
- </models>
28
- </global>
29
-
30
- <admin>
31
- <routers>
32
- <asperience_deleteallorders>
33
- <use>admin</use>
34
- <args>
35
- <module>Asperience_DeleteAllOrders</module>
36
- <frontName>deleteallorders</frontName>
37
- </args>
38
- </asperience_deleteallorders>
39
- </routers>
40
- </admin>
 
 
 
 
 
 
 
 
41
 
42
  <adminhtml>
43
- <acl>
44
- <resources>
45
- <all>
46
- <title>Allow delete</title>
47
- </all>
48
- <admin>
49
- <children>
50
- <sales>
51
- <children>
52
- <order>
53
- <children>
54
- <actions>
55
- <children>
56
- <delete>
57
- <title>Delete Orders</title>
58
- </delete>
59
- </children>
60
- </actions>
61
- </children>
62
- </order>
63
- </children>
64
- </sales>
65
- </children>
66
- </admin>
67
- </resources>
68
- </acl>
69
  <translate>
70
  <modules>
71
  <Asperience_DeleteOrders>
@@ -76,11 +84,7 @@
76
  </modules>
77
  </translate>
78
  <events>
79
- <!-- A tester :
80
- controller_action_layout_render_before_adminhtml_sales_order_index
81
- controller_action_postdispatch_adminhtml_sales_order_index
82
- -->
83
- <adminhtml_block_html_before>
84
  <observers>
85
  <asperience_deleteallorders>
86
  <class>deleteallorders/observer</class>
@@ -88,7 +92,7 @@
88
  </asperience_deleteallorders>
89
  </observers>
90
  </adminhtml_block_html_before>
91
- </events>
92
  </adminhtml>
93
 
94
  <default>
8
  */
9
  -->
10
  <config>
11
+ <modules>
12
+ <Asperience_DeleteAllOrders>
13
+ <version>0.2.4</version>
14
+ </Asperience_DeleteAllOrders>
15
+ </modules>
16
 
17
+ <global>
18
+ <helpers>
19
  <deleteallorders>
20
  <class>Asperience_DeleteAllOrders_Helper</class>
21
  </deleteallorders>
22
  </helpers>
23
+ <models>
24
+ <deleteallorders>
25
+ <class>Asperience_DeleteAllOrders_Model</class>
26
+ </deleteallorders>
27
+ </models>
28
+ <resources>
29
+ <asperience_deleteallorders_setup>
30
+ <setup>
31
+ <module>Asperience_DeleteAllOrders</module>
32
+ <class>Asperience_DeleteAllOrders_Model_Resource_Setup</class>
33
+ </setup>
34
+ </asperience_deleteallorders_setup>
35
+ </resources>
36
+ </global>
37
+
38
+ <admin>
39
+ <routers>
40
+ <asperience_deleteallorders>
41
+ <use>admin</use>
42
+ <args>
43
+ <module>Asperience_DeleteAllOrders</module>
44
+ <frontName>deleteallorders</frontName>
45
+ </args>
46
+ </asperience_deleteallorders>
47
+ </routers>
48
+ </admin>
49
 
50
  <adminhtml>
51
+ <acl>
52
+ <resources>
53
+ <all>
54
+ <title>Allow delete</title>
55
+ </all>
56
+ <admin>
57
+ <children>
58
+ <sales>
59
+ <children>
60
+ <order>
61
+ <children>
62
+ <actions>
63
+ <children>
64
+ <delete>
65
+ <title>Delete Orders</title>
66
+ </delete>
67
+ </children>
68
+ </actions>
69
+ </children>
70
+ </order>
71
+ </children>
72
+ </sales>
73
+ </children>
74
+ </admin>
75
+ </resources>
76
+ </acl>
77
  <translate>
78
  <modules>
79
  <Asperience_DeleteOrders>
84
  </modules>
85
  </translate>
86
  <events>
87
+ <adminhtml_block_html_before>
 
 
 
 
88
  <observers>
89
  <asperience_deleteallorders>
90
  <class>deleteallorders/observer</class>
92
  </asperience_deleteallorders>
93
  </observers>
94
  </adminhtml_block_html_before>
95
+ </events>
96
  </adminhtml>
97
 
98
  <default>
app/code/community/Asperience/DeleteAllOrders/sql/asperience_deleteallorders_setup/mysql4-install-0.2.4.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //Module page: http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html\n
9
+
10
+ Mage::log("Running This Install: ");
11
+ Mage::log(get_class($this));
12
+
13
+ Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
14
+ (
15
+ "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
16
+ "Do not forget to add the pending status if needed.",
17
+ "This module is provided by ASPerience (http://www.asperience.fr/)"
18
+ );
19
+
20
+ // $installer = $this;
21
+ // $installer->startSetup();
22
+ // Mage::log("install message");
23
+ // Mage::getModel('adminnotification/inbox')
24
+ // ->setTitle("Thanks for installing Asperience_DeleteAllOrders")
25
+ // ->setDescription("In Magento, you can't natively delete orders.\n
26
+ // Asperience_DeleteAllOrders allows to delete : \n
27
+ // 1) selected sales orders without any invoice/shipment/credit memo => level 1\n
28
+ // 2) selected sales orders and linked invoices, shipments and credit memos => level 2\n
29
+ // You can set the status of orders you want to delete in the configuration panel.\n
30
+ // \n
31
+ // Warning: It's preferable to delete only the testing orders during the development of your local website.You take risks if you delete orders directly in your Website.\n
32
+ // \n
33
+ // Configuration panel: System - Configuration - Sales - Deletion of Orders")
34
+ // ->setUrl("http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html")
35
+ // ->setSeverity(Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE)
36
+ // //->setSeverity(4)
37
+ // ->setDateAdded(Mage::getModel('core/date')->gmtDate())
38
+ // ->save();
39
+ // Mage::getModel('test')->save();
40
+ // $installer->endSetup();
41
+
42
+ ?>
app/code/community/Asperience/DeleteAllOrders/sql/asperience_deleteallorders_setup/mysql4-upgrade-0.2.3-0.2.4.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Module page: http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html")
9
+
10
+ Mage::log("Running This Upgrade: ");
11
+ Mage::log(get_class($this));
12
+
13
+ Mage::helper('asperience_notificationmanager/Data')->createAdminNotification
14
+ (
15
+ "To finish the configuration please go in Magento Admin Panel - System - Configuration - Sales - Deletion of Orders",
16
+ "Do not forget to add the pending status if needed.",
17
+ "This module is provided by ASPerience (http://www.asperience.fr/)"
18
+ );
19
+
20
+ //$installer = $this;
21
+ //$installer->startSetup();
22
+ //Mage::getModel('adminnotification/inbox')
23
+ // ->setTitle("Thanks for upgrading Asperience_DeleteAllOrders")
24
+ // ->setDescription("Configuration panel: System - Configuration - Sales - Deletion of Orders\n
25
+ // //->setUrl("/index.php/admin/system_config/edit/section/sale")
26
+ // ->setUrl("http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html")
27
+ // //->setSeverity(Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE)
28
+ // ->setSeverity(4)
29
+ // ->setDateAdded(Mage::getModel('core/date')->gmtDate())
30
+ // ->save();
31
+ // Mage::getModel('test')->save();
32
+ // $installer->endSetup();
33
+
34
+ ?>
app/etc/modules/Asperience_DeleteAllOrders.xml CHANGED
@@ -12,6 +12,9 @@
12
  <Asperience_DeleteAllOrders>
13
  <active>true</active>
14
  <codePool>community</codePool>
 
 
 
15
  </Asperience_DeleteAllOrders>
16
  </modules>
17
  </config>
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>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Asperience_DeleteAllOrders</name>
4
- <version>0.2.3</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>
@@ -12,9 +12,9 @@ You can set the status of orders you want to delete in the configuration section
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-01-31</date>
16
- <time>13:37:13</time>
17
- <contents><target name="magecommunity"><dir name="Asperience"><dir name="DeleteAllOrders"><dir name="Helper"><file name="Data.php" hash="747caa90dd55fd313f5aa0a642f89b28"/></dir><dir name="Model"><file name="Observer.php" hash="9c11ed2bbc7bc2e8e2e41c0247c4bed8"/><file name="Order.php" hash="f6372db58a485c14fecf55fc3c676888"/><file name="Status.php" hash="619a4803a34efe0f82378af8f42bb7db"/></dir><dir name="controllers"><file name="IndexController.php" hash="cf9d63f67ef2a8411e0cc45fbd42476c"/></dir><dir name="etc"><file name="config.xml" hash="e5e6f36c5a0141f316a2514f8c5e6693"/><file name="system.xml" hash="a6ffdfefc94437bd6bf45453549aa389"/></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="564d484d06362fee6d4f0b42660bfa85"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Asperience_DeleteAllOrders</name>
4
+ <version>0.2.4</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>
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-25</date>
16
+ <time>17:39:09</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="1f4b9de6842f08da284420afa7e40815"/><file name="system.xml" hash="a6ffdfefc94437bd6bf45453549aa389"/></dir><dir name="sql"><dir name="asperience_deleteallorders_setup"><file name="mysql4-install-0.2.4.php" hash="23a2a6e1055360699fc2e2ab6e08632d"/><file name="mysql4-upgrade-0.2.3-0.2.4.php" hash="58627dc9ad7570ea50b82c537cbde4c5"/></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></required></dependencies>
20
  </package>