我在将数组转换为xml时遇到问题,因为CustomerOrderLines正在重复,生成的xml只获取最后一个[CustomerOrderLines]值,如何生成包含所有对象的xml。
public function ProcessOrderAction(){
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerAddress = array();
$_orders = Mage::getModel('sales/order')->getCollection()- >addFieldToFilter('customer_id',$customerData->getId());
$_orderCnt = $_orders->count(); //orders count
if($_orderCnt == 0){
$CustomerOperation="Create";
}else{
$CustomerOperation="Find";
}
$soapClient = new SoapClient("https://api.ongoingsystems.se/Colliflow/service.asmx?wsdl", array('trace' => 1));
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$store = Mage::app('checkout/session')->getStore();
$ap_param = array(
'GoodsOwnerCode'=>'Test',
'UserName' => 'test',
'Password' => 'test',
'co'=> [
'OrderInfo'=>[
'OrderIdentification' => 'SystemId',
'OrderOperation' => 'Create',
'GoodsOwnerOrderNumber' => '1111',
'OrderId' => '',
'GoodsOwnerOrderId' => '102',
'DeliveryDate' => '2016-05-14T22:16:00',
'OrderType'=> [
'OrderTypeOperation' => 'CreateOrFind',
'OrderTypeIdentification' => 'OrderTypeCode'
]
],
'Customer'=> [
'CustomerOperation' => $CustomerOperation,
'CustomerIdentification' => 'CustomerNumber',
'ExternalCustomerCode' => 'ExternalCustomerCode',
'CustomerNumber' => ''.$customerData->getId(),
'CustomerId' => ''.$customerData->getId(),
'Name' => ''.$customerData->getName(),
'Address' => ''.$customerAddress['region'],
'PostCode' => ''.$customerAddress['postcode'],
'City' => ''.$customerAddress['city'],
'TelePhone' => ''.$customerAddress['telephone'],
'Remark' => 'Remarks',
'IsVisible'=>'true',
'NotifyBySMS'=> 'true',
'NotifyByEmail'=> 'false',
'NotifyByTelephone'=>'false',
'Email' => ''.$customerData->getEmail(),
'MobilePhone' => ''.$customerAddress['telephone'],
'CountryCode' =>'NO',
'CountryStateCode' => '90'
],
'CustomerOrderLines' => [
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '123',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '123',
'ArticleNumber' => ''.$item->getSku(),
'ArticleName' => ''.$item->getName(),
'NumberOfItems' => '6',
'ProductCode' => ''.$item->getProductId()
],
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '1231',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '1230',
'ArticleNumber' => '0000099',
'ArticleName' => 'test222',
'NumberOfItems' => '6',
'ProductCode' => '6786978'
]
]
]
);
print_r($ap_param);
$error = 0;
try {
$info = $soapClient->__call("ProcessOrder", array($ap_param));
}catch (SoapFault $fault) {
$error = 1;
print("
alert('Sorry, returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
window.location = 'main.php'; ");
}
if ($error == 0) {
$auth_num = $info->ProcessOrderResult;
print_r($auth_num);
}
}