How to get the order item id in Magento 2 (not the order ID)?How to change save path of PDF files in magento 2Magento 2.1 Create a filter in the product grid by new attributepayment-information 400 bad request when product quantity is bigger (or equal) than 3Get product id from order historyHow to Update Magento 2 configurable child products price by REST APIMagento 2 How to disable price from orders, customer account and order view if custom module is enabled?Magento 2.3.1 Error on checkout getAdditionalInformation()Plugin wont set Stock level and status - Module wont fire on Product LoadHow to get the value of custom product attribute in order itemHow to add item status for an order in magento 2
Cops: The Hidden OEIS Substring
Why does the autopilot disengage even when it does not receive pilot input?
Single word for "refusing to move to next activity unless present one is completed."
Who Can Help Retag This?
Why didn't Thanos kill all the Dwarves on Nidavellir?
Keep milk (or milk alternative) for a day without a fridge
What would be the ideal melee weapon made of "Phase Metal"?
Is purchasing foreign currency before going abroad a losing proposition?
For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?
Double-sided action figure, early 80s?
How to know whether a Tamron lens is compatible with Canon EOS 60D?
will it increase or decrease my credit score, if i split a high balance on 2 credit cards
What was the definition of "set" that resulted in Russell's Paradox
Why isn't pressure filtration popular compared to vacuum filtration?
Why are they 'nude photos'?
How can one write good dialogue in a story without sounding wooden?
During copyediting, journal disagrees about spelling of paper's main topic
How can I get a player to accept that they should stop trying to pull stunts without thinking them through first?
How do I take a fraction to a negative power?
Was the Ford Model T black because of the speed black paint dries?
Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?
Why do Americans say "less than five people"?
Managing and organizing the massively increased number of classes after switching to SOLID?
How to achieve this rough borders and stippled illustration look?
How to get the order item id in Magento 2 (not the order ID)?
How to change save path of PDF files in magento 2Magento 2.1 Create a filter in the product grid by new attributepayment-information 400 bad request when product quantity is bigger (or equal) than 3Get product id from order historyHow to Update Magento 2 configurable child products price by REST APIMagento 2 How to disable price from orders, customer account and order view if custom module is enabled?Magento 2.3.1 Error on checkout getAdditionalInformation()Plugin wont set Stock level and status - Module wont fire on Product LoadHow to get the value of custom product attribute in order itemHow to add item status for an order in magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to show product information on Order_View page. I have selected all of the product I have ordered from many orders to show on a page (Order_History). On the Order_History, When you click on Order Detail, it will show the product you have clicked on with information about price, qty...My idea to do that is I want to get the itemId in table sale_order_item, from that, I can get specific the product I want to show on.
Can anyone show me how can we get the itemId?? I refer to this link, But, it did not solve my problem.
<?php
namespace MagentoHistoryBlock;
class Display extends MagentoFrameworkViewElementTemplate
protected $order;
protected $orderRepository;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '4';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
echo $item->getName();
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId();
$count++;
return $item_data;
magento2 magento2.3
add a comment |
I'm trying to show product information on Order_View page. I have selected all of the product I have ordered from many orders to show on a page (Order_History). On the Order_History, When you click on Order Detail, it will show the product you have clicked on with information about price, qty...My idea to do that is I want to get the itemId in table sale_order_item, from that, I can get specific the product I want to show on.
Can anyone show me how can we get the itemId?? I refer to this link, But, it did not solve my problem.
<?php
namespace MagentoHistoryBlock;
class Display extends MagentoFrameworkViewElementTemplate
protected $order;
protected $orderRepository;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '4';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
echo $item->getName();
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId();
$count++;
return $item_data;
magento2 magento2.3
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45
add a comment |
I'm trying to show product information on Order_View page. I have selected all of the product I have ordered from many orders to show on a page (Order_History). On the Order_History, When you click on Order Detail, it will show the product you have clicked on with information about price, qty...My idea to do that is I want to get the itemId in table sale_order_item, from that, I can get specific the product I want to show on.
Can anyone show me how can we get the itemId?? I refer to this link, But, it did not solve my problem.
<?php
namespace MagentoHistoryBlock;
class Display extends MagentoFrameworkViewElementTemplate
protected $order;
protected $orderRepository;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '4';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
echo $item->getName();
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId();
$count++;
return $item_data;
magento2 magento2.3
I'm trying to show product information on Order_View page. I have selected all of the product I have ordered from many orders to show on a page (Order_History). On the Order_History, When you click on Order Detail, it will show the product you have clicked on with information about price, qty...My idea to do that is I want to get the itemId in table sale_order_item, from that, I can get specific the product I want to show on.
Can anyone show me how can we get the itemId?? I refer to this link, But, it did not solve my problem.
<?php
namespace MagentoHistoryBlock;
class Display extends MagentoFrameworkViewElementTemplate
protected $order;
protected $orderRepository;
public function __construct(
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '4';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
echo $item->getName();
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId();
$count++;
return $item_data;
magento2 magento2.3
magento2 magento2.3
edited Jul 4 at 7:11
Michael Tao
asked Jul 4 at 3:18
Michael TaoMichael Tao
447 bronze badges
447 bronze badges
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45
add a comment |
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45
add a comment |
2 Answers
2
active
oldest
votes
You can use this below code and get order item id using order id :
Method 1 :
protected $orderRepository;
public function __construct(
...
MagentoSalesApiOrderRepositoryInterface $orderRepository,
....
)
....
$this->orderRepository = $orderRepository;
....
public function yourFunction()
$orderId = 105105;
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 2 :
protected $order;
protected $orderRepository;
public function __construct(
...
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository,
...
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '100005363';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 1 : Get order item id by order id
Method 2 : Get order item id by order increment id
Now, call function $block->yourFunction()
in your phtml file.
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
|
show 5 more comments
If you have order id then you can load by this:
//Where $this->orderRepository is the instance of MagentoSalesApiOrderRepositoryInterface
$order = $this->orderRepository->get($id);
If you have order increment id then you can load order by this:
//Where $this->orderInterfaceFactory is the instance of MagentoSalesApiDataOrderInterfaceFactory
$order = $this->orderInterfaceFactory->create()->loadByIncrementId($orderId);
Now get all items
$items = $order->getAllVisibleItems();
The difference between getAllVisibleItems()
and getAllItems()
is that Visible items will only show items which would visible on frontend, whereas AllItems will send visible as well as associated items.
Now use foreach loop to get item ids
foreach($items as $item)
echo "Order Item ID :".$item->getItemId();
echo "Order Product ID : ".$item->getProductId();
$item->getItemId()
will return item id which is primary key of sale_order_item
table, whereas $item->getProductId()
will return product id.
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
add a comment |
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%2f280707%2fhow-to-get-the-order-item-id-in-magento-2-not-the-order-id%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
You can use this below code and get order item id using order id :
Method 1 :
protected $orderRepository;
public function __construct(
...
MagentoSalesApiOrderRepositoryInterface $orderRepository,
....
)
....
$this->orderRepository = $orderRepository;
....
public function yourFunction()
$orderId = 105105;
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 2 :
protected $order;
protected $orderRepository;
public function __construct(
...
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository,
...
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '100005363';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 1 : Get order item id by order id
Method 2 : Get order item id by order increment id
Now, call function $block->yourFunction()
in your phtml file.
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
|
show 5 more comments
You can use this below code and get order item id using order id :
Method 1 :
protected $orderRepository;
public function __construct(
...
MagentoSalesApiOrderRepositoryInterface $orderRepository,
....
)
....
$this->orderRepository = $orderRepository;
....
public function yourFunction()
$orderId = 105105;
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 2 :
protected $order;
protected $orderRepository;
public function __construct(
...
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository,
...
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '100005363';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 1 : Get order item id by order id
Method 2 : Get order item id by order increment id
Now, call function $block->yourFunction()
in your phtml file.
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
|
show 5 more comments
You can use this below code and get order item id using order id :
Method 1 :
protected $orderRepository;
public function __construct(
...
MagentoSalesApiOrderRepositoryInterface $orderRepository,
....
)
....
$this->orderRepository = $orderRepository;
....
public function yourFunction()
$orderId = 105105;
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 2 :
protected $order;
protected $orderRepository;
public function __construct(
...
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository,
...
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '100005363';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 1 : Get order item id by order id
Method 2 : Get order item id by order increment id
Now, call function $block->yourFunction()
in your phtml file.
You can use this below code and get order item id using order id :
Method 1 :
protected $orderRepository;
public function __construct(
...
MagentoSalesApiOrderRepositoryInterface $orderRepository,
....
)
....
$this->orderRepository = $orderRepository;
....
public function yourFunction()
$orderId = 105105;
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 2 :
protected $order;
protected $orderRepository;
public function __construct(
...
MagentoSalesApiDataOrderInterface $order,
MagentoSalesApiOrderRepositoryInterface $orderRepository,
...
)
$this->order = $order;
$this->orderRepository = $orderRepository;
public function yourFunction()
$order_increment_id = '100005363';
$order = $this->order->loadByIncrementId($order_increment_id);
$orderId = $order->getId();
$order = $this->orderRepository->get($orderId);
$item_data = [];
$count = 0;
foreach ($order->getAllVisibleItems() as $item)
//var_dump($item->getData());
$item_data[$count]['item_id'] = $item->getItemId();
$item_data[$count]['product_id'] = $item->getProductId(); //for product Id
$count++;
return $item_data;
Method 1 : Get order item id by order id
Method 2 : Get order item id by order increment id
Now, call function $block->yourFunction()
in your phtml file.
edited Jul 4 at 7:09
answered Jul 4 at 4:53
Rohan HapaniRohan Hapani
7,7174 gold badges21 silver badges65 bronze badges
7,7174 gold badges21 silver badges65 bronze badges
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
|
show 5 more comments
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Hi @Rohan, Thanks to you a lot. I get this error after followed your code: An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 6:48
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
Which id is needed? Which method you used?
– Rohan Hapani
Jul 4 at 6:58
I used method 2
– Michael Tao
Jul 4 at 7:01
I used method 2
– Michael Tao
Jul 4 at 7:01
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
Can you please upload your code in your question which you tried? I think you didn't comment simple text of comment so.
– Rohan Hapani
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
I'm so sorry but I have no idea. I just used your code and run, and get the error is: Exception #0 (MagentoFrameworkExceptionInputException): An ID is needed. Set the ID and try again.
– Michael Tao
Jul 4 at 7:08
|
show 5 more comments
If you have order id then you can load by this:
//Where $this->orderRepository is the instance of MagentoSalesApiOrderRepositoryInterface
$order = $this->orderRepository->get($id);
If you have order increment id then you can load order by this:
//Where $this->orderInterfaceFactory is the instance of MagentoSalesApiDataOrderInterfaceFactory
$order = $this->orderInterfaceFactory->create()->loadByIncrementId($orderId);
Now get all items
$items = $order->getAllVisibleItems();
The difference between getAllVisibleItems()
and getAllItems()
is that Visible items will only show items which would visible on frontend, whereas AllItems will send visible as well as associated items.
Now use foreach loop to get item ids
foreach($items as $item)
echo "Order Item ID :".$item->getItemId();
echo "Order Product ID : ".$item->getProductId();
$item->getItemId()
will return item id which is primary key of sale_order_item
table, whereas $item->getProductId()
will return product id.
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
add a comment |
If you have order id then you can load by this:
//Where $this->orderRepository is the instance of MagentoSalesApiOrderRepositoryInterface
$order = $this->orderRepository->get($id);
If you have order increment id then you can load order by this:
//Where $this->orderInterfaceFactory is the instance of MagentoSalesApiDataOrderInterfaceFactory
$order = $this->orderInterfaceFactory->create()->loadByIncrementId($orderId);
Now get all items
$items = $order->getAllVisibleItems();
The difference between getAllVisibleItems()
and getAllItems()
is that Visible items will only show items which would visible on frontend, whereas AllItems will send visible as well as associated items.
Now use foreach loop to get item ids
foreach($items as $item)
echo "Order Item ID :".$item->getItemId();
echo "Order Product ID : ".$item->getProductId();
$item->getItemId()
will return item id which is primary key of sale_order_item
table, whereas $item->getProductId()
will return product id.
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
add a comment |
If you have order id then you can load by this:
//Where $this->orderRepository is the instance of MagentoSalesApiOrderRepositoryInterface
$order = $this->orderRepository->get($id);
If you have order increment id then you can load order by this:
//Where $this->orderInterfaceFactory is the instance of MagentoSalesApiDataOrderInterfaceFactory
$order = $this->orderInterfaceFactory->create()->loadByIncrementId($orderId);
Now get all items
$items = $order->getAllVisibleItems();
The difference between getAllVisibleItems()
and getAllItems()
is that Visible items will only show items which would visible on frontend, whereas AllItems will send visible as well as associated items.
Now use foreach loop to get item ids
foreach($items as $item)
echo "Order Item ID :".$item->getItemId();
echo "Order Product ID : ".$item->getProductId();
$item->getItemId()
will return item id which is primary key of sale_order_item
table, whereas $item->getProductId()
will return product id.
If you have order id then you can load by this:
//Where $this->orderRepository is the instance of MagentoSalesApiOrderRepositoryInterface
$order = $this->orderRepository->get($id);
If you have order increment id then you can load order by this:
//Where $this->orderInterfaceFactory is the instance of MagentoSalesApiDataOrderInterfaceFactory
$order = $this->orderInterfaceFactory->create()->loadByIncrementId($orderId);
Now get all items
$items = $order->getAllVisibleItems();
The difference between getAllVisibleItems()
and getAllItems()
is that Visible items will only show items which would visible on frontend, whereas AllItems will send visible as well as associated items.
Now use foreach loop to get item ids
foreach($items as $item)
echo "Order Item ID :".$item->getItemId();
echo "Order Product ID : ".$item->getProductId();
$item->getItemId()
will return item id which is primary key of sale_order_item
table, whereas $item->getProductId()
will return product id.
answered Jul 4 at 4:49
Shoaib MunirShoaib Munir
5,2826 gold badges23 silver badges69 bronze badges
5,2826 gold badges23 silver badges69 bronze badges
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
add a comment |
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
1
1
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
Thanks @ShoaibMunir +1 for mine also :)
– Rohan Hapani
Jul 4 at 9:22
add a comment |
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%2f280707%2fhow-to-get-the-order-item-id-in-magento-2-not-the-order-id%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
Can you please attach screenshot or sales_order_item table?
– Rohan Hapani
Jul 4 at 4:45