what will be in Magento 2.2 code of this?
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
Hi @bbbmishucs
Well you need to use,\Magento\Sales\Api\Data\OrderInterface.
/** @var \Magento\Sales\Api\Data\OrderInterface $order **/ protected $order; public function __construct( \Magento\Sales\Api\Data\OrderInterface $order, ...... ) { $this->order = $order; }
After that to load order object by increment id , you required to use below syntax :
$this->order->loadByIncrementId($orderId);
for more details refer this link - https://magento.stackexchange.com/questions/140374/magento-2-1-1-how-to-load-order-with-increment-id...
https://mage2.pro/t/topic/1561
Hope it helps !
Hello @Manthan Dave
Thank you for your answer.
But I need more details. I'm converting a Magento 1.9 extension to 2.2 extensions. Can you help me out?
If possible to help me in person it will be better for me.
Hi @bbbmishucs
You can use by inject \Magento\Sales\Api\Data\OrderInterface in construct. Add this below code
protected $order; public function __construct( \Magento\Sales\Api\Data\OrderInterface $order, ...... ) { $this->order = $order; }
Then , Load order object by increment id :
$this->order->loadByIncrementId($orderId); //$this->order->loadByIncrementId('123456');
Remove generation folder and clean cache.
Hope, It will helpful for you.
If issue solved , Click Kudos & Accept as Solution
You can refer below links,
For getting order by increment id,
For getting Order by order id,
https://www.rakeshjesadiya.com/how-to-get-order-data-by-order-id-programatically-in-magento-2/
For create order programmatically,
https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/