For the reorder function, I added an Observer in my custom module that allows me to extract the quote_id. Actually my real goal is to get the increment id of the order I am reordering for. Currently this is my code but it is not working:
events.xml
<event name="sales_quote_add_item">
<observer name="custom_reorder_observer" instance="Catalog\Product\Observer\ReorderObserver" />
</event>
ReorderObserver.php
<?php
namespace Catalog\Product\Observer;
use Magento\Framework\Event\ObserverInterface;
class ReorderObserver implements ObserverInterface
{
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
private $orderRepository;
public function __construct(
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
) {
$this->orderRepository = $orderRepository;
}
//FUNZIONE PER PRELEVARE POSIZIONE SCELTA NEL CALCOLATORE
public function execute(\Magento\Framework\Event\Observer $observer)
{
$quoteItem = $observer->getQuoteItem();
$quoteId = $observer->getQuoteItem()->getquote_id();
$orderId = $this->orderRepository->getByQuoteId($quoteId)->getId();
$quoteItem->setIdreorder($orderId);
}
}
How could I do this?