I want to delete the order item from observer I created like this:
namespace Namespace\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class AfterOrder implements ObserverInterface
{
protected $_objectManager;
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager
) {
$this->_objectManager = $objectManager;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
//not sure if it's correct
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item){
if(condition){
//delete order item, how?
}
}
}
}
events.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_onepage_controller_success_action">
<observer name="module_controller_success_action" instance="Namespace\Module\Observer\AfterOrder" />
</event>
</config>