Magento 1.9 to Magento 2.2 code conversion
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
what will be in Magento 2.2 code of this?
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
magento2 orders
add a comment |Â
up vote
1
down vote
favorite
what will be in Magento 2.2 code of this?
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
magento2 orders
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
what will be in Magento 2.2 code of this?
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
magento2 orders
what will be in Magento 2.2 code of this?
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
magento2 orders
edited Aug 13 at 7:00
Amit Beraâ¦
53.3k1365156
53.3k1365156
asked Aug 13 at 6:59
alaminmishu
112
112
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
use Magento Order factory Class.
MagentoSalesModelOrderFactory
First, you have to inject this class to __construct()
of your class where you want to use.
Then you can get order details using factory class below code:
protected $orderFactory;
public function __construct(
....
MagentoSalesModelOrderFactory $orderFactory
.....
)
$this->orderFactory = $orderFactory;
public function getOrderBYIncrementId()
$orderIncrementID = 10000250;
$orderModel = $this->orderFactory->create();
$orderModel->loadByIncrementId($orderIncrementID);
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
add a comment |Â
up vote
1
down vote
namespace VendorModuleBlock;
class BlockName extends MagentoFrameworkViewElementTemplate
protected $orderRepository;
protected $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data =
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
public function getOrderById($id)
return $this->orderRepository->get($id);
public function getOrderByIncrementId($incrementId)
$this->searchCriteriaBuilder->addFilter('increment_id', $incrementId);
$order = $this->orderRepository->getList($this->searchCriteriaBuilder->create())->getItems();
return $order;
add a comment |Â
up vote
1
down vote
use this for M2
protected $order;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
)
$this->order = $order;
public function getOrder()
$orderId = 10000003;
$order = $this->order->loadByIncrementId($orderId);
Or
protected $orderFactory;
public function __construct(
MagentoSalesModelOrderFactory $orderFactory,
)
$this->orderFactory = $orderFactory;
public function getOrder()
$orderId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
use Magento Order factory Class.
MagentoSalesModelOrderFactory
First, you have to inject this class to __construct()
of your class where you want to use.
Then you can get order details using factory class below code:
protected $orderFactory;
public function __construct(
....
MagentoSalesModelOrderFactory $orderFactory
.....
)
$this->orderFactory = $orderFactory;
public function getOrderBYIncrementId()
$orderIncrementID = 10000250;
$orderModel = $this->orderFactory->create();
$orderModel->loadByIncrementId($orderIncrementID);
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
add a comment |Â
up vote
1
down vote
use Magento Order factory Class.
MagentoSalesModelOrderFactory
First, you have to inject this class to __construct()
of your class where you want to use.
Then you can get order details using factory class below code:
protected $orderFactory;
public function __construct(
....
MagentoSalesModelOrderFactory $orderFactory
.....
)
$this->orderFactory = $orderFactory;
public function getOrderBYIncrementId()
$orderIncrementID = 10000250;
$orderModel = $this->orderFactory->create();
$orderModel->loadByIncrementId($orderIncrementID);
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
add a comment |Â
up vote
1
down vote
up vote
1
down vote
use Magento Order factory Class.
MagentoSalesModelOrderFactory
First, you have to inject this class to __construct()
of your class where you want to use.
Then you can get order details using factory class below code:
protected $orderFactory;
public function __construct(
....
MagentoSalesModelOrderFactory $orderFactory
.....
)
$this->orderFactory = $orderFactory;
public function getOrderBYIncrementId()
$orderIncrementID = 10000250;
$orderModel = $this->orderFactory->create();
$orderModel->loadByIncrementId($orderIncrementID);
use Magento Order factory Class.
MagentoSalesModelOrderFactory
First, you have to inject this class to __construct()
of your class where you want to use.
Then you can get order details using factory class below code:
protected $orderFactory;
public function __construct(
....
MagentoSalesModelOrderFactory $orderFactory
.....
)
$this->orderFactory = $orderFactory;
public function getOrderBYIncrementId()
$orderIncrementID = 10000250;
$orderModel = $this->orderFactory->create();
$orderModel->loadByIncrementId($orderIncrementID);
edited Aug 13 at 7:08
answered Aug 13 at 7:02
Amit Beraâ¦
53.3k1365156
53.3k1365156
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
add a comment |Â
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
It's kind of Magento 1 style used in Magento 2. Correct one - use repository for getting order
â Ihor Sviziev
Aug 14 at 4:14
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
ihor donot think the factory is wrong. Chosen between repository and factory is user call
â Amit Beraâ¦
Aug 14 at 7:20
add a comment |Â
up vote
1
down vote
namespace VendorModuleBlock;
class BlockName extends MagentoFrameworkViewElementTemplate
protected $orderRepository;
protected $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data =
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
public function getOrderById($id)
return $this->orderRepository->get($id);
public function getOrderByIncrementId($incrementId)
$this->searchCriteriaBuilder->addFilter('increment_id', $incrementId);
$order = $this->orderRepository->getList($this->searchCriteriaBuilder->create())->getItems();
return $order;
add a comment |Â
up vote
1
down vote
namespace VendorModuleBlock;
class BlockName extends MagentoFrameworkViewElementTemplate
protected $orderRepository;
protected $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data =
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
public function getOrderById($id)
return $this->orderRepository->get($id);
public function getOrderByIncrementId($incrementId)
$this->searchCriteriaBuilder->addFilter('increment_id', $incrementId);
$order = $this->orderRepository->getList($this->searchCriteriaBuilder->create())->getItems();
return $order;
add a comment |Â
up vote
1
down vote
up vote
1
down vote
namespace VendorModuleBlock;
class BlockName extends MagentoFrameworkViewElementTemplate
protected $orderRepository;
protected $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data =
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
public function getOrderById($id)
return $this->orderRepository->get($id);
public function getOrderByIncrementId($incrementId)
$this->searchCriteriaBuilder->addFilter('increment_id', $incrementId);
$order = $this->orderRepository->getList($this->searchCriteriaBuilder->create())->getItems();
return $order;
namespace VendorModuleBlock;
class BlockName extends MagentoFrameworkViewElementTemplate
protected $orderRepository;
protected $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data =
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
public function getOrderById($id)
return $this->orderRepository->get($id);
public function getOrderByIncrementId($incrementId)
$this->searchCriteriaBuilder->addFilter('increment_id', $incrementId);
$order = $this->orderRepository->getList($this->searchCriteriaBuilder->create())->getItems();
return $order;
edited Aug 13 at 7:19
answered Aug 13 at 7:13
Evince Development
558112
558112
add a comment |Â
add a comment |Â
up vote
1
down vote
use this for M2
protected $order;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
)
$this->order = $order;
public function getOrder()
$orderId = 10000003;
$order = $this->order->loadByIncrementId($orderId);
Or
protected $orderFactory;
public function __construct(
MagentoSalesModelOrderFactory $orderFactory,
)
$this->orderFactory = $orderFactory;
public function getOrder()
$orderId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
add a comment |Â
up vote
1
down vote
use this for M2
protected $order;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
)
$this->order = $order;
public function getOrder()
$orderId = 10000003;
$order = $this->order->loadByIncrementId($orderId);
Or
protected $orderFactory;
public function __construct(
MagentoSalesModelOrderFactory $orderFactory,
)
$this->orderFactory = $orderFactory;
public function getOrder()
$orderId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
add a comment |Â
up vote
1
down vote
up vote
1
down vote
use this for M2
protected $order;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
)
$this->order = $order;
public function getOrder()
$orderId = 10000003;
$order = $this->order->loadByIncrementId($orderId);
Or
protected $orderFactory;
public function __construct(
MagentoSalesModelOrderFactory $orderFactory,
)
$this->orderFactory = $orderFactory;
public function getOrder()
$orderId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
use this for M2
protected $order;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
)
$this->order = $order;
public function getOrder()
$orderId = 10000003;
$order = $this->order->loadByIncrementId($orderId);
Or
protected $orderFactory;
public function __construct(
MagentoSalesModelOrderFactory $orderFactory,
)
$this->orderFactory = $orderFactory;
public function getOrder()
$orderId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderId);
edited Aug 13 at 8:21
answered Aug 13 at 7:02
Addify
593
593
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
add a comment |Â
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
If you pass order to constructor two times per request - it will be shared. It's not expected behavior. So I can't recommend to use first variant, second is better, but correct one - load via repository.
â Ihor Sviziev
Aug 14 at 4:13
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f238131%2fmagento-1-9-to-magento-2-2-code-conversion%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password