Search code examples
magentomagento-soap-api

Get simple product sku and qty using salesOrderInfo of SOAP API in magento


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


Solution

  • 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.