如何解决运费的费率计算?

时间:2016-07-10 00:48:25

标签: 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</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_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);
    }
  }

0 个答案:

没有答案