通过重量获取所有可能的快递方式,可以做成接口,代码片段
<?php ini_set('display_errors', 1); header('Content-Type: text/html; charset=utf-8'); include 'app/Mage.php'; Mage::app(); $request = Mage::getModel('shipping/rate_request') ->setPackageWeight(1000)//这里填写重量 ->setConditionName('package_weight') ->setDestCountryId('US')//这里填写送货国家,如果有地区、邮编也可以设定 ->setWebsiteId(Mage::app()->getStore(true)->getWebsite()->getId()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); if ($result) { $shippingRates = $result->getAllRates(); foreach ($shippingRates as $shippingRate) { //Exclude Custom Method if(!$shippingRate->getPrice()){ continue; } print_r($shippingRate->getData()); } }
输出结果
Array ( [carrier] => mycarrier [carrier_title] => Select Shipping Method [method] => mycarrier_81123 [method_title] => Registered Air Mail [cost] => 0.0000 [delivery_type] => Registered Air Mail [price] => 6.43 ) Array ( [carrier] => mycarrier [carrier_title] => Select Shipping Method [method] => mycarrier_81231 [method_title] => DHL [cost] => 0.0000 [delivery_type] => DHL [price] => 17.89 )