Php 如何解决运费计算问题?

Php 如何解决运费计算问题?,php,Php,我尝试使用下面这个元素的保存结果来计算postcanada中的比率 由于我的coe codre返回此错误,您是否有办法解决此元素 多谢各位 Fatal error: Uncaught Exception: <?xml version="1.0" encoding="UTF-8"?> <messages xmlns="http://www.canadapost.ca/ws/messages"> <message> <code>Server</c

我尝试使用下面这个元素的保存结果来计算postcanada中的比率

由于我的coe codre返回此错误,您是否有办法解决此元素

多谢各位

Fatal error: Uncaught Exception: <?xml version="1.0" encoding="UTF-8"?> <messages xmlns="http://www.canadapost.ca/ws/messages"> <message> <code>Server</code> <description>/rs/ship/price: cvc-simple-type 1: element {http://www.canadapost.ca/ws/ship/rate-v3}weight with anonymous type may not be empty</description></message></messages> : 400 in /home/www/clicshopping_test_ui/boutique/ext/api/canadaPost/class.CanadaPost.php on line 176
原始代码

$result = new CanadaPostShipment(
      array(
         'destination' => array('domestic' => array('postal-code' => $origin)),
    'origin-postal-code' => $destination,
    'parcel-characteristics' => array(
      'weight' => round((float)$total_weight, 2), // kg
      'dimensions' => array(
        'width' => round((float)$total_width, 2),
        'length' => round((float)$total_length, 2),
        'height' => round((float)$total_height, 2),
      )
    )
  )
);
新代码(包括一些产品)

foreach($products\u数组为$value){
$weight[]=$value['weight'];
$quantity[]=$value['quantity'];
$products\u dimension\u width[]=$value['products\u dimension\u width'];
$products\u dimension\u height[]=$value['products\u dimension\u height'];
$products\u dimension\u depth[]=$value['products\u dimension\u depth'];
对于($i=0;$i数组(
“国内”=>阵列(
“邮政编码”=>$origin
)
),
“来源邮政编码”=>$destination,
“地块特征”=>array('weight'=>weight[$i],//kg
“维度”=>数组(
“宽度”=>$products\u dimension\u width[$i],
“长度”=>$products\u dimension\u height[$i],
“高度”=>$products\u dimension\u depth[$i],
)
)
);
$result1=新的CanadaPostShipping($product);
$result[]=$cp->getRates($result1);
}
}
  foreach ($products_array as $value) {
    $weight[] = $value['weight'];
    $quantity[] = $value['quantity'];
    $products_dimension_width[] = $value['products_dimension_width'];
    $products_dimension_height[] = $value['products_dimension_height'];
    $products_dimension_depth[] = $value['products_dimension_depth'];

    for ($i = 0; $i < count($products_array); $i++) {
      $product =  array(
        'destination' => array(
          'domestic' => array(
            'postal-code' => $origin
          )
        ),
        'origin-postal-code' => $destination,
        'parcel-characteristics' => array('weight' => $weight[$i], // kg
                                          'dimensions' => array(
                                                                'width' => $products_dimension_width[$i],
                                                                'length' => $products_dimension_height[$i],
                                                                'height' => $products_dimension_depth[$i],
                                                              )
                                          )
        );

      $result1 = new CanadaPostShipment($product);
      $result[] = $cp->getRates($result1);
    }
  }