Asperience_DeleteAllOrders - Version 0.2.0

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.0
Comparing to
See all releases


Code changes from version 0.1.9 to 0.2.0

app/code/community/Asperience/DeleteAllOrders/Model/Observer.php CHANGED
@@ -18,7 +18,7 @@ class Asperience_DeleteAllOrders_Model_Observer
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)) {
22
  if(Mage::getStoreConfig(self::XML_PATH_SALES_DELETE_ALL)) {
23
  $massBlock->addItem('delete_order', array(
24
  'label'=> Mage::helper('deleteallorders')->__('Delete All !'),
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 !'),
app/code/community/Asperience/DeleteAllOrders/Model/Order.php CHANGED
@@ -20,6 +20,8 @@ class Asperience_DeleteAllOrders_Model_Order extends Mage_Sales_Model_Order
20
 
21
  public function hasAvalaibleStatus()
22
  {
 
 
23
  return (in_array($this->getStatus(), $this->getDeleteStatusIds()));
24
  }
25
 
20
 
21
  public function hasAvalaibleStatus()
22
  {
23
+ Mage::log($this->getStatus());
24
+ Mage::log($this->getDeleteStatusIds());
25
  return (in_array($this->getStatus(), $this->getDeleteStatusIds()));
26
  }
27
 
app/code/community/Asperience/DeleteAllOrders/Model/Status.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Order Statuses source model
10
+ */
11
+ class Asperience_DeleteAllOrders_Model_Status
12
+ {
13
+
14
+ public function toOptionArray()
15
+ {
16
+ $statuses = Mage::getSingleton('sales/order_config')->getStatuses();
17
+ $options = array();
18
+ $options[] = array(
19
+ 'value' => '',
20
+ 'label' => Mage::helper('adminhtml')->__('-- Please Select --')
21
+ );
22
+ foreach ($statuses as $code=>$label) {
23
+ $options[] = array(
24
+ 'value' => $code,
25
+ 'label' => $label
26
+ );
27
+ }
28
+ return $options;
29
+ }
30
+ }
app/code/community/Asperience/DeleteAllOrders/controllers/IndexController.php CHANGED
@@ -22,11 +22,24 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
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
  $countDeleteInvoice = 0;
 
 
26
  $countDeleteShipment = 0;
 
 
27
  $countDeleteCreditmemo = 0;
28
-
 
 
 
 
 
 
29
  try {
 
30
  foreach ($orderIds as $orderId) {
31
  $order = Mage::getModel('deleteallorders/order')->load($orderId);
32
  if ($order->canDelete()) {
@@ -34,46 +47,109 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
34
  if ($order->hasInvoices()) {
35
  $invoices = Mage::getResourceModel('sales/order_invoice_collection')->setOrderFilter($orderId)->load();
36
  foreach($invoices as $invoice){
37
- $invoice = Mage::getModel('sales/order_invoice')->load($invoice->getId());
38
- $invoice->delete();
 
 
39
  $countDeleteInvoice++;
 
 
 
 
 
 
 
 
 
40
  }
41
  }
42
 
43
  if ($order->hasShipments()) {
44
  $shipments = Mage::getResourceModel('sales/order_shipment_collection')->setOrderFilter($orderId)->load();
45
  foreach($shipments as $shipment){
46
- $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getId());
47
- $shipment->delete();
 
 
48
  $countDeleteShipment++;
 
 
 
 
 
 
 
 
49
  }
50
  }
51
 
52
  if ($order->hasCreditmemos()) {
53
  $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')->setOrderFilter($orderId)->load();
54
  foreach($creditmemos as $creditmemo){
55
- $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemo->getId());
56
- $creditmemo->delete();
 
 
57
  $countDeleteCreditmemo++;
 
 
 
 
 
 
 
 
58
  }
59
  }
60
-
61
- $order->delete();
 
62
  $countDeleteOrder++;
63
- }
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
  if ($countDeleteOrder > 0) {
67
  $this->_getSession()->addSuccess($this->__('%s sale(s) order(s) was/were successfully deleted.', $countDeleteOrder));
 
 
 
 
68
  if ($countDeleteInvoice > 0) {
69
  $this->_getSession()->addSuccess($this->__('%s invoice(s) order(s) was/were successfully deleted.', $countDeleteInvoice));
 
70
  }
 
 
 
71
  if ($countDeleteShipment > 0) {
72
  $this->_getSession()->addSuccess($this->__('%s shipment(s) order(s) was/were successfully deleted.', $countDeleteShipment));
 
73
  }
 
 
 
74
  if ($countDeleteCreditmemo > 0) {
75
  $this->_getSession()->addSuccess($this->__('%s credit memo(s) order(s) was/were successfully deleted.', $countDeleteCreditmemo));
 
76
  }
 
 
 
 
 
 
 
 
77
  } else {
78
  $this->_getSession()->addError($this->__('Selected order(s) can not be deleted.'));
79
  }
@@ -85,4 +161,4 @@ class Asperience_DeleteAllOrders_IndexController extends Mage_Adminhtml_Sales_Or
85
  }
86
  $this->_redirect('adminhtml/sales_order/', array());
87
  }
88
- }
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
+ $orders_delete = array();
37
+ $invoices_delete = array();
38
+ $creditmemos_delete = array();
39
+ $shipments_delete = array();
40
+ $orders_undelete = array();
41
  try {
42
+ Mage::log($orderIds);
43
  foreach ($orderIds as $orderId) {
44
  $order = Mage::getModel('deleteallorders/order')->load($orderId);
45
  if ($order->canDelete()) {
47
  if ($order->hasInvoices()) {
48
  $invoices = Mage::getResourceModel('sales/order_invoice_collection')->setOrderFilter($orderId)->load();
49
  foreach($invoices as $invoice){
50
+ $id = $invoice->getId();
51
+ $invoice = Mage::getModel('sales/order_invoice')->load($id);
52
+ $invoices_delete[] = $invoice->getIncrementId();
53
+ //$invoice->delete();
54
  $countDeleteInvoice++;
55
+ /*try {
56
+ Mage::log(get_class(Mage::getModel('sales/order_invoice_grid_collection')));
57
+ $invoice = Mage::getModel('sales/order_invoice_grid')->load($id);
58
+ $invoice->delete();
59
+ $countDeleteInvoiceGrid++;
60
+ } catch (Exception $e){
61
+ Mage::log($e->getMessage());
62
+ $countDeleteInvoiceGridException++;
63
+ }*/
64
  }
65
  }
66
 
67
  if ($order->hasShipments()) {
68
  $shipments = Mage::getResourceModel('sales/order_shipment_collection')->setOrderFilter($orderId)->load();
69
  foreach($shipments as $shipment){
70
+ $id = $shipment->getId();
71
+ $shipment = Mage::getModel('sales/order_shipment')->load($id);
72
+ $shipments_delete[] = $shipment->getIncrementId();
73
+ //$shipment->delete();
74
  $countDeleteShipment++;
75
+ /*try {
76
+ $shipment = Mage::getModel('sales/order_shipment_grid')->load($id);
77
+ $shipment->delete();
78
+ $countDeleteShipmentGrid++;
79
+ } catch (Exception $e){
80
+ Mage::log($e->getMessage());
81
+ $countDeleteShipmentGridException++;
82
+ }*/
83
  }
84
  }
85
 
86
  if ($order->hasCreditmemos()) {
87
  $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')->setOrderFilter($orderId)->load();
88
  foreach($creditmemos as $creditmemo){
89
+ $id = $creditmemo->getId();
90
+ $creditmemo = Mage::getModel('sales/order_creditmemo')->load($id);
91
+ $creditmemos_delete[] = $creditmemo->getIncrementId();
92
+ //$creditmemo->delete();
93
  $countDeleteCreditmemo++;
94
+ /*try {
95
+ $creditmemo = Mage::getModel('sales/order_creditmemo_grid')->load($id);
96
+ $creditmemo->delete();
97
+ $countDeleteCreditmemoGrid++;
98
+ } catch (Exception $e){
99
+ Mage::log($e->getMessage());
100
+ $countDeleteCreditmemoGridException++;
101
+ }*/
102
  }
103
  }
104
+ $order = Mage::getModel('sales/order')->load($orderId);
105
+ $orders_delete[] = $order->getIncrementId();
106
+ //$order->delete();
107
  $countDeleteOrder++;
108
+ /*try {
109
+ $order = Mage::getModel('sales/order_grid')->load($orderId);
110
+ $order->delete();
111
+ $countDeleteOrderGrid++;
112
+ } catch (Exception $e){
113
+ Mage::log($e->getMessage());
114
+ $countDeleteOrderGridException++;
115
+ }*/
116
+ } else {
117
+ $orders_undelete[] = Mage::getModel('sales/order')->load($orderId)->getIncrementId();
118
+ }
119
  }
120
 
121
  if ($countDeleteOrder > 0) {
122
  $this->_getSession()->addSuccess($this->__('%s sale(s) order(s) was/were successfully deleted.', $countDeleteOrder));
123
+ $this->_getSession()->addSuccess(implode(" ",$orders_delete));
124
+ /*if ($countDeleteOrderGrid > 0) {
125
+ $this->_getSession()->addSuccess($this->__('%s sale(s) order(s) was/were successfully deleted in grid.', $countDeleteOrderGrid));
126
+ }*/
127
  if ($countDeleteInvoice > 0) {
128
  $this->_getSession()->addSuccess($this->__('%s invoice(s) order(s) was/were successfully deleted.', $countDeleteInvoice));
129
+ $this->_getSession()->addSuccess(implode(" ",$invoices_delete));
130
  }
131
+ /*if ($countDeleteInvoiceGrid > 0) {
132
+ $this->_getSession()->addSuccess($this->__('%s invoice(s) order(s) was/were successfully deleted in grid.', $countDeleteInvoiceGrid));
133
+ }*/
134
  if ($countDeleteShipment > 0) {
135
  $this->_getSession()->addSuccess($this->__('%s shipment(s) order(s) was/were successfully deleted.', $countDeleteShipment));
136
+ $this->_getSession()->addSuccess(implode(" ",$shipments_delete));
137
  }
138
+ /*if ($countDeleteShipmentGrid > 0) {
139
+ $this->_getSession()->addSuccess($this->__('%s shipment(s) order(s) was/were successfully deleted in grid.', $countDeleteShipmentGrid));
140
+ }*/
141
  if ($countDeleteCreditmemo > 0) {
142
  $this->_getSession()->addSuccess($this->__('%s credit memo(s) order(s) was/were successfully deleted.', $countDeleteCreditmemo));
143
+ $this->_getSession()->addSuccess(implode(" ",$creditmemos_delete));
144
  }
145
+ /*if ($countDeleteCreditmemoGrid > 0) {
146
+ $this->_getSession()->addSuccess($this->__('%s credit memo(s) order(s) was/were successfully deleted in grid.', $countDeleteCreditmemoGrid));
147
+ }*/
148
+ Mage::log($orders_undelete);
149
+ if(count($orders_undelete) > 0) {
150
+ $this->_getSession()->addWarning($this->__('Selected order(s) can not be deleted:').implode(" ",$orders_undelete));
151
+ }
152
+
153
  } else {
154
  $this->_getSession()->addError($this->__('Selected order(s) can not be deleted.'));
155
  }
161
  }
162
  $this->_redirect('adminhtml/sales_order/', array());
163
  }
