Version Notes
Initial Release
Download this release
Release Info
Developer | Ameronix |
Extension | Ameronix_OrderDelete |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Ameronix/OrderDelete/Helper/Xml.php +21 -0
- app/code/community/Ameronix/OrderDelete/Model/Observer.php +39 -0
- app/code/community/Ameronix/OrderDelete/controllers/Adminhtml/OrderdeleteController.php +74 -0
- app/code/community/Ameronix/OrderDelete/etc/config.xml +60 -0
- app/design/adminhtml/default/default/layout/ameronix_orderdelete.xml +12 -0
- app/etc/modules/Ameronix_OrderDelete.xml +9 -0
- package.xml +18 -0
app/code/community/Ameronix/OrderDelete/Helper/Xml.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ameronix_OrderDelete_Helper_Xml
|
4 |
+
extends Mage_Core_Helper_Abstract {
|
5 |
+
|
6 |
+
public function getDeleteOrderData() {
|
7 |
+
/* @var $salesOrder Mage_Sales_Model_Order */
|
8 |
+
$salesOrder = Mage::registry('sales_order');
|
9 |
+
|
10 |
+
if($salesOrder->getId()) {
|
11 |
+
$url = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/orderdelete/delete', array('order_id' => $salesOrder->getId()));
|
12 |
+
|
13 |
+
return array(
|
14 |
+
'label' => 'Delete Order',
|
15 |
+
'class' => 'delete',
|
16 |
+
'onclick' => 'if(confirm(\'Are you sure?\')) { setLocation(\'' . $url . '\') }'
|
17 |
+
);
|
18 |
+
}
|
19 |
+
|
20 |
+
}
|
21 |
+
}
|
app/code/community/Ameronix/OrderDelete/Model/Observer.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ameronix_OrderDelete_Model_Observer {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @param $observer
|
7 |
+
*/
|
8 |
+
public function coreBlockAbstractToHtmlBefore($observer) {
|
9 |
+
$block = $observer->getBlock();
|
10 |
+
|
11 |
+
// Is the block the sales order grid or derived from?
|
12 |
+
if($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction) {
|
13 |
+
/* @var $block Mage_Adminhtml_Block_Widget_Grid_Massaction */
|
14 |
+
|
15 |
+
if($block->getParentBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
|
16 |
+
$block->addItem('amx_orderdelete', array(
|
17 |
+
'label' => 'Delete Order',
|
18 |
+
'url' => $block->getUrl('adminhtml/orderdelete/massaction'),
|
19 |
+
'confirm' => 'Are you sure?'
|
20 |
+
));
|
21 |
+
}
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @param $observer
|
27 |
+
*/
|
28 |
+
public function salesOrderDeleteBefore($observer) {
|
29 |
+
/* @var $order Mage_Sales_Model_Order */
|
30 |
+
$order = $observer->getOrder();
|
31 |
+
|
32 |
+
// Checks to see if it has an id
|
33 |
+
if($order->getId()) {
|
34 |
+
Mage::unregister('__amx_orderdelete_last_attempted_order');
|
35 |
+
Mage::register('__amx_orderdelete_last_attempted_order', $order);
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
app/code/community/Ameronix/OrderDelete/controllers/Adminhtml/OrderdeleteController.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Ameronix_OrderDelete_Adminhtml_OrderdeleteController
|
4 |
+
extends Mage_Adminhtml_Controller_Action {
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @param $orderIds
|
8 |
+
*/
|
9 |
+
protected function delete($orderIds) {
|
10 |
+
if(!$orderIds) {
|
11 |
+
$this->_getSession()->addError('No Order(s) Specified!');
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
if(!is_array($orderIds)) {
|
16 |
+
$orderIds = array($orderIds);
|
17 |
+
}
|
18 |
+
|
19 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
20 |
+
->addFieldToFilter('entity_id', array('in' => $orderIds))
|
21 |
+
->setOrder('entity_id', 'desc');
|
22 |
+
|
23 |
+
if($orders->count() > 0) {
|
24 |
+
$newestId = $orders->getFirstItem()->getId();
|
25 |
+
$oldestId = $orders->getLastItem()->getId();
|
26 |
+
|
27 |
+
try {
|
28 |
+
// Generates a tranaction model
|
29 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
30 |
+
|
31 |
+
// Add all the orders we are deleting to the transaction
|
32 |
+
foreach($orders as $order) {
|
33 |
+
$transaction->addObject($order);
|
34 |
+
}
|
35 |
+
|
36 |
+
// Delete all the orders
|
37 |
+
$transaction->delete();
|
38 |
+
|
39 |
+
// If there is only one order we are deleting
|
40 |
+
if($newestId == $oldestId) {
|
41 |
+
$this->_getSession()->addSuccess("Successfully deleted order number {$newestId}.");
|
42 |
+
} else {
|
43 |
+
$this->_getSession()->addSuccess("Successfully deleted order numbers {$oldestId}-{$newestId}.");
|
44 |
+
}
|
45 |
+
} catch(Exception $e) {
|
46 |
+
$lastAttemptedOrder = Mage::registry('__amx_orderdelete_last_attempted_order');
|
47 |
+
|
48 |
+
if($lastAttemptedOrder) {
|
49 |
+
$this->_getSession()->addError("An error occured when deleting order number {$lastAttemptedOrder->getIncrementId()}!");
|
50 |
+
} else {
|
51 |
+
$this->_getSession()->addError('An error occured when deleting an order!');
|
52 |
+
}
|
53 |
+
}
|
54 |
+
} else {
|
55 |
+
$this->_getSession()->addError('Could not load orders!');
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
public function massactionAction() {
|
60 |
+
$orderIds = $this->getRequest()->getParam('order_ids');
|
61 |
+
|
62 |
+
$this->delete($orderIds);
|
63 |
+
|
64 |
+
$this->_redirect('adminhtml/sales_order');
|
65 |
+
}
|
66 |
+
|
67 |
+
public function deleteAction() {
|
68 |
+
$orderId = $this->getRequest()->getParam('order_id');
|
69 |
+
|
70 |
+
$this->delete($orderId);
|
71 |
+
|
72 |
+
$this->_redirect('adminhtml/sales_order');
|
73 |
+
}
|
74 |
+
}
|
app/code/community/Ameronix/OrderDelete/etc/config.xml
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ameronix_OrderDelete>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</Ameronix_OrderDelete>
|
7 |
+
</modules>
|
8 |
+
|
9 |
+
<global>
|
10 |
+
<helpers>
|
11 |
+
<ameronix_orderdelete>
|
12 |
+
<class>Ameronix_OrderDelete_Helper</class>
|
13 |
+
</ameronix_orderdelete>
|
14 |
+
</helpers>
|
15 |
+
|
16 |
+
<events>
|
17 |
+
<core_block_abstract_to_html_before>
|
18 |
+
<observers>
|
19 |
+
<ameronix_orderdelete>
|
20 |
+
<type>singleton</type>
|
21 |
+
<class>Ameronix_OrderDelete_Model_Observer</class>
|
22 |
+
<method>coreBlockAbstractToHtmlBefore</method>
|
23 |
+
</ameronix_orderdelete>
|
24 |
+
</observers>
|
25 |
+
</core_block_abstract_to_html_before>
|
26 |
+
|
27 |
+
<sales_order_delete_before>
|
28 |
+
<observers>
|
29 |
+
<ameronix_orderdelete>
|
30 |
+
<type>singleton</type>
|
31 |
+
<class>Ameronix_OrderDelete_Model_Observer</class>
|
32 |
+
<method>salesOrderDeleteBefore</method>
|
33 |
+
</ameronix_orderdelete>
|
34 |
+
</observers>
|
35 |
+
</sales_order_delete_before>
|
36 |
+
</events>
|
37 |
+
</global>
|
38 |
+
|
39 |
+
<adminhtml>
|
40 |
+
<layout>
|
41 |
+
<updates>
|
42 |
+
<ameronix_orderdelete>
|
43 |
+
<file>ameronix_orderdelete.xml</file>
|
44 |
+
</ameronix_orderdelete>
|
45 |
+
</updates>
|
46 |
+
</layout>
|
47 |
+
</adminhtml>
|
48 |
+
|
49 |
+
<admin>
|
50 |
+
<routers>
|
51 |
+
<adminhtml>
|
52 |
+
<args>
|
53 |
+
<modules>
|
54 |
+
<ameronix_orderdelete before="Mage_Adminhtml">Ameronix_OrderDelete_Adminhtml</ameronix_orderdelete>
|
55 |
+
</modules>
|
56 |
+
</args>
|
57 |
+
</adminhtml>
|
58 |
+
</routers>
|
59 |
+
</admin>
|
60 |
+
</config>
|
app/design/adminhtml/default/default/layout/ameronix_orderdelete.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<adminhtml_sales_order_view>
|
4 |
+
<reference name="sales_order_edit">
|
5 |
+
<action method="addButton">
|
6 |
+
<id>amx_order_delete</id>
|
7 |
+
<data helper="ameronix_orderdelete/xml/getDeleteOrderData"/>
|
8 |
+
<sortOrder>-1</sortOrder>
|
9 |
+
</action>
|
10 |
+
</reference>
|
11 |
+
</adminhtml_sales_order_view>
|
12 |
+
</layout>
|
app/etc/modules/Ameronix_OrderDelete.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ameronix_OrderDelete>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Ameronix_OrderDelete>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Ameronix_OrderDelete</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL-3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Utilizes transactions to securely delete orders using the native Magento API.</summary>
|
10 |
+
<description>Using Magento's built-in order delete API and its database transaction capability, this module securely deletes orders while making sure there have been no errors before committing the changes to the database all while fully complying with Magento development standards.</description>
|
11 |
+
<notes>Initial Release</notes>
|
12 |
+
<authors><author><name>Richard Klint</name><user>ameronix</user><email>rklint@ameornix.com</email></author></authors>
|
13 |
+
<date>2014-07-31</date>
|
14 |
+
<time>13:00:17</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Ameronix_OrderDelete.xml" hash="63e06b2afb02fec7987103dfa5d552c8"/></dir></target><target name="magecommunity"><dir name="Ameronix"><dir name="OrderDelete"><dir name="Helper"><file name="Xml.php" hash="550f37f0d70d1f1be4e22d00776cb4f8"/></dir><dir name="Model"><file name="Observer.php" hash="e5fbb6da0335c20ed1b3a7ae43165c86"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="OrderdeleteController.php" hash="f1ddefaf6287f8157be43b17f3e97f58"/></dir></dir><dir name="etc"><file name="config.xml" hash="57ea8b9ff19078900fb8a5014d939bc9"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="ameronix_orderdelete.xml" hash="4e396b3ef292d28a181fc3a11a64a65e"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|