Get Order Increment Id in Magento
If you're specifically doing this on the checkout success page - in success.phtml - then the code to get the order increment ID is already available in the template, since it is displayed to the customer.
You just need the following:
$orderId = $this->getOrderId();
Note that this won't work on other pages so, for those, you'd need to use:
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
Magento - get order id from increment id
If you want to fetch only order_id then simply use mysql query, if you want order_id in for loop, it is not load entire order object and it is very quick and fast, you don't need to load order object model.
$write = Mage::getSingleton('core/resource')->getConnection('core_read');
$result=$write->query("SELECT entity_id FROM `sales_flat_order` WHERE `increment_id` = 'your increment id' ");
$row = $result->fetch();
echo $row['entity_id'];
How to get order increment id using order id?
$order = Mage::getModel('sales/order')->load($orderid);
$Incrementid = $order->getIncrementId();
Getting Shipment Increment ID by Order ID in Magento via SOAP
Using default methods of soap you wouldn't be able to get shipment id by order id. For this you need to override Mage/Sales/Model/Order/Shipment/Api.php and extend the method as mentioned below.
In app/code/local/Namespace/Modulename/etc/config.xml
<models>
<sales>
<rewrite>
<order_shipment_api>Namespace_Modulename_Model_Sales_Order_Shipment_Api</order_shipment_api>
</rewrite>
</sales>
</models>
Now create a method in app/code/local/Namespace/Modulename/Model/Sales/Order/Shipment/Api.php
class Namespace_Modulename_Model_Sales_Order_Shipment_Api extends Mage_Sales_Model_Order_Shipment_Api
{
/**
* Retrieve shipment information
*
* @param string $shipmentIncrementId
* @return array
*/
public function info($id, $attribute = null)
{
if(!empty($attribute)){
$ids = Mage::getModel('sales/order_shipment')->getCollection()
->addAttributeToFilter($attribute, $id)
->getAllIds();
if (!empty($ids)) {
reset($ids);
$shipment = Mage::getModel('sales/order_shipment')->load(current($ids));
}
}else{
$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($id);
}
/* @var $shipment Mage_Sales_Model_Order_Shipment */
if (!$shipment->getId()) {
$this->_fault('not_exists');
}
$result = $this->_getAttributes($shipment, 'shipment');
$result['items'] = array();
foreach ($shipment->getAllItems() as $item) {
$result['items'][] = $this->_getAttributes($item, 'shipment_item');
}
$result['tracks'] = array();
foreach ($shipment->getAllTracks() as $track) {
$result['tracks'][] = $this->_getAttributes($track, 'shipment_track');
}
$result['comments'] = array();
foreach ($shipment->getCommentsCollection() as $comment) {
$result['comments'][] = $this->_getAttributes($comment, 'shipment_comment');
}
return $result;
}
}
Now you can call this Soap method to get shipment info (including shipment id)
$result = $this->_client->salesOrderShipmentInfo($sessionId, $orderId, 'order_id');
var_dump($result);
Magento 2 : How to get order id in guest checkout before success page?
$this->_checkoutSession->getQuote()->reserveOrderId();
$order = $this->_checkoutSession->getQuote()->getReservedOrderId();
Get the Increment Id in to observer after saving the sales order?
It's already assigned to the order at this point, so you can get it like this:
$incrementId = $observer->getOrder()->getIncrementId();
Explanation:
- The increment id gets assigned in
Mage_Sales_Model_Order::_beforeSave()
"order" is a parameter of the event, so that you can use
$observer->getOrder()
which is actually a shortcut for$observer->getEvent()->getData('order')
. The name of the parameter for the "before_save" and "after_save" events is defined in the$_eventObject
property of the model class:protected $_eventObject = 'order';
How to get Shipment Increment ID by Order ID in Magento
In theory an order can have more than one shipment. But if you make a convention to always have one single shipment per order you can get its increment id like this:
$orderIncrementId = 120000012;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$shipment = $order->getShipmentsCollection()->getFirstItem();
$shipmentIncrementId = $shipment->getIncrementId();
Related Topics
Strip HTML Tags and Its Contents
Jquery UI Saving Sortable List
Cakephp Cake_Core_ Cache Was Unable to Write 'Cake_Dev_En-Us'
How to Count the Consecutive Duplicate Values in an Array
Maximum Length of Generated Hash When Using Password_Hash
PHP Function to Replace a (I)Th-Position Character
Warning Problem: Expects Parameter 1 to Be MySQLi_Result
Do I Need a Trailing Semicolon Here
How to Determine the Extension(S) Associated with a Mime Type in PHP
Redirect to 'Www' Before Ssl Requirement
PHP - Fastest Way to Check Presence of Text in Many Domains (Above 1000)
How to Execute MySQL Command Delimiter
Convert This String to Timestamp PHP