Magehit_DeleteOrrders - Version 0.1.0

Version Notes

Delete Orders version 0.1.0

Download this release

Release Info

Developer MageHit
Extension Magehit_DeleteOrrders
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Magehit/Deleteorder/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ protected function _initConfig()
5
+ {
6
+ return Mage::getSingleton('deleteorder/config');
7
+ }
8
+
9
+ public function isEnabled(){
10
+ return $this->_initConfig()->isEnabled();
11
+ }
12
+ }
app/code/local/Magehit/Deleteorder/Model/Config.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Model_Config extends Mage_Core_Model_Abstract{
3
+ const XML_GENERAL_ENABLE = 'deleteorder/general/enable';
4
+
5
+ public function isEnabled(){
6
+ return $this->getConfig(self::XML_GENERAL_ENABLE);
7
+ }
8
+
9
+ public function getConfig($name = null){
10
+ if(!$name) return null;
11
+ return Mage::getStoreConfig($name);
12
+ }
13
+ }
app/code/local/Magehit/Deleteorder/Model/Observer.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Model_Observer
3
+ {
4
+ public function core_block_abstract_to_html_before(Varien_Event_Observer $observer)
5
+ {
6
+ if (!Mage::helper('deleteorder')->isEnabled()) return;
7
+
8
+ $block = $observer->getEvent()->getBlock();
9
+ if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction && $block->getRequest()->getControllerName() == 'sales_order') {
10
+ $block->addItem('delete-order-magehit', array(
11
+ 'label' => '' . Mage::helper('deleteorder')->__('Delete Order(s)'),
12
+ 'url' => Mage::helper("adminhtml")->getUrl('deleteorderadmin/adminhtml_index/deleteOrders'),
13
+ ));
14
+ }
15
+ }
16
+ }
app/code/local/Magehit/Deleteorder/Model/Order.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Model_Order extends Mage_Core_Model_Abstract
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ }
8
+
9
+ public function deleteOrder($orderIds = array())
10
+ {
11
+
12
+ $this->deteleRelated($orderIds);
13
+
14
+ if (version_compare(Mage::getVersion(), '1.3.0', '<=') && $this->_deleteOld($orderIds)) {
15
+ return true;
16
+ } else {
17
+ if ($this->_delete($orderIds)) return true;
18
+ }
19
+
20
+ return false;
21
+
22
+ }
23
+
24
+ public function _deleteOld($orderIds = array())
25
+ {
26
+
27
+ $orderIds = '(' . implode(",", $orderIds) . ')';
28
+ $resource = Mage::getSingleton('core/resource');
29
+ $write = $resource->getConnection('core_write');
30
+ $saleOrder = $resource->getTableName('sales_order');
31
+ $saleOrderEntity = $resource->getTableName('sales_order_entity');
32
+ $saleOrderEntityInt = $resource->getTableName('sales_order_entity_int');
33
+ $eavAttr = $resource->getTableName('eav_attribute');
34
+ $saleFlatOrderItem = $resource->getTableName('sales_flat_order_item');
35
+
36
+
37
+ try {
38
+ $sql = "DELETE FROM " . $saleOrder . " WHERE entity_id IN " . $orderIds . ";";
39
+ $write->query($sql);
40
+ $sql = "DELETE FROM " . $saleOrderEntity . " WHERE parent_id IN " . $orderIds . ";";
41
+ $write->query($sql);
42
+ $sql = "DELETE s FROM " . $saleOrderEntity . " s
43
+ JOIN " . $saleOrderEntityInt . " si on s.entity_id = si.entity_id
44
+ JOIN " . $eavAttr . " a on si.attribute_id = a.attribute_id
45
+ WHERE a.attribute_code = 'order_id'
46
+ AND si.value IN " . $orderIds . ";";
47
+ $write->query($sql);
48
+ $sql = "DELETE FROM " . $saleFlatOrderItem . " WHERE order_id IN " . $orderIds . ";";
49
+ $write->query($sql);
50
+ } catch (Exception $e) {
51
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
52
+ }
53
+
54
+ return true;
55
+ }
56
+
57
+ public function _delete($orderIds = array())
58
+ {
59
+
60
+ $orderIds = '(' . implode(",", $orderIds) . ')';
61
+ $resource = Mage::getSingleton('core/resource');
62
+ $write = $resource->getConnection('core_write');
63
+ $saleFlatOrder = $resource->getTableName('sales_flat_order');
64
+ $saleFlatOrderGrid = $resource->getTableName('sales_flat_order_grid');
65
+
66
+ try {
67
+ $sql = "DELETE FROM " . $saleFlatOrder . " WHERE entity_id IN " . $orderIds . ";";
68
+ $write->query($sql);
69
+ $sql = "DELETE FROM " . $saleFlatOrderGrid . " WHERE entity_id IN " . $orderIds . ";";
70
+ $write->query($sql);
71
+ } catch (Exception $e) {
72
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
73
+ }
74
+
75
+ return true;
76
+ }
77
+
78
+ public function deteleRelated($orderIds = array())
79
+ {
80
+
81
+ try {
82
+ $invoices = Mage::getResourceModel('sales/order_invoice_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
83
+ foreach ($invoices as $invoice) $invoice->delete();
84
+
85
+ $gridInvoices = Mage::getResourceModel('sales/order_invoice_grid_collection')->addFieldToFilter('order_id', array('in', $orderIds));
86
+ foreach ($gridInvoices as $invoice) $invoice->delete();
87
+
88
+ $shipments = Mage::getResourceModel('sales/order_shipment_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
89
+ foreach ($shipments as $shipment) $shipment->delete();
90
+
91
+ $gridShipments = Mage::getResourceModel('sales/order_shipment_grid_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
92
+ foreach ($gridShipments as $shipment) $shipment->delete();
93
+
94
+ $creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
95
+ foreach ($creditmemos as $creditmemo) $creditmemo->delete();
96
+
97
+ $gridCreditMemos = Mage::getResourceModel('sales/order_creditmemo_grid_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
98
+ foreach ($gridCreditMemos as $creditmemo) $creditmemo->delete();
99
+
100
+ $transactions = Mage::getResourceModel('sales/order_payment_transaction_collection')->addAttributeToSelect('*')->addFieldToFilter('order_id', array('in', $orderIds));
101
+ foreach ($transactions as $transaction) $transaction->delete();
102
+ } catch (Exception $e) {
103
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
104
+ }
105
+ }
106
+
107
+ }
app/code/local/Magehit/Deleteorder/Model/Status.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Model_Status extends Varien_Object
3
+ {
4
+ const STATUS_ENABLED = 1;
5
+ const STATUS_DISABLED = 2;
6
+
7
+ static public function getOptionArray()
8
+ {
9
+ return array(
10
+ self::STATUS_ENABLED => Mage::helper('deleteorder')->__('Enabled'),
11
+ self::STATUS_DISABLED => Mage::helper('deleteorder')->__('Disabled')
12
+ );
13
+ }
14
+
15
+ static public function getOptionHash()
16
+ {
17
+ $options = array();
18
+ foreach (self::getOptionArray() as $value => $label) {
19
+ $options[] = array(
20
+ 'value' => $value,
21
+ 'label' => $label
22
+ );
23
+ }
24
+ return $options;
25
+ }
26
+ }
app/code/local/Magehit/Deleteorder/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Magehit_Deleteorder_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ public function deleteOrdersAction()
5
+ {
6
+ $orderIds = $this->getRequest()->getParam('order_ids');
7
+ if (empty($orderIds)) {
8
+ Mage::getSingleton('adminhtml/session')->addError($this->__('There is no order to process'));
9
+ $this->_redirect('adminhtml/sales_order');
10
+ return;
11
+ }
12
+ try {
13
+ $count = 0;
14
+ foreach($orderIds as $orderId){
15
+ if(Mage::getModel('deleteorder/order')->deleteOrder(array($orderId))) $count++;
16
+ }
17
+ Mage::getSingleton('adminhtml/session')->addSuccess(
18
+ Mage::helper('adminhtml')->__('%s order(s) successfully deleted', $count)
19
+ );
20
+ } catch (Exception $e) {
21
+ Mage::getSingleton('core/session')->addError($e->getMessage());
22
+ }
23
+ $this->_redirect('adminhtml/sales_order');
24
+ }
25
+
26
+ protected function _isAllowed()
27
+ {
28
+ return Mage::getSingleton('admin/session')->isAllowed('deleteorder');
29
+ }
30
+ }
app/code/local/Magehit/Deleteorder/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Delete Order</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <deleteorder translate="title">
15
+ <title>Delete Order</title>
16
+ </deleteorder>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/local/Magehit/Deleteorder/etc/config.xml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magehit_Deleteorder>
5
+ <version>0.1.0</version>
6
+ </Magehit_Deleteorder>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <deleteorderadmin>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>Magehit_Deleteorder</module>
14
+ <frontName>deleteorderadmin</frontName>
15
+ </args>
16
+ </deleteorderadmin>
17
+ </routers>
18
+ </admin>
19
+ <adminhtml>
20
+ <translate>
21
+ <modules>
22
+ <Magehit_Deleteorder>
23
+ <files>
24
+ <default>Magegiant_Deleteorder.csv</default>
25
+ </files>
26
+ </Magehit_Deleteorder>
27
+ </modules>
28
+ </translate>
29
+
30
+ <events>
31
+ <core_block_abstract_to_html_before>
32
+ <observers>
33
+ <deleteorder>
34
+ <class>deleteorder/observer</class>
35
+ <method>core_block_abstract_to_html_before</method>
36
+ </deleteorder>
37
+ </observers>
38
+ </core_block_abstract_to_html_before>
39
+ </events>
40
+
41
+ </adminhtml>
42
+ <global>
43
+ <models>
44
+ <deleteorder>
45
+ <class>Magehit_Deleteorder_Model</class>
46
+ </deleteorder>
47
+ </models>
48
+ <blocks>
49
+ <deleteorder>
50
+ <class>Magehit_Deleteorder_Block</class>
51
+ </deleteorder>
52
+ </blocks>
53
+ <helpers>
54
+ <deleteorder>
55
+ <class>Magehit_Deleteorder_Helper</class>
56
+ </deleteorder>
57
+ </helpers>
58
+ </global>
59
+ <default>
60
+ <deleteorder>
61
+ <general>
62
+ <enable>1</enable>
63
+ </general>
64
+ </deleteorder>
65
+ </default>
66
+ </config>
app/code/local/Magehit/Deleteorder/etc/system.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <magehit translate="label">
5
+ <label>Magehit</label>
6
+ <sort_order>100</sort_order>
7
+ </magehit>
8
+ </tabs>
9
+ <sections>
10
+ <deleteorder translate="label" module="deleteorder">
11
+ <class>separator-top</class>
12
+ <label>Delete orders</label>
13
+ <tab>magehit</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>200</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <general translate="label">
21
+ <label>General Configuration</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <fields>
28
+ <enable translate="label">
29
+ <label>Enable</label>
30
+ <frontend_type>select</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <source_model>adminhtml/system_config_source_yesno</source_model>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ <comment></comment>
37
+ </enable>
38
+ </fields>
39
+ </general>
40
+ </groups>
41
+ </deleteorder>
42
+ </sections>
43
+ </config>
app/etc/modules/Magehit_Deleteorder.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magehit_Deleteorder>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Magehit_Deleteorder>
8
+ </modules>
9
+ </config>
app/locale/en_US/Magehit_Deleteorder.csv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ "Allow Everything","Allow Everything"
2
+ "Delete","Delete"
3
+ "Delete orders","Delete orders"
4
+ "Deleteorder","Deleteorder"
5
+ "Disabled","Disabled"
6
+ "Enable","Enable"
7
+ "Enabled","Enabled"
8
+ "General Configuration","General Configuration"
9
+ "Manage Items","Manage Items"
10
+ "Settings","Settings"
11
+ "There is no order to process","There is no order to process"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Magehit_DeleteOrrders</name>
4
+ <version>0.1.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>Delete Orders version 0.1.0</summary>
10
+ <description>Delete Orders version 0.1.0</description>
11
+ <notes>Delete Orders version 0.1.0</notes>
12
+ <authors><author><name>MageHit</name><user>magehit</user><email>support@magehit.com</email></author></authors>
13
+ <date>2015-10-30</date>
14
+ <time>02:16:43</time>
15
+ <contents><target name="magelocal"><dir name="Magehit"><dir name="Deleteorder"><dir name="Helper"><file name="Data.php" hash="2d1fcd27fa5eae9ea5b460f02d2858cb"/></dir><dir name="Model"><file name="Config.php" hash="664dc88379f1079edc2417e18b5dbbc9"/><file name="Observer.php" hash="9f4141e16ad898dbf534b7d15410b9e8"/><file name="Order.php" hash="a72e837ab2b7b0a18c799d3f3d8ac7d9"/><file name="Status.php" hash="3edb78e93f5505409bc3ef9694fdb2fc"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="707f53d171c28c52647f206daf8191e7"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="d183cf1031e19320048bd872fd9f02e8"/><file name="config.xml" hash="93a86201b75f179c14cb0e49c4451da0"/><file name="system.xml" hash="efb0f61a82d0f11ba8082f48a1c0cbca"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magehit_Deleteorder.xml" hash="284f56283266a8e8f110123812a042fe"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Magehit_Deleteorder.csv" hash="daa13ecced4f79f55f9de0d2cdd2e1c3"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>