How to get shipping method title in sales_order_save event?
-
16-10-2019 - |
Question
How can I get shippingMethod Title in mage/sales/model/Order.php, in function _beforeSave() ? Actually I have to set label for Shipping Description.
Solution
if you have the order object you can get the shipping description
$order = $observer->getEvent()->getOrder(); // or where ever the order is located in your observer event
echo $order->getShippingDescription();
Or optionally if you want all the shipping method data you should be able to retrieve it via
$shipping = $order->getShippingAddress()->getShippingMethod();
var_dump($shipping->getData());
OTHER TIPS
$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
$options = array();
foreach($methods as $_code => $_method)
{
if(!$_title = Mage::getStoreConfig("carriers/$_code/title"))
$_title = $_code;
$options[] = array('value' => $_code, 'label' => $_title . " ($_code)");
}
echo "<xmp>";
print_r($options);
echo "</xmp>";
This worked for me when looking for the custom title:
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$shippingTitle = $order->getTracksCollection()->getFirstItem()->getTitle();
$order->getShippingDescription(); // returns Shipping Method Title
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange