If a customer placed an order of 3 different items with different quantities like
- shirt 2 qty
- Watch 1qty
- pant 3qty
and cancels the order item at different times I have to set the state to order cancelled
here's my code can anyone please tell me where I am wrong
if (isset($_POST['order'])) {
$_orderCollectionFactory = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory');
$collection = $_orderCollectionFactory->create()
->addFieldToSelect('*')
->addFieldToFilter('status', ['neq' => 'cancelled']);
foreach ($collectionFactory as $order)
{
$items = $order->getAllVisibleItems();
foreach ($items as $items) {
$totalitem = $totalitem + ($item['qty_canceled']);
$itemcount = $order->getQtyOrdered();
if ($itemcount == ($totalitem))
{
$order->setState("canceled");
$order->save();
}
}
}
}