问题
I have added following code in the
/app/code/core/Mage/Sales/Model/Order/Api.php
File.
public function info($orderIncrementId)
{
------
-------
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
// get order total value
$orderValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
// get order item collection
$orderItems = $order->getItemsCollection();
$skuQtyArray = array();
foreach ($orderItems as $item)
{
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$product_qty = $item->getQtyOrdered();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0]; // just grab the first id
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);
$productType=$product->getTypeID();
if($productType=='simple')
{
$skuQtVal = $product_sku."=".$product_qty;
$skuQtyArray[] = $skuQtVal;
}
}
$result['simple_product_skus'] = $skuQtyArray;
Mage::log($skuQtyArray,null,"logTest.txt",true);
return $result;
}
But when I run following code in the application root
<?php
$client = new SoapClient('localhost/magento/index.php/api/v2_soap/index?wsdl=1');
$session = $client->login('testuser', 'testuser');
$result = $client ->salesOrderInfo($session, '100000026');
print_r($result);
?>
I am not getting the changes which I did.
Please suggest some solution.
edited:
My directory structure to override the core code is as following.
I my Overridden Api.php, I am using like this.
class Sigma_Sales_Model_Order_Api extends Mage_Sales_Model_Order_Api
Got it: I need to override like this
class Sigma_Sales_Model_Order_Api_V2 extends Mage_Sales_Model_Order_Api_V2
Because:- Mage_Sales_Model_Order_Api_V2 extends Mage_Sales_Model_Order_Api
回答1:
Muk, you have to go to app\code\core\Mage\Sales\etc and modify wsdl.xml and wsi.xml and add the element for sku or whatever you want as per your requirement.
<element name="sku" type="xsd:string" minOccurs="0" /> //in wsdl.xml
<xsd:element name="sku" type="xsd:string" minOccurs="0" /> //wsi.xml
if you don't want to modify core file than you have to override it.
回答2:
First correction is on
/app/code/core/Mage/Sales/Model/Order/Api.php
from:
$orderValue = number_format ($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
try to remove the space after number_format
to:
$orderValue = number_format($order->getGrandTotal(), 2, '.' , $thousands_sep = '');
Second is check the Order Increment ID, is it exist?
Third is check on var/log/logTest.txt, what's the value $skuQtyArray?
if you are only add that function, it must be correct now.
My suggestion is do not overwrite core, because Magento is often to upgrade the version, you'll be confused if you want to upgrade it.
来源:https://stackoverflow.com/questions/19811307/get-simple-product-sku-and-qty-using-salesorderinfo-of-soap-api-in-magento