Version Notes
Public release
Download this release
Release Info
| Developer | Magebeam |
| Extension | Magebeam_EasyOrderDeleter |
| Version | 0.1.0 |
| Comparing to | |
| See all releases | |
Version 0.1.0
- app/code/community/Magebeam/EasyOrderDeleter/Helper/Data.php +34 -0
- app/code/community/Magebeam/EasyOrderDeleter/Model/Deleter.php +348 -0
- app/code/community/Magebeam/EasyOrderDeleter/Model/Observer.php +54 -0
- app/code/community/Magebeam/EasyOrderDeleter/controllers/Adminhtml/Sales/OrderController.php +35 -0
- app/code/community/Magebeam/EasyOrderDeleter/etc/config.xml +79 -0
- app/etc/modules/Magebeam_EasyOrderDeleter.xml +30 -0
- app/locale/en_US/Magebeam_EasyOrderDeleter.csv +1 -0
- package.xml +18 -0
app/code/community/Magebeam/EasyOrderDeleter/Helper/Data.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magebeam Easy Order Deleter data helper
|
| 4 |
+
*
|
| 5 |
+
* @category Magebeam
|
| 6 |
+
* @package Magebeam_EasyOrderDeleter
|
| 7 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 9 |
+
*/
|
| 10 |
+
class Magebeam_EasyOrderDeleter_Helper_Data extends Mage_Core_Helper_Abstract
|
| 11 |
+
{
|
| 12 |
+
/**
|
| 13 |
+
* Returns boolean flag: true if "delete" action is allowed for order, false if not
|
| 14 |
+
*
|
| 15 |
+
* @return bool
|
| 16 |
+
*/
|
| 17 |
+
public function isAllowedOrderDeleteAction()
|
| 18 |
+
{
|
| 19 |
+
return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/delete');
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Deletes order
|
| 24 |
+
*
|
| 25 |
+
* @param int $orderId Order id
|
| 26 |
+
*
|
| 27 |
+
* @return bool True if order has been deleted, false otherwise
|
| 28 |
+
*/
|
| 29 |
+
public function deleteOrder($orderId)
|
| 30 |
+
{
|
| 31 |
+
$deleter = Mage::getSingleton('magebeam_easyorderdeleter/deleter');
|
| 32 |
+
return $deleter->deleteOrder($orderId);
|
| 33 |
+
}
|
| 34 |
+
}
|
app/code/community/Magebeam/EasyOrderDeleter/Model/Deleter.php
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magebeam Easy Order Deleter deleter
|
| 4 |
+
*
|
| 5 |
+
* @category Magebeam
|
| 6 |
+
* @package Magebeam_EasyOrderDeleter
|
| 7 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 9 |
+
*/
|
| 10 |
+
class Magebeam_EasyOrderDeleter_Model_Deleter extends Mage_Core_Model_Abstract
|
| 11 |
+
{
|
| 12 |
+
/**
|
| 13 |
+
* Read connection
|
| 14 |
+
*
|
| 15 |
+
* @var Varien_Db_Adapter_Interface
|
| 16 |
+
*/
|
| 17 |
+
protected $_readConn = null;
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Write connection
|
| 21 |
+
*
|
| 22 |
+
* @var Varien_Db_Adapter_Interface
|
| 23 |
+
*/
|
| 24 |
+
protected $_writeConn = null;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Existing database tables list
|
| 28 |
+
*
|
| 29 |
+
* @var array
|
| 30 |
+
*/
|
| 31 |
+
protected $_existingTables = array();
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Fetches list of existing tables from database
|
| 35 |
+
*/
|
| 36 |
+
protected function _fetchExistingDatabaseTables()
|
| 37 |
+
{
|
| 38 |
+
$query = 'SHOW TABLES';
|
| 39 |
+
$this->_existingTables = $this->_readConn->fetchCol($query);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Deletes order and all its data from database
|
| 44 |
+
*
|
| 45 |
+
* @param int $orderId Order id to delete
|
| 46 |
+
*
|
| 47 |
+
* @return bool True if order successfully deleted, false otherwise
|
| 48 |
+
*/
|
| 49 |
+
public function deleteOrder($orderId)
|
| 50 |
+
{
|
| 51 |
+
/** @var Mage_Sales_Model_Order $order */
|
| 52 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
| 53 |
+
if (!$order->getId()) {
|
| 54 |
+
return false;
|
| 55 |
+
}
|
| 56 |
+
$this->_initResources();
|
| 57 |
+
$this->_deleteOrderCreditmemos($order);
|
| 58 |
+
$this->_deleteOrderInvoices($order);
|
| 59 |
+
$this->_deleteOrderQuotes($order);
|
| 60 |
+
$this->_deleteOrderShipments($order);
|
| 61 |
+
$this->_deleteOrderDownloadableLinksPurchased($order);
|
| 62 |
+
$this->_deleteOrderData($order);
|
| 63 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
| 64 |
+
return !$order->getId();
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/**
|
| 68 |
+
* Initializes resources
|
| 69 |
+
*/
|
| 70 |
+
protected function _initResources()
|
| 71 |
+
{
|
| 72 |
+
$this->_readConn = Mage::getSingleton('core/resource')->getConnection('read');
|
| 73 |
+
$this->_writeConn = Mage::getSingleton('core/resource')->getConnection('write');
|
| 74 |
+
$this->_fetchExistingDatabaseTables();
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Deletes order creditmemos
|
| 79 |
+
*
|
| 80 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 81 |
+
*/
|
| 82 |
+
protected function _deleteOrderCreditmemos($order)
|
| 83 |
+
{
|
| 84 |
+
$tblSalesFlatCreditmemo = $this->_getTableName('sales_flat_creditmemo');
|
| 85 |
+
if ($this->_isTableExists($tblSalesFlatCreditmemo)) {
|
| 86 |
+
$tblSalesFlatCreditmemo = $this->_quoteIdentifier($tblSalesFlatCreditmemo);
|
| 87 |
+
$where = $this->_quoteInto(
|
| 88 |
+
"parent_id IN (SELECT entity_id FROM {$tblSalesFlatCreditmemo} WHERE order_id = ?)",
|
| 89 |
+
$order->getId()
|
| 90 |
+
);
|
| 91 |
+
$this->_deleteIfTableExists('sales_flat_creditmemo_comment', $where);
|
| 92 |
+
$this->_deleteIfTableExists('sales_flat_creditmemo_item', $where);
|
| 93 |
+
$where = $this->_quoteInto(
|
| 94 |
+
'order_id = ?',
|
| 95 |
+
$order->getId()
|
| 96 |
+
);
|
| 97 |
+
$this->_delete('sales_flat_creditmemo_grid', $where);
|
| 98 |
+
$this->_delete('sales_flat_creditmemo', $where);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Deletes order invoices
|
| 104 |
+
*
|
| 105 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 106 |
+
*/
|
| 107 |
+
protected function _deleteOrderInvoices($order)
|
| 108 |
+
{
|
| 109 |
+
$tblSalesFlatInvoice = $this->_getTableName('sales_flat_invoice');
|
| 110 |
+
if ($this->_isTableExists($tblSalesFlatInvoice)) {
|
| 111 |
+
$tblSalesFlatInvoice = $this->_quoteIdentifier($tblSalesFlatInvoice);
|
| 112 |
+
$where = $this->_quoteInto(
|
| 113 |
+
"parent_id IN (SELECT entity_id FROM {$tblSalesFlatInvoice} WHERE order_id = ?)",
|
| 114 |
+
$order->getId()
|
| 115 |
+
);
|
| 116 |
+
$this->_deleteIfTableExists('sales_flat_invoice_comment', $where);
|
| 117 |
+
$this->_deleteIfTableExists('sales_flat_invoice_item', $where);
|
| 118 |
+
$where = $this->_quoteInto(
|
| 119 |
+
'order_id = ?',
|
| 120 |
+
$order->getId()
|
| 121 |
+
);
|
| 122 |
+
$this->_delete('sales_flat_invoice_grid', $where);
|
| 123 |
+
$this->_delete('sales_flat_invoice', $where);
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Deletes order quotes
|
| 129 |
+
*
|
| 130 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 131 |
+
*/
|
| 132 |
+
protected function _deleteOrderQuotes($order)
|
| 133 |
+
{
|
| 134 |
+
$tblSalesFlatOrder = $this->_getTableName('sales_flat_order');
|
| 135 |
+
$select = $this->_readConn->select()
|
| 136 |
+
->from($tblSalesFlatOrder)
|
| 137 |
+
->columns('quote_id')
|
| 138 |
+
->where('entity_id = ?', $order->getId());
|
| 139 |
+
$orderQuoteId = $this->_readConn->fetchOne($select);
|
| 140 |
+
if ($orderQuoteId) {
|
| 141 |
+
$tblSalesFlatQuoteAddress = $this->_getTableName('sales_flat_quote_address');
|
| 142 |
+
if ($this->_isTableExists($tblSalesFlatQuoteAddress)) {
|
| 143 |
+
$tblSalesFlatQuoteAddress = $this->_quoteIdentifier($tblSalesFlatQuoteAddress);
|
| 144 |
+
$where = $this->_quoteInto(
|
| 145 |
+
"parent_item_id IN (SELECT address_id FROM {$tblSalesFlatQuoteAddress} WHERE quote_id = ?)",
|
| 146 |
+
$orderQuoteId
|
| 147 |
+
);
|
| 148 |
+
$this->_deleteIfTableExists('sales_flat_quote_address_item', $where);
|
| 149 |
+
$where = $this->_quoteInto(
|
| 150 |
+
"address_id IN (SELECT address_id FROM {$tblSalesFlatQuoteAddress} WHERE quote_id = ?)",
|
| 151 |
+
$orderQuoteId
|
| 152 |
+
);
|
| 153 |
+
$this->_deleteIfTableExists('sales_flat_quote_shipping_rate', $where);
|
| 154 |
+
}
|
| 155 |
+
$tblSalesFlatQuoteItem = $this->_getTableName('sales_flat_quote_item');
|
| 156 |
+
if ($this->_isTableExists($tblSalesFlatQuoteItem)) {
|
| 157 |
+
$tblSalesFlatQuoteItem = $this->_quoteIdentifier($tblSalesFlatQuoteItem);
|
| 158 |
+
$where = $this->_quoteInto(
|
| 159 |
+
"item_id IN (SELECT item_id FROM {$tblSalesFlatQuoteItem} WHERE quote_id = ?)",
|
| 160 |
+
$orderQuoteId
|
| 161 |
+
);
|
| 162 |
+
|
| 163 |
+
$this->_deleteIfTableExists('sales_flat_quote_item_option', $where);
|
| 164 |
+
}
|
| 165 |
+
$where = $this->_quoteInto(
|
| 166 |
+
'quote_id = ?',
|
| 167 |
+
$orderQuoteId
|
| 168 |
+
);
|
| 169 |
+
$this->_deleteIfTableExists('sales_flat_quote_address', $where);
|
| 170 |
+
$this->_deleteIfTableExists('sales_flat_quote_item', $where);
|
| 171 |
+
$this->_deleteIfTableExists('sales_flat_quote_payment', $where);
|
| 172 |
+
$where = $this->_quoteInto(
|
| 173 |
+
'quote_id = ?',
|
| 174 |
+
$orderQuoteId
|
| 175 |
+
);
|
| 176 |
+
$this->_deleteIfTableExists('log_quote', $where);
|
| 177 |
+
$where = $this->_quoteInto(
|
| 178 |
+
'entity_id = ?',
|
| 179 |
+
$orderQuoteId
|
| 180 |
+
);
|
| 181 |
+
$this->_deleteIfTableExists('sales_flat_quote', $where);
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Deletes order shipments
|
| 187 |
+
*
|
| 188 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 189 |
+
*/
|
| 190 |
+
protected function _deleteOrderShipments($order)
|
| 191 |
+
{
|
| 192 |
+
$tblSalesFlatShipment = $this->_getTableName('sales_flat_shipment');
|
| 193 |
+
if ($this->_isTableExists($tblSalesFlatShipment)) {
|
| 194 |
+
$tblSalesFlatShipment = $this->_quoteIdentifier($tblSalesFlatShipment);
|
| 195 |
+
$where = $this->_quoteInto(
|
| 196 |
+
"parent_id IN (SELECT entity_id FROM {$tblSalesFlatShipment} WHERE order_id = ?)",
|
| 197 |
+
$order->getId()
|
| 198 |
+
);
|
| 199 |
+
$this->_deleteIfTableExists('sales_flat_shipment_comment', $where);
|
| 200 |
+
$this->_deleteIfTableExists('sales_flat_shipment_item', $where);
|
| 201 |
+
}
|
| 202 |
+
$where = $this->_quoteInto(
|
| 203 |
+
"order_id IN (SELECT entity_id FROM {$tblSalesFlatShipment} WHERE order_id = ?)",
|
| 204 |
+
$order->getId()
|
| 205 |
+
);
|
| 206 |
+
$this->_deleteIfTableExists('sales_flat_shipment_track', $where);
|
| 207 |
+
$where = $this->_quoteInto(
|
| 208 |
+
'order_id = ?',
|
| 209 |
+
$order->getId()
|
| 210 |
+
);
|
| 211 |
+
$this->_deleteIfTableExists('sales_flat_shipment_grid', $where);
|
| 212 |
+
$this->_deleteIfTableExists('sales_flat_shipment', $where);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Deletes downloadable items
|
| 217 |
+
*
|
| 218 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 219 |
+
*/
|
| 220 |
+
protected function _deleteOrderDownloadableLinksPurchased($order)
|
| 221 |
+
{
|
| 222 |
+
$tblDownloadableLinkPurchased = $this->_getTableName('downloadable_link_purchased');
|
| 223 |
+
if ($this->_isTableExists($tblDownloadableLinkPurchased)) {
|
| 224 |
+
$tblDownloadableLinkPurchased = $this->_quoteIdentifier($tblDownloadableLinkPurchased);
|
| 225 |
+
$where = $this->_quoteInto(
|
| 226 |
+
"purchased_id IN (SELECT purchased_id FROM {$tblDownloadableLinkPurchased} WHERE order_id = ?)",
|
| 227 |
+
$order->getId()
|
| 228 |
+
);
|
| 229 |
+
$this->_deleteIfTableExists('downloadable_link_purchased_item', $where);
|
| 230 |
+
}
|
| 231 |
+
$where = $this->_quoteInto(
|
| 232 |
+
'order_id = ?',
|
| 233 |
+
$order->getId()
|
| 234 |
+
);
|
| 235 |
+
$this->_deleteIfTableExists('downloadable_link_purchased', $where);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/**
|
| 239 |
+
* Deletes order data
|
| 240 |
+
*
|
| 241 |
+
* @param Mage_Sales_Model_Order $order Order
|
| 242 |
+
*/
|
| 243 |
+
protected function _deleteOrderData($order)
|
| 244 |
+
{
|
| 245 |
+
$where = $this->_quoteInto(
|
| 246 |
+
'parent_id = ?',
|
| 247 |
+
$order->getId()
|
| 248 |
+
);
|
| 249 |
+
$this->_deleteIfTableExists('sales_flat_order_address', $where);
|
| 250 |
+
$this->_deleteIfTableExists('sales_flat_order_payment', $where);
|
| 251 |
+
$this->_deleteIfTableExists('sales_flat_order_status_history', $where);
|
| 252 |
+
$where = $this->_quoteInto(
|
| 253 |
+
'order_id = ?',
|
| 254 |
+
$order->getId()
|
| 255 |
+
);
|
| 256 |
+
|
| 257 |
+
// Delete order
|
| 258 |
+
$this->_deleteIfTableExists('sales_flat_order_item', $where);
|
| 259 |
+
if ($order->getIncrementId()) {
|
| 260 |
+
$where = $this->_quoteInto(
|
| 261 |
+
'increment_id = ?',
|
| 262 |
+
$order->getIncrementId()
|
| 263 |
+
);
|
| 264 |
+
$this->_deleteIfTableExists('sales_flat_order_grid', $where);
|
| 265 |
+
}
|
| 266 |
+
$where = $this->_quoteInto(
|
| 267 |
+
'entity_id = ?',
|
| 268 |
+
$order->getId()
|
| 269 |
+
);
|
| 270 |
+
$this->_deleteIfTableExists('sales_flat_order', $where);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
/**
|
| 274 |
+
* Returns table name in database
|
| 275 |
+
*
|
| 276 |
+
* @param string $tableName Table name
|
| 277 |
+
*
|
| 278 |
+
* @return string
|
| 279 |
+
*/
|
| 280 |
+
protected function _getTableName($tableName)
|
| 281 |
+
{
|
| 282 |
+
return Mage::getSingleton('core/resource')->getTableName($tableName);
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/**
|
| 286 |
+
* Returns quoted identifier
|
| 287 |
+
*
|
| 288 |
+
* @param string $identifier Identifier
|
| 289 |
+
*
|
| 290 |
+
* @return string
|
| 291 |
+
*/
|
| 292 |
+
protected function _quoteIdentifier($identifier)
|
| 293 |
+
{
|
| 294 |
+
return $this->_readConn->quoteIdentifier($identifier);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
/**
|
| 298 |
+
* Returns SQL with value quoted into
|
| 299 |
+
*
|
| 300 |
+
* @param string $sql SQL string
|
| 301 |
+
* @param string $value Value
|
| 302 |
+
*
|
| 303 |
+
* @return string
|
| 304 |
+
*/
|
| 305 |
+
protected function _quoteInto($sql, $value)
|
| 306 |
+
{
|
| 307 |
+
return $this->_readConn->quoteInto($sql, $value);
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* Returns boolean flag: true if table exists in database, false if not
|
| 312 |
+
*
|
| 313 |
+
* @param string $tableName Table name
|
| 314 |
+
*
|
| 315 |
+
* @return bool
|
| 316 |
+
*/
|
| 317 |
+
protected function _isTableExists($tableName)
|
| 318 |
+
{
|
| 319 |
+
return in_array($tableName, $this->_existingTables);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
/**
|
| 323 |
+
* Executes DELETE SQL if table exists
|
| 324 |
+
*
|
| 325 |
+
* @param string $tableName Table name
|
| 326 |
+
* @param string $where WHERE SQL clause
|
| 327 |
+
*/
|
| 328 |
+
protected function _deleteIfTableExists($tableName, $where)
|
| 329 |
+
{
|
| 330 |
+
$fullTableName = $this->_getTableName($tableName);
|
| 331 |
+
if (!$this->_isTableExists($fullTableName)) {
|
| 332 |
+
return;
|
| 333 |
+
}
|
| 334 |
+
$this->_writeConn->delete($fullTableName, $where);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* Executes DELETE SQL
|
| 339 |
+
*
|
| 340 |
+
* @param string $tableName Table name
|
| 341 |
+
* @param string $where WHERE SQL clause
|
| 342 |
+
*/
|
| 343 |
+
protected function _delete($tableName, $where)
|
| 344 |
+
{
|
| 345 |
+
$fullTableName = $this->_getTableName($tableName);
|
| 346 |
+
$this->_writeConn->delete($fullTableName, $where);
|
| 347 |
+
}
|
| 348 |
+
}
|
app/code/community/Magebeam/EasyOrderDeleter/Model/Observer.php
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magebeam Easy Order Deleter observer
|
| 4 |
+
*
|
| 5 |
+
* @category Magebeam
|
| 6 |
+
* @package Magebeam_EasyOrderDeleter
|
| 7 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 9 |
+
*/
|
| 10 |
+
class Magebeam_EasyOrderDeleter_Model_Observer
|
| 11 |
+
{
|
| 12 |
+
/**
|
| 13 |
+
* Adds "Delete" button to order view page
|
| 14 |
+
*
|
| 15 |
+
* @param Varien_Event_Observer $event Event object
|
| 16 |
+
*
|
| 17 |
+
* @return Magebeam_EasyOrderDeleter_Model_Observer
|
| 18 |
+
*/
|
| 19 |
+
public function addDeleteOrderButton(Varien_Event_Observer $event)
|
| 20 |
+
{
|
| 21 |
+
/** @var Mage_Adminhtml_Block_Sales_Order_View $block */
|
| 22 |
+
$block = $event->getBlock();
|
| 23 |
+
if ($block->getId() != 'sales_order_view') {
|
| 24 |
+
return $this;
|
| 25 |
+
}
|
| 26 |
+
$this->_addDeleteOrderButton($block);
|
| 27 |
+
return $this;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Adds "Delete" button to order view page
|
| 32 |
+
*
|
| 33 |
+
* @param Mage_Adminhtml_Block_Sales_Order_View $orderViewBlock Order view block
|
| 34 |
+
*
|
| 35 |
+
* @return Magebeam_EasyOrderDeleter_Model_Observer
|
| 36 |
+
*
|
| 37 |
+
*/
|
| 38 |
+
protected function _addDeleteOrderButton($orderViewBlock)
|
| 39 |
+
{
|
| 40 |
+
$order = $orderViewBlock->getOrder();
|
| 41 |
+
if (!$order->getId()) {
|
| 42 |
+
return $this;
|
| 43 |
+
}
|
| 44 |
+
if (Mage::helper('magebeam_easyorderdeleter')->isAllowedOrderDeleteAction()) {
|
| 45 |
+
$orderViewBlock->addButton('delete', array(
|
| 46 |
+
'label' => Mage::helper('adminhtml')->__('Delete'),
|
| 47 |
+
'class' => 'delete',
|
| 48 |
+
'onclick' => 'deleteConfirm(\''. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
|
| 49 |
+
.'\', \'' . $orderViewBlock->getUrl('*/*/delete', array('order_id' => $order->getId())) . '\')',
|
| 50 |
+
));
|
| 51 |
+
}
|
| 52 |
+
return $this;
|
| 53 |
+
}
|
| 54 |
+
}
|
app/code/community/Magebeam/EasyOrderDeleter/controllers/Adminhtml/Sales/OrderController.php
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magebeam Easy Order Deleter order controller
|
| 4 |
+
*
|
| 5 |
+
* @category Magebeam
|
| 6 |
+
* @package Magebeam_EasyOrderDeleter
|
| 7 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 9 |
+
*/
|
| 10 |
+
class Magebeam_EasyOrderDeleter_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Controller_Action
|
| 11 |
+
{
|
| 12 |
+
/**
|
| 13 |
+
* Order id param name
|
| 14 |
+
*/
|
| 15 |
+
const PARAM_ORDER_ID = 'order_id';
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Delete order action
|
| 19 |
+
*/
|
| 20 |
+
public function deleteAction()
|
| 21 |
+
{
|
| 22 |
+
$orderId = $this->getRequest()->getParam(self::PARAM_ORDER_ID);
|
| 23 |
+
$isOrderDeleted = Mage::helper('magebeam_easyorderdeleter')->deleteOrder($orderId);
|
| 24 |
+
if ($isOrderDeleted) {
|
| 25 |
+
$this->_getSession()->addSuccess(
|
| 26 |
+
$this->__('The order has been deleted.')
|
| 27 |
+
);
|
| 28 |
+
} else {
|
| 29 |
+
$this->_getSession()->addError(
|
| 30 |
+
Mage::helper('sales')->__('This order no longer exists.')
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
$this->_redirect('*/sales_order/index');
|
| 34 |
+
}
|
| 35 |
+
}
|
app/code/community/Magebeam/EasyOrderDeleter/etc/config.xml
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Magebeam
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* It is available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
*
|
| 12 |
+
* DISCLAIMER
|
| 13 |
+
*
|
| 14 |
+
* Do not edit or add to this file if you wish to upgrade this package
|
| 15 |
+
* to newer versions in the future.
|
| 16 |
+
*
|
| 17 |
+
* @category Magebeam
|
| 18 |
+
* @package Magebeam_EasyOrderDeleter
|
| 19 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 20 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 21 |
+
*/
|
| 22 |
+
-->
|
| 23 |
+
<config>
|
| 24 |
+
<modules>
|
| 25 |
+
<Magebeam_EasyOrderDeleter>
|
| 26 |
+
<version>0.1.0</version>
|
| 27 |
+
</Magebeam_EasyOrderDeleter>
|
| 28 |
+
</modules>
|
| 29 |
+
<global>
|
| 30 |
+
<blocks>
|
| 31 |
+
<magebeam_easyorderdeleter>
|
| 32 |
+
<class>Magebeam_EasyOrderDeleter_Block</class>
|
| 33 |
+
</magebeam_easyorderdeleter>
|
| 34 |
+
</blocks>
|
| 35 |
+
<models>
|
| 36 |
+
<magebeam_easyorderdeleter>
|
| 37 |
+
<class>Magebeam_EasyOrderDeleter_Model</class>
|
| 38 |
+
</magebeam_easyorderdeleter>
|
| 39 |
+
</models>
|
| 40 |
+
<helpers>
|
| 41 |
+
<magebeam_easyorderdeleter>
|
| 42 |
+
<class>Magebeam_EasyOrderDeleter_Helper</class>
|
| 43 |
+
</magebeam_easyorderdeleter>
|
| 44 |
+
</helpers>
|
| 45 |
+
</global>
|
| 46 |
+
<adminhtml>
|
| 47 |
+
<events>
|
| 48 |
+
<adminhtml_widget_container_html_before>
|
| 49 |
+
<observers>
|
| 50 |
+
<magebeam_easyorderdeleter>
|
| 51 |
+
<class>magebeam_easyorderdeleter/observer</class>
|
| 52 |
+
<method>addDeleteOrderButton</method>
|
| 53 |
+
</magebeam_easyorderdeleter>
|
| 54 |
+
</observers>
|
| 55 |
+
</adminhtml_widget_container_html_before>
|
| 56 |
+
</events>
|
| 57 |
+
<translate>
|
| 58 |
+
<modules>
|
| 59 |
+
<Magebeam_OrderDeleter>
|
| 60 |
+
<files>
|
| 61 |
+
<default>Magebeam_EasyOrderDeleter.csv</default>
|
| 62 |
+
</files>
|
| 63 |
+
</Magebeam_OrderDeleter>
|
| 64 |
+
</modules>
|
| 65 |
+
</translate>
|
| 66 |
+
</adminhtml>
|
| 67 |
+
<admin>
|
| 68 |
+
<routers>
|
| 69 |
+
<adminhtml>
|
| 70 |
+
<use>admin</use>
|
| 71 |
+
<args>
|
| 72 |
+
<modules>
|
| 73 |
+
<Magebeam_EasyOrderDeleter after="Mage_Adminhtml">Magebeam_EasyOrderDeleter_Adminhtml</Magebeam_EasyOrderDeleter>
|
| 74 |
+
</modules>
|
| 75 |
+
</args>
|
| 76 |
+
</adminhtml>
|
| 77 |
+
</routers>
|
| 78 |
+
</admin>
|
| 79 |
+
</config>
|
app/etc/modules/Magebeam_EasyOrderDeleter.xml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Magebeam
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* It is available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
*
|
| 12 |
+
* DISCLAIMER
|
| 13 |
+
*
|
| 14 |
+
* Do not edit or add to this file if you wish to upgrade this package
|
| 15 |
+
* to newer versions in the future.
|
| 16 |
+
*
|
| 17 |
+
* @category Magebeam
|
| 18 |
+
* @package Magebeam_EasyOrderDeleter
|
| 19 |
+
* @copyright Copyright (c) 2012 Magebeam (http://www.magebeam.com)
|
| 20 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 21 |
+
*/
|
| 22 |
+
-->
|
| 23 |
+
<config>
|
| 24 |
+
<modules>
|
| 25 |
+
<Magebeam_EasyOrderDeleter>
|
| 26 |
+
<active>true</active>
|
| 27 |
+
<codePool>community</codePool>
|
| 28 |
+
</Magebeam_EasyOrderDeleter>
|
| 29 |
+
</modules>
|
| 30 |
+
</config>
|
app/locale/en_US/Magebeam_EasyOrderDeleter.csv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
"The order has been deleted.","The order has been deleted."
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Magebeam_EasyOrderDeleter</name>
|
| 4 |
+
<version>0.1.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary><b>Magebeam EasyOrderDeleter</b> gives the store owner ability to easly delete any order from the store.</summary>
|
| 10 |
+
<description><b>Magebeam EasyOrderDeleter</b> is small but useful utility that can delete any order in back office from order edit page .</description>
|
| 11 |
+
<notes>Public release</notes>
|
| 12 |
+
<authors><author><name>Magebeam</name><user>magebeam</user><email>team@magebeam.com</email></author></authors>
|
| 13 |
+
<date>2013-01-24</date>
|
| 14 |
+
<time>09:23:36</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="Magebeam"><dir name="EasyOrderDeleter"><dir name="Helper"><file name="Data.php" hash="a93fcc152127e3b9da7614ba4dd409fb"/></dir><dir name="Model"><file name="Deleter.php" hash="593dbadaf5de15e617c4c37a946e6d4e"/><file name="Observer.php" hash="50a55718b6f850e0a9953f52f7f4cc9c"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><file name="OrderController.php" hash="2bf51b971a811fb8622bf53349eeea17"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="c709cddff4b4b026841079b06a2d9720"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magebeam_EasyOrderDeleter.xml" hash="53f7c9fff01f291470a27389e9a457c0"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Magebeam_EasyOrderDeleter.csv" hash="f1861203b0d53761347a523f1f72032c"/></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
+
</package>
|
