1.首先有准备好的短信接口,能够使用
2.监听订单发货事件
*在对应的config.xml中加入订单发货监听时间:
<adminhtml>
<events>
<sales_order_shipment_save_after>
<observers>
<boc_receiveorder>
<type>singleton</type>
<class>boc/observer</class>
<method>sendShippmentMessage</method>
</boc_receiveorder>
</observers>
</sales_order_shipment_save_after>
</events>
</adminhtml>
*从订单中获取订单的发货地址,从发货地址中获取发货详细信息:
public function sendShippmentMessage(Varien_Event_Observer $observer){
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$orderIncrementId = $order->getIncrementId();
// $orderDetail = Mage::getModel('sales/order')->load($orderIncrementId);
$orders = Mage::getModel('sales/order')->getCollection();
$orders->addAttributeToFilter('increment_id', $orderIncrementId);
$orders->addAttributeToSelect('*');
$orders->load();
$alldata = $orders->getData();
foreach($alldata as $alldatas){
// $grand_total = $alldatas['grand_total'];
// $increment_id = $alldatas['increment_id'];
$shipping_address_id = $alldatas['shipping_address_id'];
}
/*order address*/
$address = Mage::getModel('sales/order_address')->getCollection();
$address->addAttributeToFilter('entity_id', $shipping_address_id);
$address->addAttributeToSelect('*');
$address->load();
$address_alldata = $address->getData();
foreach($address_alldata as $address_alldatas){
// $street = $address_alldatas['street'];
// $postCode = $address_alldatas['postcode'];
$telephone = $address_alldatas['telephone'];
// $cn_name = $address_alldatas['cn_name'];
// $provinceId = $address_alldatas['cn_province'];
// $cityId = $address_alldatas['cn_city'];
// $districtId = $address_alldatas['cn_district'];
// $city = Mage::getModel('cnregion/city')->load($cityId)->getName();
// $district = Mage::getModel('cnregion/district')->load($districtId)->getName();
// $provinceModel = Mage::getModel('cnregion/province')->load($provinceId);
// $province = $provinceModel->getName();
}
if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$telephone)){
$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($order)
->load();
foreach ($shipmentCollection as $shipment){
foreach($shipment->getTracksCollection() as $tracknum)
{
$tracknums=$tracknum->getNumber();//获取运单号
$tracktitles=$tracknum->getTitle();//获取运单名称
}
}
}
}