简体   繁体   中英

How to get the returned values as stdClass object

I am having following code to override V2.php

class Sigma_Sales_Model_Order_Api_V2 extends Mage_Sales_Model_Order_Api_V2
{
    public function info($orderIncrementId)
    {  
        $result = parent::info( $orderIncrementId ); 
        $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);       
        $orderItems = $order->getItemsCollection();

        $skuQtyArray = array();
        foreach ($orderItems as $item)
        {
              $product_id = $item->product_id;
             $product_sku = $item->sku;
                 $item_id = $item->getItemId();     
            $tax_percent = $item->gettaxPercent();                      
            $product_qty = $item->getQtyOrdered();                      

            $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);              
            $productType=$product->getTypeID();
            if($productType=='simple')
            {                                           
                    $skuQtVal = $product_sku."=".$item_id;
                    $skuQtyArray[] = $skuQtVal;                                 
            }
        }

    $result['simple_product_skus'] = array_unique($skuQtyArray);         

    return $result; 
    }

}

Now I am accessing this as

<?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);
?>

Output is like

 stdClass Object
 (
        ------
        ------
        ------

     [status_history] => Array
    (
        [0] => stdClass Object
            (
                [parent_id] => 72
                [created_at] => 2013-11-08 14:42:11
                [is_customer_notified] => 1
                [status] => pending
            )

    )

            [simple_product_skus] => Array
            (
                [0] => ASL-B346-67-64-98=155=166=1.0000=0.0000
                [1] => ASL-B346-67-64-98=156=116=1.0000=0.0000
            )

 )

I want simple_product_skus as stdClass Object Like I am getting status_history .

How can I get this please help.

I think this will get you what you want:

$result['simple_product_skus'] = (object)array_unique($skuQtyArray);

This is type casting the array into a standard php object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM