Wyomind_Delete_Orders - Version 1.0.2

Version Notes

none

Download this release

Release Info

Developer Magento Core Team
Extension Wyomind_Delete_Orders
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

app/code/local/Wyomind/DeleteOrders/Block/Grid.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_DeleteOrders_Block_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('sales_order_grid');
10
+ $this->setUseAjax(true);
11
+ $this->setDefaultSort('created_at');
12
+ $this->setDefaultDir('DESC');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ protected function _prepareCollection()
17
+ {
18
+ //TODO: add full name logic
19
+ $collection = Mage::getResourceModel('sales/order_collection')
20
+ ->addAttributeToSelect('*')
21
+ ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
22
+ ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
23
+ ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
24
+ ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
25
+ ->addExpressionAttributeToSelect('billing_name',
26
+ 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
27
+ array('billing_firstname', 'billing_lastname'))
28
+ ->addExpressionAttributeToSelect('shipping_name',
29
+ 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
30
+ array('shipping_firstname', 'shipping_lastname'));
31
+ $this->setCollection($collection);
32
+ return parent::_prepareCollection();
33
+ }
34
+
35
+ protected function _prepareColumns()
36
+ {
37
+
38
+ $this->addColumn('real_order_id', array(
39
+ 'header'=> Mage::helper('sales')->__('Order #'),
40
+ 'width' => '80px',
41
+ 'type' => 'text',
42
+ 'index' => 'increment_id',
43
+ ));
44
+
45
+ if (!Mage::app()->isSingleStoreMode()) {
46
+ $this->addColumn('store_id', array(
47
+ 'header' => Mage::helper('sales')->__('Purchased from (store)'),
48
+ 'index' => 'store_id',
49
+ 'type' => 'store',
50
+ 'store_view'=> true,
51
+ 'display_deleted' => true,
52
+ ));
53
+ }
54
+
55
+ $this->addColumn('created_at', array(
56
+ 'header' => Mage::helper('sales')->__('Purchased On'),
57
+ 'index' => 'created_at',
58
+ 'type' => 'datetime',
59
+ 'width' => '100px',
60
+ ));
61
+
62
+ /*$this->addColumn('billing_firstname', array(
63
+ 'header' => Mage::helper('sales')->__('Bill to First name'),
64
+ 'index' => 'billing_firstname',
65
+ ));
66
+
67
+ $this->addColumn('billing_lastname', array(
68
+ 'header' => Mage::helper('sales')->__('Bill to Last name'),
69
+ 'index' => 'billing_lastname',
70
+ ));*/
71
+ $this->addColumn('billing_name', array(
72
+ 'header' => Mage::helper('sales')->__('Bill to Name'),
73
+ 'index' => 'billing_name',
74
+ ));
75
+
76
+ /*$this->addColumn('shipping_firstname', array(
77
+ 'header' => Mage::helper('sales')->__('Ship to First name'),
78
+ 'index' => 'shipping_firstname',
79
+ ));
80
+
81
+ $this->addColumn('shipping_lastname', array(
82
+ 'header' => Mage::helper('sales')->__('Ship to Last name'),
83
+ 'index' => 'shipping_lastname',
84
+ ));*/
85
+ $this->addColumn('shipping_name', array(
86
+ 'header' => Mage::helper('sales')->__('Ship to Name'),
87
+ 'index' => 'shipping_name',
88
+ ));
89
+
90
+ $this->addColumn('base_grand_total', array(
91
+ 'header' => Mage::helper('sales')->__('G.T. (Base)'),
92
+ 'index' => 'base_grand_total',
93
+ 'type' => 'currency',
94
+ 'currency' => 'base_currency_code',
95
+ ));
96
+
97
+ $this->addColumn('grand_total', array(
98
+ 'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
99
+ 'index' => 'grand_total',
100
+ 'type' => 'currency',
101
+ 'currency' => 'order_currency_code',
102
+ ));
103
+
104
+ $this->addColumn('status', array(
105
+ 'header' => Mage::helper('sales')->__('Status'),
106
+ 'index' => 'status',
107
+ 'type' => 'options',
108
+ 'width' => '70px',
109
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
110
+ ));
111
+
112
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
113
+ $this->addColumn('action',
114
+ array(
115
+ 'header' => Mage::helper('sales')->__('Action'),
116
+ 'width' => '50px',
117
+ 'type' => 'action',
118
+ 'getter' => 'getId',
119
+ 'actions' => array(
120
+ array(
121
+ 'caption' => Mage::helper('sales')->__('View'),
122
+ 'url' => array('base'=>'*/*/view'),
123
+ 'field' => 'order_id'
124
+ ),
125
+ array(
126
+ 'caption' => Mage::helper('sales')->__('Delete'),
127
+ 'url' => array('base'=>'deleteorders/adminhtml_order/delete'),
128
+ 'confirm' => Mage::helper('sales')->__('Are your sure your want to delete this order and to erase all linked data ? '),
129
+ 'field' => 'order_id'
130
+ )
131
+ ),
132
+ 'filter' => false,
133
+ 'sortable' => false,
134
+ 'index' => 'stores',
135
+ 'is_system' => true,
136
+ ));
137
+ }
138
+ $this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
139
+
140
+ return parent::_prepareColumns();
141
+ }
142
+
143
+ protected function _prepareMassaction()
144
+ {
145
+ $this->setMassactionIdField('entity_id');
146
+ $this->getMassactionBlock()->setFormFieldName('order_ids');
147
+
148
+ $this->getMassactionBlock()->addItem('delete_order', array(
149
+ 'label'=> Mage::helper('sales')->__('Delete'),
150
+ 'url' => $this->getUrl('deleteorders/adminhtml_order/massdelete'),
151
+ ));
152
+
153
+
154
+ $this->getMassactionBlock()->addItem('cancel_order', array(
155
+ 'label'=> Mage::helper('sales')->__('Cancel'),
156
+ 'url' => $this->getUrl('*/*/massCancel'),
157
+ ));
158
+
159
+ $this->getMassactionBlock()->addItem('hold_order', array(
160
+ 'label'=> Mage::helper('sales')->__('Hold'),
161
+ 'url' => $this->getUrl('*/*/massHold'),
162
+ ));
163
+
164
+ $this->getMassactionBlock()->addItem('unhold_order', array(
165
+ 'label'=> Mage::helper('sales')->__('Unhold'),
166
+ 'url' => $this->getUrl('*/*/massUnhold'),
167
+ ));
168
+
169
+ $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
170
+ 'label'=> Mage::helper('sales')->__('Print Invoices'),
171
+ 'url' => $this->getUrl('*/*/pdfinvoices'),
172
+ ));
173
+
174
+ $this->getMassactionBlock()->addItem('pdfshipments_order', array(
175
+ 'label'=> Mage::helper('sales')->__('Print Packingslips'),
176
+ 'url' => $this->getUrl('*/*/pdfshipments'),
177
+ ));
178
+
179
+ $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
180
+ 'label'=> Mage::helper('sales')->__('Print Credit Memos'),
181
+ 'url' => $this->getUrl('*/*/pdfcreditmemos'),
182
+ ));
183
+
184
+ $this->getMassactionBlock()->addItem('pdfdocs_order', array(
185
+ 'label'=> Mage::helper('sales')->__('Print All'),
186
+ 'url' => $this->getUrl('*/*/pdfdocs'),
187
+ ));
188
+
189
+ // $statuses = Mage::getSingleton('sales/order_config')->getStatuses();
190
+ // array_unshift($statuses, array('value'=>'', 'label'=>''));
191
+ // $this->getMassactionBlock()->addItem('change_status', array(
192
+ // 'label'=> Mage::helper('sales')->__('Change Status'),
193
+ // 'url' => $this->getUrl('*/*/massStatus'),
194
+ // 'additional' => array(
195
+ // 'visibility' => array(
196
+ // 'name' => 'status',
197
+ // 'type' => 'select',
198
+ // 'class' => 'required-entry',
199
+ // 'label' => Mage::helper('sales')->__('New Status'),
200
+ // 'values' => $statuses
201
+ // )
202
+ // )
203
+ // ));
204
+
205
+ // $prints = array(
206
+ // 'empty' => array('value'=>'', 'label'=>''),
207
+ // 'order' => Mage::helper('sales')->__('Orders'),
208
+ // 'invoice' => Mage::helper('sales')->__('Invoices'),
209
+ // 'shipment' => Mage::helper('sales')->__('Shipments'),
210
+ // );
211
+ // $this->getMassactionBlock()->addItem('print', array(
212
+ // 'label'=> Mage::helper('sales')->__('Print'),
213
+ // 'url' => $this->getUrl('*/*/massPrint'),
214
+ // 'additional' => array(
215
+ // 'visibility' => array(
216
+ // 'name' => 'document',
217
+ // 'type' => 'select',
218
+ // 'class' => 'required-entry',
219
+ // 'label' => Mage::helper('sales')->__('Document'),
220
+ // 'values' => $prints
221
+ // )
222
+ // )
223
+ // ));
224
+
225
+ return $this;
226
+ }
227
+
228
+ public function getRowUrl($row)
229
+ {
230
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
231
+ return $this->getUrl('*/*/view', array('order_id' => $row->getId()));
232
+ }
233
+ return false;
234
+ }
235
+
236
+ public function getGridUrl()
237
+ {
238
+ return $this->getUrl('*/*/grid', array('_current'=>true));
239
+ }
240
+
241
+ }
app/code/local/Wyomind/DeleteOrders/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wyomind_DeleteOrders_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Wyomind/DeleteOrders/Model/Erase.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Wyomind_DeleteOrders_Model_Erase extends Varien_Object{
5
+
6
+ public function _erase($orderId){
7
+
8
+ $resource = Mage::getSingleton('core/resource');
9
+ $delete= $resource->getConnection('core_read');
10
+ $tableSo = $resource->getTableName('sales_order');
11
+ $tableSoe = $resource->getTableName('sales_order_entity');
12
+ $tableSoei = $resource->getTableName('sales_order_entity_int');
13
+ $tableEa = $resource->getTableName('eav_attribute');
14
+ $tableSfoi = $resource->getTableName('sales_flat_order_item');
15
+
16
+ $sql= "DELETE FROM ".$tableSo." WHERE entity_id = ".$orderId.";";
17
+ $delete->query($sql);
18
+ $sql="DELETE FROM ".$tableSoe." WHERE parent_id = ".$orderId.";";
19
+ $delete->query($sql);
20
+ $sql="DELETE s FROM ".$tableSoe." s
21
+ JOIN ".$tableSoei." si on s.entity_id = si.entity_id
22
+ JOIN ".$tableEa." a on si.attribute_id = a.attribute_id
23
+ WHERE a.attribute_code = 'order_id'
24
+ AND si.value = ".$orderId.";";
25
+ $delete->query($sql);
26
+ $sql="DELETE FROM ".$tableSfoi." WHERE order_id=".$orderId.";";
27
+ $delete->query($sql);
28
+ return true;
29
+ }
30
+
31
+
32
+ }
33
+
app/code/local/Wyomind/DeleteOrders/controllers/adminhtml/OrderController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Wyomind_DeleteOrders_adminhtml_OrderController extends Mage_Adminhtml_Controller_action
3
+ {
4
+ protected function _initOrder()
5
+ {
6
+ $id = $this->getRequest()->getParam('order_id');
7
+ $order = Mage::getModel('sales/order')->load($id);
8
+
9
+ if (!$order->getId()) {
10
+ $this->_getSession()->addError($this->__('This order no longer exists.'));
11
+ $this->_redirect('adminhtml/sales_order/');
12
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
13
+ return false;
14
+ }
15
+ Mage::register('sales_order', $order);
16
+ Mage::register('current_order', $order);
17
+ return $order;
18
+ }
19
+
20
+ public function massDeleteAction()
21
+ {
22
+
23
+ $orderIds = $this->getRequest()->getPost('order_ids', array());
24
+
25
+
26
+ $countDeleteOrder = 0;
27
+ foreach ($orderIds as $orderId) {
28
+
29
+ if (Mage::getModel('deleteorders/erase')->_erase($orderId)) {
30
+ $countDeleteOrder++;
31
+ }
32
+ }
33
+ if ($countDeleteOrder>0) {
34
+ $this->_getSession()->addSuccess($this->__('%s order(s) successfully deleted', $countDeleteOrder));
35
+ }
36
+ else {
37
+
38
+ }
39
+ $this->_redirect('adminhtml/sales_order/');
40
+ }
41
+
42
+ public function deleteAction(){
43
+
44
+ if ($order = $this->_initOrder()) {
45
+
46
+ try {
47
+ Mage::getModel('deleteorders/erase')->_erase($order->getId());
48
+ $this->_getSession()->addSuccess(
49
+ $this->__('Order was successfully deleted.')
50
+ );
51
+ }
52
+ catch (Mage_Core_Exception $e) {
53
+ $this->_getSession()->addError($e->getMessage());
54
+ }
55
+ catch (Exception $e) {
56
+ $this->_getSession()->addError($this->__('Unable to delete order.'));
57
+ }
58
+ $this->_redirect('adminhtml/sales_order/');
59
+ }
60
+
61
+ }
62
+
63
+ }
app/code/local/Wyomind/DeleteOrders/etc/config.xml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Wyomind
5
+ * @package Wyomind_DeleteOrders
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Wyomind_DeleteOrders>
13
+ <version>1.0.2</version>
14
+ </Wyomind_DeleteOrders>
15
+ </modules>
16
+ <admin>
17
+ <routers>
18
+ <deleteorders>
19
+ <use>admin</use>
20
+ <args>
21
+ <module>Wyomind_DeleteOrders</module>
22
+ <frontName>deleteorders</frontName>
23
+ </args>
24
+ </deleteorders>
25
+ </routers>
26
+ </admin>
27
+ <global>
28
+ <models>
29
+ <deleteorders>
30
+ <class>Wyomind_DeleteOrders_Model</class>
31
+ <resourceModel>deleteorders_mysql4</resourceModel>
32
+ </deleteorders>
33
+ <deleteorders_mysql4>
34
+ <class>Wyomind_DeleteOrders_Model_Mysql4</class>
35
+ <entities>
36
+ <deleteorders>
37
+ <table>deleteorders</table>
38
+ </deleteorders>
39
+ </entities>
40
+ </deleteorders_mysql4>
41
+ </models>
42
+ <blocks>
43
+ <adminhtml>
44
+ <rewrite>
45
+ <sales_order_grid>Wyomind_DeleteOrders_Block_Grid</sales_order_grid>
46
+ </rewrite>
47
+ </adminhtml>
48
+ </blocks>
49
+ <helpers>
50
+ <deleteorders>
51
+ <class>Wyomind_DeleteOrders_Helper</class>
52
+ </deleteorders>
53
+ </helpers>
54
+
55
+
56
+ </global>
57
+
58
+
59
+ </config>
60
+
61
+
62
+
63
+
64
+
65
+
app/etc/modules/Wyomind_DeleteOrders.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Wyomind
5
+ * @package Wyomind_DeleteOrders
6
+ * @author ModuleCreator
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ -->
10
+ <config>
11
+ <modules>
12
+ <Wyomind_DeleteOrders>
13
+ <active>true</active>
14
+ <codePool>local</codePool>
15
+ </Wyomind_DeleteOrders>
16
+ </modules>
17
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Wyomind_Delete_Orders</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Delete Orders add an option in order panel to clean database and to delete old or canceled orders.</summary>
10
+ <description>Delete Orders add an option in order panel to clean database and to delete old or canceled orders.</description>
11
+ <notes>none</notes>
12
+ <authors><author><name>Pierre</name><user>auto-converted</user><email>contact@wyomind.com</email></author></authors>
13
+ <date>2011-03-09</date>
14
+ <time>08:28:21</time>
15
+ <contents><target name="magelocal"><dir name="Wyomind"><dir name="DeleteOrders"><dir name="Block"><file name="Grid.php" hash="6a8080cc1a20eb569b8eed2111de3fa6"/></dir><dir name="controllers"><dir name="adminhtml"><file name="OrderController.php" hash="a3c41bba1516ab90bdcd3d46b85f4115"/></dir></dir><dir name="etc"><file name="config.xml" hash="7551a4192129a2f4229cd8dd94c518c5"/></dir><dir name="Helper"><file name="Data.php" hash="e0e0560c5e57215aee50512e3bd0cc4c"/></dir><dir name="Model"><file name="Erase.php" hash="32a6659394c8f4e3c18dd867fb11ad88"/></dir></dir></dir></target><target name="mage"><dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Wyomind_DeleteOrders.xml" hash="1dd1fdadd5f5e213e48d06c76602ad40"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>