prashant_delete_orders - Version 1.0.0

Version Notes

First Release

Download this release

Release Info

Developer Prashant Kumar
Extension prashant_delete_orders
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Prashant/DeleteOrders/Block/Adminhtml/Sales/Order/Grid.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Prashant_DeleteOrders_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid{
4
+
5
+ protected function _prepareMassaction()
6
+ {
7
+ parent::_prepareMassaction();
8
+
9
+ $this->getMassactionBlock()->addItem('delete_orders', array(
10
+ 'label'=> Mage::helper('sales')->__('Delete Orders'),
11
+ 'url' => $this->getUrl('*/sales_order/deleteMass'),
12
+ ));
13
+
14
+ return $this;
15
+ }
16
+ protected function _prepareColumns()
17
+ {
18
+ parent::_prepareColumns();
19
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
20
+ $this->addColumn('action',
21
+ array(
22
+ 'header' => Mage::helper('sales')->__('Action'),
23
+ 'width' => '50px',
24
+ 'type' => 'action',
25
+ 'getter' => 'getId',
26
+ 'actions' => array(
27
+ array(
28
+ 'caption' => Mage::helper('sales')->__('View'),
29
+ 'url' => array('base'=>'*/sales_order/view'),
30
+ 'field' => 'order_id',
31
+ 'data-column' => 'action',
32
+ ),
33
+ array(
34
+ 'caption' => Mage::helper('sales')->__('Delete'),
35
+ 'url' => array('base'=>'*/sales_order/delete'),
36
+ 'field' => 'order_id',
37
+ 'data-column' => 'action',
38
+ )
39
+ ),
40
+ 'filter' => false,
41
+ 'sortable' => false,
42
+ 'index' => 'stores',
43
+ 'is_system' => true,
44
+ ));
45
+ }
46
+
47
+ return $this;
48
+ }
49
+
50
+ }
app/code/community/Prashant/DeleteOrders/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Prashant_DeleteOrders_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View{
3
+
4
+ public function __construct(){
5
+ parent::__construct();
6
+ $message = Mage::helper('adminhtml')->__('Are you sure you wnat to delete this order?');
7
+ $this->_addButton('button_id', array(
8
+ 'label' => Mage::helper('Sales')->__('Delete Order'),
9
+ 'onclick' => 'deleteConfirm(\''.$message.'\', \'' . $this->getUrl('*/sales_order/delete') . '\')',
10
+ 'class' => 'go'
11
+ ), 0, 100, 'header', 'header');
12
+ }
13
+ }
app/code/community/Prashant/DeleteOrders/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Prashant_DeleteOrders_Helper_Data extends Mage_Core_Helper_Abstract{
3
+
4
+ }
app/code/community/Prashant/DeleteOrders/controllers/Adminhtml/Sales/OrderController.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
3
+ class Prashant_DeleteOrders_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController{
4
+
5
+ /* Function for Delete*/
6
+ public function deleteAction(){
7
+ $order_id = $this->getRequest()->getParam('order_id');
8
+
9
+ if($order_id){
10
+ $order = Mage::getModel('sales/order')->load($order_id);
11
+ try{
12
+ $order->delete()->unsetAll();
13
+ if($this->removeAllData($order_id)){
14
+ $message = Mage::helper('adminhtml')->__('Order was successfully deleted.');
15
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
16
+ $this->_redirectUrl(Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/index'));
17
+ }
18
+ } catch (Exception $e) {
19
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
20
+ $this->_redirectUrl(Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/index'));
21
+ }
22
+ }
23
+
24
+ }
25
+
26
+ public function deleteMassAction(){
27
+ $order_ids = $this->getRequest()->getParam('order_ids');
28
+ if(!is_array($order_ids)){
29
+ $message = Mage::helper('adminhtml')->__('Please select item(s).');
30
+ Mage::getSingleton('adminhtml/session')->addError($message);
31
+ }
32
+ else{
33
+ try{
34
+ foreach($order_ids as $order_id){
35
+ $order = Mage::getModel('sales/order')->load($order_id);
36
+ $order->delete()->unsetAll();
37
+ $this->removeAllData($order_id);
38
+ }
39
+ $message = Mage::helper('adminhtml')->__('Total of %d record(s) were successfully deleted.', count($order_ids));
40
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
41
+
42
+ }catch(Exception $e){
43
+
44
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
45
+ }
46
+
47
+ }
48
+ $this->_redirectUrl(Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/index'));
49
+
50
+ }
51
+
52
+ /* Function Remove All Data*/
53
+ public function removeAllData($order_id){
54
+ $dbResource = Mage::getSingleton('core/resource');
55
+ $db_obj = $dbResource->getConnection('core_read');
56
+ $orderTable = $dbResource->getTableName('sales_flat_order_grid');
57
+ $invoiceTable = $dbResource->getTableName('sales_flat_invoice_grid');
58
+ $shipmentTable = $dbResource->getTableName('sales_flat_shipment_grid');
59
+ $creditmemotab = $dbResource->getTableName('sales_flat_creditmemo_grid');
60
+ $sql = "DELETE FROM " . $orderTable . " WHERE entity_id = " . $order_id . ";";
61
+ $db_obj->query($sql);
62
+ $sql = "DELETE FROM " . $invoiceTable . " WHERE order_id = " . $order_id . ";";
63
+ $db_obj->query($sql);
64
+ $sql = "DELETE FROM " . $shipmentTable . " WHERE order_id = " . $order_id . ";";
65
+ $db_obj->query($sql);
66
+ $sql = "DELETE FROM " . $creditmemotab . " WHERE order_id = " . $order_id . ";";
67
+ $db_obj->query($sql);
68
+ return true;
69
+ }
70
+
71
+ }
app/code/community/Prashant/DeleteOrders/etc/config.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Prashant_DeleteOrders>
5
+ <version>1.0.0</version>
6
+ </Prashant_DeleteOrders>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <deleteorders>
11
+ <class>Prashant_DeleteOrders_Helper</class>
12
+ </deleteorders>
13
+ </helpers>
14
+ <blocks>
15
+ <deleteorders>
16
+ <class>Prashant_DeleteOrders_Block</class>
17
+ </deleteorders>
18
+ <adminhtml>
19
+ <rewrite>
20
+ <sales_order_grid>Prashant_DeleteOrders_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
21
+ <sales_order_view>Prashant_DeleteOrders_Block_Adminhtml_Sales_Order_View</sales_order_view>
22
+ </rewrite>
23
+ </adminhtml>
24
+ </blocks>
25
+ </global>
26
+ <admin>
27
+ <routers>
28
+ <adminhtml>
29
+ <args>
30
+ <modules>
31
+ <prashant_deleteorders before="Mage_Adminhtml">Prashant_DeleteOrders_Adminhtml</prashant_deleteorders>
32
+ </modules>
33
+ </args>
34
+ </adminhtml>
35
+ </routers>
36
+ </admin>
37
+ </config>
app/etc/modules/Prashant_DeleteOrders.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Prashant_DeleteOrders>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Prashant_DeleteOrders>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>prashant_delete_orders</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension allows you to delete orders from admin panel. Easy to delete orders through admin.</summary>
10
+ <description>Magento doesn't allow to delete orders by default. This extension allows you to seamlessly delete any order from admin. You can delete multiple orders. I have also provided options to delete any order from the order list page and order view page.</description>
11
+ <notes>First Release</notes>
12
+ <authors><author><name>Prashant Kumar</name><user>prashantkr</user><email>vicky.bgp@gmail.com</email></author></authors>
13
+ <date>2016-03-16</date>
14
+ <time>20:12:02</time>
15
+ <contents><target name="magecommunity"><dir name="Prashant"><dir name="DeleteOrders"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="7e2028e0f93a74f865839b8c16559642"/><file name="View.php" hash="72a1ab998e84008d5b1d9fde6e485d54"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="90ebd7bdba37eb0b6d5b90162d3399e4"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><file name="OrderController.php" hash="cbb97c91c792f43f2fe28c7e027719ad"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="002ddd4a2aee77fee2e68f75b6ff8082"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Prashant_DeleteOrders.xml" hash="ccc1f048c2a1a7ebc9ffc213a1786c9b"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.1</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>