1 / 6

Know-How To Get Order Item Collection By Item Id In Magento 2!

If You Have An Ecommerce Site Running On Magento 2 Platform Then Knowing How To Get Item Data From Your Online Store Is A Thing You Should Know About. This Post Is Going To Teach You How To Retrieve This. LEARN MORE!

Download Presentation

Know-How To Get Order Item Collection By Item Id In Magento 2!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HOW TO GET ORDER ITEM COLLECTION BY ITEM ID IN MAGENTO 2?

  2. Magento 2 has a lot more to offer than Magento 1. If you have an eCommerce site running on Magento 2 platform then knowing how to get item data from your online store is a thing you should know about. This post is going to teach you how to retrieve this. Item data or product data collection in Magento 2 means showing you the number of items present in your store. The below code describes how to use item id to get order item collection in Magento 2. Let’s fetch the products in your Magento 2 store.

  3. <?php declare(strict_types=1); namespace MageSpark\OrderItem\Block; use Magento\Framework\View\Element\Template; use Magento\Sales\Api\Data\OrderItemInterface; use Magento\Sales\Api\OrderItemRepositoryInterface; /** * Class Item * * @package MageSpark\OrderItem\Block */ class Item extends Template { /** * @var OrderItemRepositoryInterface */ protected $orderItemRepository; /** * Item constructor. * @param Template $context * @param OrderItemRepositoryInterface $orderItemRepository * @param array $data */ public function __construct( Template $context, OrderItemRepositoryInterface $orderItemRepository, array $data = [] ) { $this->orderItemRepository = $orderItemRepository; parent::__construct($context, $data); } /** * Get order Item collection * * @param $itemId * @return OrderItemInterface */ public function getOrderItem($itemId): OrderItemInterface { return $this->orderItemRepository->get($itemId); } }

  4. At last, use the template file to call the function /** * @var $block \MageSpark\OrderItem\Block\Item */ $itemId = 120; // Use your desired item id here $itemCollection = $block- >getOrderItem($itemId); echo $itemCollection->getOrderId(); echo "<pre>"; print_r($itemCollection->debug()); That’s it. Note: You can replace the $itemId as per your need.

  5. Summary The method to get order item data from item id can be modified depending on your preference and the amount of products your store contains. If you’ve got any doubt with you, let us know in the comment section below.

  6. Contact Us Phone Number +918200035083 Email Address support@magespark.com Website www.magespark.com

More Related