cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 to Magento 2.2 code conversion

Magento 1.9 to Magento 2.2 code conversion

what will be in Magento 2.2 code of this?

$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);

 

 

4 REPLIES 4

Re: Magento 1.9 to Magento 2.2 code conversion

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 !

if issue solved,Click Kudos & Accept as Solution

Re: Magento 1.9 to Magento 2.2 code conversion

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. 

Smiley Happy 

Re: Magento 1.9 to Magento 2.2 code conversion

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

Re: Magento 1.9 to Magento 2.2 code conversion

You can refer below links,

For getting order by increment id,

https://www.rakeshjesadiya.com/how-to-get-programmatically-order-data-by-order-increment-id-in-magen...

 

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/

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial