通过php foreach从SOAP中提取值

时间:2014-03-21 18:18:35

标签: php soap

我目前有以下数据:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
    <PremiumsByVinResponse xmlns="http://tempuri.org/">
        <PremiumsByVinResult xmlns:a="http://schemas.datacontract.org/2004/07/ElevenVander.Api.Generic" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:Error i:nil="true"/>
            <a:GAPRates/>
            <a:VSCRates>
                <a:VSCPremium>
                    <a:DeductibleAmount>100</a:DeductibleAmount>
                    <a:DeductibleType>STANDARD</a:DeductibleType>
                    <a:Plan>PLAN B: EXCLUSIONARY</a:Plan>
                    <a:ProductCategory>NEW</a:ProductCategory>
                    <a:ProductName>Vehicle Service Contracts Roadside SELF</a:ProductName>
                    <a:RateCode>V315128R669847D1</a:RateCode>
                    <a:RetailPrice>1124</a:RetailPrice>
                    <a:Surcharges/>
                    <a:TermMiles>60000</a:TermMiles>
                    <a:TermMonths>60</a:TermMonths>
                </a:VSCPremium>

这是5000多行VSCPremium

值如下:

Customer:   TIM TEST

车辆:1C4NJDBBXED641679 / 2014 / JEEP / COMPASS

stdClass的 (   [VSCPremium] =&gt;排列     (       [0] =&gt; stdClass的         (           [DeductibleAmount] =&gt; 100           [DeductibleType] =&gt;标准           [计划] =&gt; B计划:排他性           [ProductCategory] ​​=&gt;新           [ProductName] =&gt;车辆服务合同路边SELF           [RateCode] =&gt; V315128R669847D1           [RetailPrice] =&gt; 1124           [附加费] =&gt; stdClass的             (             )           [TermMiles] =&gt; 60000           [TermMonths] =&gt; 60         )

这只是信息的一小部分

我目前需要更新的代码以提取信息如下:

function RU_ProcessRates($rates) {
    $converted_rates = Array();
        //printPre($rates,1);
        if(!empty($rates)) {
            if(!empty($rates->PremiumsByVinResult->Vehicle)) {
                $vehicleInfo = json_decode(json_encode($rates->PremiumsByVinResult->Vehicle),1);
            }
            if(is_object($rates->PremiumsByVinResult->VSCRates)) {
               $rates->PremiumsByVinResult->VSCRates = array($rates->PremiumsByVinResult->VSCRates);
            }
            if(is_object($rates->PremiumsByVinResult->GAPRates)) {
               $rates->PremiumsByVinResult->GAPRates = array($rates->PremiumsByVinResult->GAPRates);
            }
            if(is_object($rates->PremiumsByVinResult->WarrantyRates)) {
               $rates->PremiumsByVinResult->WarrantyRates = array($rates->PremiumsByVinResult->WarrantyRates);
            }

            foreach($rates->PremiumsByVinResult->VSCRates as $rate) {
                /* TODO: Add surcharge support
                $surcharge = !empty($rate->Surcharges) ? (array)  json_decode(json_encode($rate->Surcharges->Surcharge),true) : array();
                if(!empty($surcharge) && empty($surcharge[0])) {
                    $surcharge[] = $surcharge;
                    unset($surcharge['Code']);
                    unset($surcharge['NetDealerCost']);
                    unset($surcharge['RetailPrice']);
                }*/
                $rate->vehicleInfo = $vehicleInfo;
                //printPre ($rate,1);
                $converted_rates[] = Array(
                       'rate_id'                         => $rate->RateCode, //$rate->RateDetailId, //$deductible->RateDetailId,  //This does not seem correct
                       'hierarchy'                       => '',
                       'Miles'                           => $rate->TermMiles * 1000,
                       'Term'                            => $rate->TermMonths,
                       'DeductibleCode'                  => $rate->ProductName, //$rate->DeductibleAmount, //This does not seem correct
                       'DeductibleDescription'           => $rate->DeductibleType,
                       'RetailPrice'                     => number_format($rate->RetailPrice,2,'.',''),
                       'RateCost'                        => number_format($rate->NetDealerCost,2,'.',''),
                       'DealerShowCost'                  => number_format($rate->NetDealerCost,2,'.',''),
                       'type'                            => $rate->ContractPrefix,
                       'type_desc'                       => $rate->Plan, //$rate->CoverageName,
                       'CoverageName'                    => $rate->Plan, //$rate->CoverageName,
                       'CoverageDescription'             => $rate->Plan, //$rate->CoverageName,
                       'plan'                            => null,
                       'plan_desc'                       => null,
                       'DMS_mapping'                     => false,
                       'IP_markup'                       => false,
                       'IP_dc'                           => false,
                       'rate_source_data'                => (array) $rate,
                       'rate_options_array'              => Array(),
                       //'Surcharges'                        => $surcharge,
                       'rate_additional_fields'          => Array()
                     );
            }
        } else {
            return false;
        }
        return $converted_rates;
    return json_decode(json_encode($rates),true);
}

如果我能找出&#39; rate_id =&gt; $ rate-&gt; RateCode,那么我应该能够轻松地完成其余的工作......

很抱歉这么乱......这个任务被抛到我的肩膀上,几乎没有解释我在这里开始工作之前完成了类似的任务......

0 个答案:

没有答案