1

Create an observer file using this event.

sales_order_item_cancel

public function execute(EventObserver $observer)
    {
        /** @var \Magento\Sales\Model\Order\Item $item */
        $item = $observer->getEvent()->getItem();
        $children = $item->getChildrenItems();
        echo $qty = $item->getQtyOrdered() - max($item->getQtyShipped(), $item->getQtyInvoiced()) - $item->getQtyCanceled();
        exit;
        if ($item->getId() && $item->getProductId() && empty($children) && $qty) {
            $this->flag = "cancel";
            $this->cancelOrder = $item->getOrder()->getIncrementId();
            $this->stockManagement->backItemQty($item->getProductId(), $qty, $item->getStore()->getWebsiteId());
        }
        $this->priceIndexer->reindexRow($item->getProductId());
        return $this;
    }

How to get $this->flag and $this->cancelOrder values in observer file using this event.

cataloginventory_stock_item_save_after

if($this->flag == "cancel")
{
    $orderId = $this->cancelOrder;
}
0

I guess that you want to set two variables at sales_order_item_cancel observer class then get that value to cataloginventory_stock_item_save_after's observer.

In this situation, you can use registry \Magento\Framework\Registry . https://www.mageplaza.com/magento-2-registry-register.html.

Create two registry variable at sales_order_item_cancel 's observer and get that avriable value to cataloginventory_stock_item_save_after

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.