I have to skip some items when the customer does Reorder. For this, I have overridden the controller Using Plugin.
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Controller\AbstractController\Reorder">
<plugin name="reorder" type="MyModule\MyReorder\Plugin\Reorder" sortOrder="1" />
</type>
</config>
Controller File
<?php
namespace MyModule\MyReorder\Plugin;
use Magento\Framework\Registry;
class Reorder
{
/**
* @var \Magento\Checkout\Model\Cart
*/
private $cart;
/**
* @var \Magento\Sales\Controller\AbstractController\OrderLoaderInterface
*/
private $orderLoader;
/**
* @var Registry
*/
protected $_coreRegistry;
public function __construct(
\Magento\Sales\Controller\AbstractController\OrderLoaderInterface $orderLoader,
\Magento\Checkout\Model\Cart $cart,
Registry $registry
) {
$this->_coreRegistry = $registry;
$this->orderLoader = $orderLoader;
$this->cart = $cart;
}
public function aroundExecute(
\Magento\Sales\Controller\AbstractController\Reorder $subject,
$result
){
}
public function afterExecute(
\Magento\Sales\Controller\AbstractController\Reorder $subject,
$result
) {
$order = $this->_coreRegistry->registry('current_order');
$cart = $this->cart;
$reorderid = $order->getIncrementId();
$quote = $cart->getQuote();
$quote->setReOrderId($reorderid);
$cart->save();
return $result;
}
}
Please help me how to skip product with some ID in around Method.