-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from degica/fix/sessionError
Fix null quote issue
- Loading branch information
Showing
8 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/app/code/Komoju/Payments/Observer/RestoreAfterCancel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Komoju\Payments\Observer; | ||
|
||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class RestoreAfterCancel implements ObserverInterface | ||
{ | ||
protected CheckoutSession $checkoutSession; | ||
protected CartRepositoryInterface $quoteRepository; | ||
private LoggerInterface $logger; | ||
|
||
public function __construct( | ||
CheckoutSession $checkoutSession, | ||
CartRepositoryInterface $quoteRepository, | ||
LoggerInterface $logger = null | ||
) { | ||
$this->checkoutSession = $checkoutSession; | ||
$this->quoteRepository = $quoteRepository; | ||
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); | ||
} | ||
|
||
public function execute(Observer $observer) | ||
{ | ||
$lastRealQuoteId = $this->checkoutSession->getLastRealQuoteId(); | ||
|
||
if (!$lastRealQuoteId) { | ||
$quote = $observer->getEvent()->getQuote(); | ||
$quote->setIsActive(true); | ||
return; | ||
} | ||
|
||
$order = $observer->getEvent()->getOrder(); | ||
$quote = $this->quoteRepository->get($lastRealQuoteId); | ||
|
||
if ($order) { | ||
try { | ||
$this->checkoutSession->replaceQuote($quote); | ||
$this->checkoutSession->restoreQuote(); | ||
} catch (Exception $e) { | ||
$this->logger->info('RestoreAfterCancel:: Fail to restore'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/app/code/Komoju/Payments/Observer/SaveQuoteBeforeOrder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Komoju\Payments\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class SaveQuoteBeforeOrder implements ObserverInterface | ||
{ | ||
protected $checkoutSession; | ||
protected $logger; | ||
|
||
public function __construct( | ||
CheckoutSession $checkoutSession, | ||
LoggerInterface $logger | ||
) { | ||
$this->checkoutSession = $checkoutSession; | ||
$this->logger = $logger; | ||
} | ||
|
||
public function execute(Observer $observer) | ||
{ | ||
$quote = $observer->getEvent()->getQuote(); | ||
$this->checkoutSession->setLastRealQuoteId($quote->getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters