I am trying to override Sales/Model/Order/Api.php
file. but it going to core file. and i am getting that sales_order_api
in rewrite collection with below script
<?php
$folders = array('app/code/local/', 'app/code/community/');//folders to parse
$configFiles = array();
foreach ($folders as $folder){
$files = glob($folder.'*/*/etc/config.xml');//get all config.xml files in the specified folder
$configFiles = array_merge($configFiles, $files);//merge with the rest of the config files
}
$rewrites = array();//list of all rewrites
foreach ($configFiles as $file){
$dom = new DOMDocument;
$dom->loadXML(file_get_contents($file));
$xpath = new DOMXPath($dom);
$path = '//rewrite/*';//search for tags named 'rewrite'
$text = $xpath->query($path);
foreach ($text as $rewriteElement){
$type = $rewriteElement->parentNode->parentNode->parentNode->tagName;//what is overwritten (model, block, helper)
$parent = $rewriteElement->parentNode->parentNode->tagName;//module identifier that is being rewritten (core, catalog, sales, ...)
$name = $rewriteElement->tagName;//element that is rewritten (layout, product, category, order)
foreach ($rewriteElement->childNodes as $element){
$rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it
}
}
}
echo "<pre>";print_r($rewrites);
?>
Output is
Array
(
[models] => Array
(
[cataloginventory/stock_item_api_v2] => Array
(
[0] => Example_Webservices_Model_Cataloginventory_Api_V2
)
[sales/order_api] => Array
(
[0] => Example_Webservices_Model_Order_Api
)
[core_mysql4/session] => Array
(
[0] => Cm_RedisSession_Model_Session
)
)
)
The script is:
config.xml
:
<?xml version="1.0"?>
<config>
<modules>
<Example_Webservices>
<version>0.2.0</version>
</Example_Webservices>
</modules>
<frontend>
<routers>
<connector>
<use>standard</use>
<args>
<module>Example_Webservices</module>
<frontName>test</frontName>
</args>
</connector>
</routers>
</frontend>
<global>
<models>
<cataloginventory>
<rewrite>
<stock_item_api_v2>Example_Webservices_Model_Cataloginventory_Api_V2</stock_item_api_v2>
</rewrite>
</cataloginventory>
<sales>
<rewrite>
<order_api>Example_Webservices_Model_Order_Api</order_api>
</rewrite>
</sales>
</models>
</global>
Example/Webservices/Model/Order/Api.php
file:
<?php
class Example_Webservices_Model_Order_Api extends Mage_Sales_Model_Order_Api {
protected function _initOrder($orderIncrementId) {
$order = Mage::getModel('sales/order');
if(is_string($orderIncrementId)) {
$order->loadByIncrementId($orderIncrementId);
if (!$order->getId()) {
$this->_fault('not_exists');
}
} else {
$order->load($orderIncrementId);
if (!$order->getId()) {
$this->_fault('not_exists');
}
}
return $order;
}
public function cancel($orderIncrementId)
{
Mage::log("Canel Order",null,'cancel-order.log');
$order = $this->_initOrder($orderIncrementId);
if (Mage_Sales_Model_Order::STATE_CANCELED == $order->getState()) {
$this->_fault('status_not_changed');
}
try {
$order->cancel();
$order->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('status_not_changed', $e->getMessage());
}
if (Mage_Sales_Model_Order::STATE_CANCELED != $order->getState()) {
$this->_fault('status_not_changed');
}
return true;
}
}