本文介绍了如何获取返回值作为stdClass对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码来覆盖V2.php
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);
?>
输出就像
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
)
)
我想要simple_product_skus作为stdClass对象,就像我正在获取status_history一样.
I want simple_product_skus as stdClass Object Like I am getting status_history .
请问如何获得此帮助.
推荐答案
我认为这将为您提供所需的东西:
I think this will get you what you want:
$result['simple_product_skus'] = (object)array_unique($skuQtyArray);
这是将数组类型转换为标准php对象的类型.
This is type casting the array into a standard php object.
这篇关于如何获取返回值作为stdClass对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!