164
+ }
app/code/community/Asperience/DeleteAllOrders/etc/config.xml CHANGED
@@ -10,7 +10,7 @@
10
  <config>
11
  <modules>
12
  <Asperience_DeleteAllOrders>
13
- <version>0.1.9</version>
14
  </Asperience_DeleteAllOrders>
15
  </modules>
16
 
@@ -40,6 +40,32 @@
40
  </admin>
41
 
42
  <adminhtml>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  <translate>
44
  <modules>
45
  <Asperience_DeleteOrders>
@@ -74,4 +100,4 @@
74
  </delete_order>
75
  </sales>
76
  </default>
77
- </config>
10
  <config>
11
  <modules>
12
  <Asperience_DeleteAllOrders>
13
+ <version>0.2.2</version>
14
  </Asperience_DeleteAllOrders>
15
  </modules>
16
 
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>
100
  </delete_order>
101
  </sales>
102
  </default>
103
+ </config>
app/code/community/Asperience/DeleteAllOrders/etc/system.xml CHANGED
@@ -40,10 +40,10 @@
40
  <order_status translate="label">
41
  <label>Delete order status</label>
42
  <frontend_type>multiselect</frontend_type>
43
- <source_model>adminhtml/system_config_source_order_status</source_model>
44
  <sort_order>3</sort_order>
45
  <show_in_default>1</show_in_default>
46
- <show_in_website>01</show_in_website>
47
  <show_in_store>0</show_in_store>
48
  </order_status>
49
  </fields>
@@ -51,4 +51,4 @@
51
  </groups>
52
  </sales>
53
  </sections>
54
- </config>
40
  <order_status translate="label">
41
  <label>Delete order status</label>
42
  <frontend_type>multiselect</frontend_type>
43
+ <source_model>deleteallorders/status</source_model>
44
  <sort_order>3</sort_order>
45
  <show_in_default>1</show_in_default>
46
+ <show_in_website>0</show_in_website>
47
  <show_in_store>0</show_in_store>
48
  </order_status>
49
  </fields>
51
  </groups>
52
  </sales>
53
  </sections>
54
+ </config>
app/locale/fr_FR/Asperience_DeleteAllOrders.csv CHANGED
@@ -11,4 +11,5 @@
11
  "Allow to delete the orders","Permettre de supprimer les commandes"
12
  "Deletion of Orders","Suppression des commandes"
13
  "Delete order status","Statuts des commandes supprimables"
14
- "Also remove orders with invoices, shipments or credit memos related","Supprimer aussi les commandes avec des factures, expéditions ou remboursements liés"
 
11
  "Allow to delete the orders","Permettre de supprimer les commandes"
