How to Get Applied rule ids of the item from the Order Magento 2?

You can get applied rule ids of the product item from the Sales Order by order item id.

A customer has applied the shopping cart rule for the order and if any item contains that specific rules, after place order, the sales item persists the shopping cart rule id in the sales_order_item database table for the item level. Continue reading “How to Get Applied rule ids of the item from the Order Magento 2?”

How to Delete Order item by id Magento 2?

Magento 2, Sales Order item has information of Order items like Item Id, Parent order id, SKU, name, and much more information.

If you want to delete an Order item by item id using Magento 2, You can delete it safely using OrderItemRepositoryInterface. Continue reading “How to Delete Order item by id Magento 2?”

How to get order item collection by item id magento 2?

You can get item collection data by Item id in Magento 2 by using below code snippet, Create Block file,

<?php
namespace Rbj\Training\Block;

class Item extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template $context,
        \Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository,
        array $data = []
    ) {
        $this->orderItemRepository = $orderItemRepository;
        parent::__construct($context, $data);
    }

    /* get order Item collection */
    public function getOrderItem($itemIid)
    {
        $itemCollection = $this->orderItemRepository->get($itemId);
        return $itemCollection;
    }
}

Call function from the Template file,

$itemId = 10; // order item id
$getItemCollection = $block->getOrderItem($itemId);
echo $getItemCollection->getOrderId();
echo "<pre>";print_r($getItemCollection->debug());