use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Quote\Model\QuoteFactory;
use Magento\Checkout\Model\Cart;
use Magento\Catalog\Model\ProductFactory;
class Copyquote extends \Magento\Framework\App\Action\Action
{
protected $_resultPageFactory;
protected $quoteFactory;
protected $formKey;
protected $cart;
protected $product;
public function __construct(Context $context,
PageFactory $resultPageFactory,
QuoteFactory $quoteFactory,
Cart $cart,
ProductFactory $product)
{
$this->_resultPageFactory = $resultPageFactory;
$this->quoteFactory = $quoteFactory;
$this->cart = $cart;
$this->product = $product;
parent::__construct($context);
}
public function execute()
{
try
{
$id = ‘YOUR QUOTE ID’
if($id > 0)
{
$quote = $this->quoteFactory->create()->load($id);
$items = $quote->getAllVisibleItems();
foreach ($items as $item)
{
$productId =$item->getProductId();
$_product = $this->product->create()->load($productId);
$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
$info = $options['info_buyRequest'];
$request1 = new \Magento\Framework\DataObject();
$request1->setData($info);
$this->cart->addProduct($_product, $request1);
}
$this->cart->save();
}
catch (\Exception $e)
{
$this->messageManager->addError( __($e->getMessage()) );
}
}
}