12
  "Deletion of Orders","Suppression des commandes"
13
  "Delete order status","Statuts des commandes supprimables"
14
+ "Also remove orders with invoices, shipments or credit memos related","Supprimer aussi les commandes avec des factures, expéditions ou remboursements liés"
15
+ "Selected order(s) can not be deleted:","Les commandes suivantes ne peuvent être supprimées:"
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Asperience_DeleteAllOrders</name>
4
- <version>0.1.9</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>2012-06-01</date>
16
- <time>22:01:35</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="ae9890811c2411ebe791bc3dce72d6c0"/><file name="Order.php" hash="f6372db58a485c14fecf55fc3c676888"/></dir><dir name="controllers"><file name="IndexController.php" hash="c496b80e6cee4c19cdce016ecbfb3e6e"/></dir><dir name="etc"><file name="config.xml" hash="6eb50b102037c865253184eba7cb7dc0"/><file name="system.xml" hash="02f4c05514bc9b3f1c92cce9e2c16681"/></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="8334e497eb99d7496ab770e5311ef70e"/></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.0</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>2013-04-18</date>
16
+ <time>01:18:24</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="ddec94fe82a280cb3e7d8cf082c50861"/><file name="Status.php" hash="619a4803a34efe0f82378af8f42bb7db"/></dir><dir name="controllers"><file name="IndexController.php" hash="1a91dc41e50f4b7fcf514db048aa6cb3"/></dir><dir name="etc"><file name="config.xml" hash="bd613021b1d909599ea8b2296b5d5f8b"/><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>