Magento 2.1.1 How to load Order with Increment ID using OrderRepository objectHow to load product by SKU in magento 2Deprecated save and load methods in Abstract ModelMagento 2: what are the benefits of using service contracts?How to Get order increment id using order id in Magento 2Magento 2: unable to set payment Transaction Id after successful payment processing (solved by myself)Fetch a specific model in magento 2What is the best method to retrieve a SINGLE ITEM order details in Magento2?Alphanumeric order increment id'sDuplicate Order Increment ID IssueEvent to use to fetch Order Id and not Increment IdCancelling an order is messing up the increment IDsjQuery optimized load for module, using only one file (layout)Mage sales order ::loadByIncrementId does not load orderHow to Get order increment id using order id in Magento 2Magento 2.1.1: How can we add Payment Information (custom payment) to an order?Magento 2 Can you get Order Increment id from Invoice Increment id?how to set order increment Id while creating order dynamically in magento 2
A Tale of Snake and Coffee
Basic power tool set for Home repair and simple projects
Are there any rules for identifying what spell an opponent is casting?
How can I detect if I'm in a subshell?
Does anyone recognize these rockets, and their location?
How can this shape perfectly cover a cube?
For Saintsbury, which English novelists constituted the "great quartet of the mid-eighteenth century"?
Why did the USA sell so many airplanes prior to WW2?
The last tree in the Universe
Does an African-American baby born in Youngstown, Ohio have a higher infant mortality rate than a baby born in Iran?
How to make a villain when your PCs are villains?
IIS LAN and WAN separate SSL certificates for the same server
Was the Lonely Mountain, where Smaug lived, a volcano?
Reflecting Telescope Blind Spot?
When is the phrase "j'ai bon" used?
How can I improve readability and length of a method with many if statements?
Does PC weight have a mechanical effect?
How to ask if I can mow my neighbor's lawn
Print the phrase "And she said, 'But that's his.'" using only the alphabet
How can religions without a hell discourage evil-doing?
How to sort human readable size
Converting 3x7 to a 1x7. Is it possible with only existing parts?
What does the output current rating from an H-Bridge's datasheet really mean?
How many times to repeat an event with known probability before it has occurred a number of times
Magento 2.1.1 How to load Order with Increment ID using OrderRepository object
How to load product by SKU in magento 2Deprecated save and load methods in Abstract ModelMagento 2: what are the benefits of using service contracts?How to Get order increment id using order id in Magento 2Magento 2: unable to set payment Transaction Id after successful payment processing (solved by myself)Fetch a specific model in magento 2What is the best method to retrieve a SINGLE ITEM order details in Magento2?Alphanumeric order increment id'sDuplicate Order Increment ID IssueEvent to use to fetch Order Id and not Increment IdCancelling an order is messing up the increment IDsjQuery optimized load for module, using only one file (layout)Mage sales order ::loadByIncrementId does not load orderHow to Get order increment id using order id in Magento 2Magento 2.1.1: How can we add Payment Information (custom payment) to an order?Magento 2 Can you get Order Increment id from Invoice Increment id?how to set order increment Id while creating order dynamically in magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
What would be the latest best practice to load Order using increment ID (instead of Order ID) using OrderRepository
magento2 module orders magento-2.1
add a comment |
What would be the latest best practice to load Order using increment ID (instead of Order ID) using OrderRepository
magento2 module orders magento-2.1
2
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
1
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58
add a comment |
What would be the latest best practice to load Order using increment ID (instead of Order ID) using OrderRepository
magento2 module orders magento-2.1
What would be the latest best practice to load Order using increment ID (instead of Order ID) using OrderRepository
magento2 module orders magento-2.1
magento2 module orders magento-2.1
edited Oct 12 '16 at 20:54
frostshoxx
asked Oct 12 '16 at 2:51
frostshoxxfrostshoxx
3501418
3501418
2
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
1
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58
add a comment |
2
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
1
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58
2
2
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
1
1
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58
add a comment |
2 Answers
2
active
oldest
votes
Magento 2 uses Service Contracts for retrieving and saving objects. In Magento this layer is formed by Repositories, which are managers with get()
and save()
methods. This keeps user code away from Model calls. Don't call model methods (like load()
or save()
or loadByIncrementId()
) directly, they are being deprecated as custom code should use the Service Contracts. Also, don't use the API from within Magento like Khoa is suggesting, it does not make sense. The API is for connecting Magento with other systems.
Inject OrderRepository and SearchCriteriaBuilder in your constructor:
private $orderRepository;
private $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
And in your function:
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001', 'eq')->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
// $orderList is now an array of Orders with this incrementId, which is just one order obviously
/** @var MagentoSalesModelOrder $order */
$order = $orderList[0];
// Your logic here
$order = $this->orderRepository->save($order);
Official Magento PHP Developer guide on magento.com
Code by Mulderea on github
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace$order = $orderList[0]
with$order = $orderList->getFirstItem()
to get the first (and only) item from the collection.
– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in$payment
Please check my problem here magento.stackexchange.com/questions/158935/…
– Ashish Raj
Feb 14 '17 at 9:20
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
add a comment |
As far as I know, we should use MagentoSalesApiDataOrderInterface
.
/** @var MagentoSalesApiDataOrderInterfaceFactory $order **/
protected $orderFactory;
public function __construct(
MagentoSalesApiDataOrderInterfaceFactory $orderFactory,
......
)
$this->orderFactory = $orderFactory;
Load order object by increment id:
$this->orderFactory->create()->loadByIncrementId('00001952-42');
[EDIT] should try with service contracts. Try Jacco's answer.
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
version 2.2.2, useMagentoSalesApiOrderRepositoryInterface
and itsget()
method
– LucScu
Mar 6 '18 at 14:41
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
|
show 6 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f140374%2fmagento-2-1-1-how-to-load-order-with-increment-id-using-orderrepository-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Magento 2 uses Service Contracts for retrieving and saving objects. In Magento this layer is formed by Repositories, which are managers with get()
and save()
methods. This keeps user code away from Model calls. Don't call model methods (like load()
or save()
or loadByIncrementId()
) directly, they are being deprecated as custom code should use the Service Contracts. Also, don't use the API from within Magento like Khoa is suggesting, it does not make sense. The API is for connecting Magento with other systems.
Inject OrderRepository and SearchCriteriaBuilder in your constructor:
private $orderRepository;
private $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
And in your function:
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001', 'eq')->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
// $orderList is now an array of Orders with this incrementId, which is just one order obviously
/** @var MagentoSalesModelOrder $order */
$order = $orderList[0];
// Your logic here
$order = $this->orderRepository->save($order);
Official Magento PHP Developer guide on magento.com
Code by Mulderea on github
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace$order = $orderList[0]
with$order = $orderList->getFirstItem()
to get the first (and only) item from the collection.
– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in$payment
Please check my problem here magento.stackexchange.com/questions/158935/…
– Ashish Raj
Feb 14 '17 at 9:20
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
add a comment |
Magento 2 uses Service Contracts for retrieving and saving objects. In Magento this layer is formed by Repositories, which are managers with get()
and save()
methods. This keeps user code away from Model calls. Don't call model methods (like load()
or save()
or loadByIncrementId()
) directly, they are being deprecated as custom code should use the Service Contracts. Also, don't use the API from within Magento like Khoa is suggesting, it does not make sense. The API is for connecting Magento with other systems.
Inject OrderRepository and SearchCriteriaBuilder in your constructor:
private $orderRepository;
private $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
And in your function:
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001', 'eq')->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
// $orderList is now an array of Orders with this incrementId, which is just one order obviously
/** @var MagentoSalesModelOrder $order */
$order = $orderList[0];
// Your logic here
$order = $this->orderRepository->save($order);
Official Magento PHP Developer guide on magento.com
Code by Mulderea on github
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace$order = $orderList[0]
with$order = $orderList->getFirstItem()
to get the first (and only) item from the collection.
– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in$payment
Please check my problem here magento.stackexchange.com/questions/158935/…
– Ashish Raj
Feb 14 '17 at 9:20
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
add a comment |
Magento 2 uses Service Contracts for retrieving and saving objects. In Magento this layer is formed by Repositories, which are managers with get()
and save()
methods. This keeps user code away from Model calls. Don't call model methods (like load()
or save()
or loadByIncrementId()
) directly, they are being deprecated as custom code should use the Service Contracts. Also, don't use the API from within Magento like Khoa is suggesting, it does not make sense. The API is for connecting Magento with other systems.
Inject OrderRepository and SearchCriteriaBuilder in your constructor:
private $orderRepository;
private $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
And in your function:
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001', 'eq')->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
// $orderList is now an array of Orders with this incrementId, which is just one order obviously
/** @var MagentoSalesModelOrder $order */
$order = $orderList[0];
// Your logic here
$order = $this->orderRepository->save($order);
Official Magento PHP Developer guide on magento.com
Code by Mulderea on github
Magento 2 uses Service Contracts for retrieving and saving objects. In Magento this layer is formed by Repositories, which are managers with get()
and save()
methods. This keeps user code away from Model calls. Don't call model methods (like load()
or save()
or loadByIncrementId()
) directly, they are being deprecated as custom code should use the Service Contracts. Also, don't use the API from within Magento like Khoa is suggesting, it does not make sense. The API is for connecting Magento with other systems.
Inject OrderRepository and SearchCriteriaBuilder in your constructor:
private $orderRepository;
private $searchCriteriaBuilder;
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoSalesModelOrderRepository $orderRepository,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder
)
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
And in your function:
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', '000000001', 'eq')->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
// $orderList is now an array of Orders with this incrementId, which is just one order obviously
/** @var MagentoSalesModelOrder $order */
$order = $orderList[0];
// Your logic here
$order = $this->orderRepository->save($order);
Official Magento PHP Developer guide on magento.com
Code by Mulderea on github
edited Jul 19 '17 at 12:18
Phoenix128_RiccardoT
5,38121232
5,38121232
answered Jan 18 '17 at 16:42
Jacco AmersfoortJacco Amersfoort
825717
825717
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace$order = $orderList[0]
with$order = $orderList->getFirstItem()
to get the first (and only) item from the collection.
– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in$payment
Please check my problem here magento.stackexchange.com/questions/158935/…
– Ashish Raj
Feb 14 '17 at 9:20
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
add a comment |
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace$order = $orderList[0]
with$order = $orderList->getFirstItem()
to get the first (and only) item from the collection.
– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in$payment
Please check my problem here magento.stackexchange.com/questions/158935/…
– Ashish Raj
Feb 14 '17 at 9:20
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
I am getting error like : Cannot use object of type MagentoSalesModelResourceModelOrderCollection as array at $order = $orderList[0];
– Ashish Raj
Feb 13 '17 at 14:26
That's odd, I got an array. Which version are you on? But with a collection you can just replace
$order = $orderList[0]
with $order = $orderList->getFirstItem()
to get the first (and only) item from the collection.– Jacco Amersfoort
Feb 14 '17 at 8:42
That's odd, I got an array. Which version are you on? But with a collection you can just replace
$order = $orderList[0]
with $order = $orderList->getFirstItem()
to get the first (and only) item from the collection.– Jacco Amersfoort
Feb 14 '17 at 8:42
I am in version 2.1.3. and I need to load order object for load payment object .. I have done
$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in $payment
Please check my problem here magento.stackexchange.com/questions/158935/…– Ashish Raj
Feb 14 '17 at 9:20
I am in version 2.1.3. and I need to load order object for load payment object .. I have done
$order = $orderList->getFirstItem(); $payment = $order->getPayment();
But getting nothing in $payment
Please check my problem here magento.stackexchange.com/questions/158935/…– Ashish Raj
Feb 14 '17 at 9:20
1
1
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
I had a bug with the accepted answer. This solved it. Thanks for the good solution
– CompactCode
Aug 31 '18 at 2:44
add a comment |
As far as I know, we should use MagentoSalesApiDataOrderInterface
.
/** @var MagentoSalesApiDataOrderInterfaceFactory $order **/
protected $orderFactory;
public function __construct(
MagentoSalesApiDataOrderInterfaceFactory $orderFactory,
......
)
$this->orderFactory = $orderFactory;
Load order object by increment id:
$this->orderFactory->create()->loadByIncrementId('00001952-42');
[EDIT] should try with service contracts. Try Jacco's answer.
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
version 2.2.2, useMagentoSalesApiOrderRepositoryInterface
and itsget()
method
– LucScu
Mar 6 '18 at 14:41
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
|
show 6 more comments
As far as I know, we should use MagentoSalesApiDataOrderInterface
.
/** @var MagentoSalesApiDataOrderInterfaceFactory $order **/
protected $orderFactory;
public function __construct(
MagentoSalesApiDataOrderInterfaceFactory $orderFactory,
......
)
$this->orderFactory = $orderFactory;
Load order object by increment id:
$this->orderFactory->create()->loadByIncrementId('00001952-42');
[EDIT] should try with service contracts. Try Jacco's answer.
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
version 2.2.2, useMagentoSalesApiOrderRepositoryInterface
and itsget()
method
– LucScu
Mar 6 '18 at 14:41
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
|
show 6 more comments
As far as I know, we should use MagentoSalesApiDataOrderInterface
.
/** @var MagentoSalesApiDataOrderInterfaceFactory $order **/
protected $orderFactory;
public function __construct(
MagentoSalesApiDataOrderInterfaceFactory $orderFactory,
......
)
$this->orderFactory = $orderFactory;
Load order object by increment id:
$this->orderFactory->create()->loadByIncrementId('00001952-42');
[EDIT] should try with service contracts. Try Jacco's answer.
As far as I know, we should use MagentoSalesApiDataOrderInterface
.
/** @var MagentoSalesApiDataOrderInterfaceFactory $order **/
protected $orderFactory;
public function __construct(
MagentoSalesApiDataOrderInterfaceFactory $orderFactory,
......
)
$this->orderFactory = $orderFactory;
Load order object by increment id:
$this->orderFactory->create()->loadByIncrementId('00001952-42');
[EDIT] should try with service contracts. Try Jacco's answer.
edited Jun 8 at 2:53
answered Oct 12 '16 at 3:12
Khoa TruongDinhKhoa TruongDinh
22.8k64591
22.8k64591
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
version 2.2.2, useMagentoSalesApiOrderRepositoryInterface
and itsget()
method
– LucScu
Mar 6 '18 at 14:41
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
|
show 6 more comments
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
version 2.2.2, useMagentoSalesApiOrderRepositoryInterface
and itsget()
method
– LucScu
Mar 6 '18 at 14:41
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
3
3
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
Please don't use underscores in your variable names. PHP has had access modifiers since PHP 5, which is now 12 years old. You should use modern programming practices, especially in answers here.
– Jacco Amersfoort
Jan 18 '17 at 11:18
1
1
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
This method should not be used even if it "works". One: the di injection is a shared object unless it is specified to not be; anytime you insert OrderInterface in you'll be using the exact same object. If you really want to go this route use OrderInterfaceFactory and then call create(). Second, you should be using the service contracts as in Jacco's answer.
– Ian
Jul 18 '17 at 22:03
2
2
version 2.2.2, use
MagentoSalesApiOrderRepositoryInterface
and its get()
method– LucScu
Mar 6 '18 at 14:41
version 2.2.2, use
MagentoSalesApiOrderRepositoryInterface
and its get()
method– LucScu
Mar 6 '18 at 14:41
2
2
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
service contracts must be taken in consideration.
– Thiago Lima
Jul 2 '18 at 10:25
1
1
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
@ThiagoLima yes, I agreed with you! I also voted the service contracts answer.
– Khoa TruongDinh
Jul 3 '18 at 1:15
|
show 6 more comments
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f140374%2fmagento-2-1-1-how-to-load-order-with-increment-id-using-orderrepository-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Not a duplicate - the linked answer is about retrieving the order by order id, not by increment id
– Fabian Schmengler
Oct 12 '16 at 18:45
ekk! Is there a way to undo the mark as duplicate? I meant to mark the answer below as the answer to the solution.
– frostshoxx
Oct 12 '16 at 20:53
1
Too late, now that it is already closed. But I nominated the question to be reopened.
– Fabian Schmengler
Oct 12 '16 at 20:58