Created plugin that overrides after SucessValidator
<?php
namespace DevAll\RedirectSuccessPlugin\Plugin\Magento\Checkout\Model\Session;
use Magento\Framework\Api\Search\SearchCriteriaFactory;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order\Collection;
/**
* Class SuccessValidator
* @package Vendor\Module\Plugin\Magento\Checkout\Model\Session
*/
class SuccessValidator
{
/**
* @var \Magento\Checkout\Model\Session
*/
protected $checkoutSession;
/**
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
*/
protected $orderCollectionFactory;
/**
* SuccessValidator constructor.
* @param OrderRepository $orderRepository
* @param \Magento\Checkout\Model\Session $checkoutSession
*/
public function __construct(
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
\Magento\Checkout\Model\Session $checkoutSession
) {
$this->checkoutSession = $checkoutSession;
$this->orderCollectionFactory = $orderCollectionFactory;
}
/**
* @param \Magento\Checkout\Model\Session\SuccessValidator $successValidator
* @param boolean $returnValue
* @return boolean
*/
public function afterIsValid(\Magento\Checkout\Model\Session\SuccessValidator $successValidator, $returnValue)
{
/** @var Order $order */
$order = $this->orderCollectionFactory->create()
->setPageSize(1)
->setOrder('entity_id', 'DESC')
->addFieldToFilter('status', ['eq' => 'complete'])
->getFirstItem();
if ($order->getId()) {
$this->checkoutSession->setLastOrderId($order->getId());
$this->checkoutSession->setLastQuoteId($order->getQuoteId());
$this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
return true;
}
return $returnValue;
}
}
I think it was working but now I have an error
Fatal error: Uncaught Error: Call to a member function getMethodInstance() on null in /var/www/html/vendor/iways/module-pay-pal-plus/Block/Onepage/Success.php:64 Stack trace: #0 /var/www/html/vendor/iways/module-pay-pal-plus/Block/Onepage/Success.php(78): Iways\PayPalPlus\Block\Onepage\Success->isPPP() #1 /var/www/html/vendor/iways/module-pay-pal-plus/view/frontend/templates/paypalplus/success.phtml(21): Iways\PayPalPlus\Block\Onepage\Success->isPUI() #2 /var/www/html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/html/v...') #3 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Iways\PayPalPlus\Block\Onepage\Success), '/var/www/html/v...', Array) #4 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array) #5 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEn in /var/www/html/vendor/iways/module-pay-pal-plus/Block/Onepage/Success.php on line 64
how could it stopped working ?