-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CartInitiated notification
- Loading branch information
1 parent
13d91b8
commit 8d49df1
Showing
6 changed files
with
317 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Alma\MonthlyPayments\Observer; | ||
|
||
|
||
use Alma\MonthlyPayments\Helpers\Logger; | ||
use Alma\MonthlyPayments\Services\MerchantBusinessService; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Quote\Model\Quote; | ||
|
||
|
||
class SalesQuoteSaveAfterObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var Logger | ||
*/ | ||
private $logger; | ||
/** | ||
* @var MerchantBusinessService | ||
*/ | ||
private $merchantBusinessService; | ||
|
||
/** | ||
* @param Logger $logger | ||
* @param MerchantBusinessService $merchantBusinessService | ||
*/ | ||
public function __construct( | ||
Logger $logger, | ||
MerchantBusinessService $merchantBusinessService | ||
) | ||
{ | ||
$this->logger = $logger; | ||
$this->merchantBusinessService = $merchantBusinessService; | ||
} | ||
|
||
/** | ||
* @param Observer $observer | ||
* @return void | ||
*/ | ||
public function execute(Observer $observer): void | ||
{ | ||
/** @var Quote $quote */ | ||
$quote = $observer->getEvent()->getData('quote'); | ||
if (!$this->merchantBusinessService->isSendCartInitiatedNotification($quote)) { | ||
$this->merchantBusinessService->createAndSendCartInitiatedBusinessEvent($quote); | ||
} | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Alma\MonthlyPayments\Test\Unit\Observer; | ||
|
||
use Alma\MonthlyPayments\Helpers\Logger; | ||
use Alma\MonthlyPayments\Observer\SalesQuoteSaveAfterObserver; | ||
use Alma\MonthlyPayments\Services\MerchantBusinessService; | ||
use Magento\Framework\Event; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Quote\Model\Quote; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SalesQuoteSaveAfterObserverTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Logger | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var MerchantBusinessService | ||
*/ | ||
private $merchantBusinessService; | ||
/** | ||
* @var SalesQuoteSaveAfterObserver | ||
*/ | ||
private $salesQuoteSaveAfterObserver; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->logger = $this->createMock(Logger::class); | ||
$this->merchantBusinessService = $this->createMock(MerchantBusinessService::class); | ||
$this->salesQuoteSaveAfterObserver = new SalesQuoteSaveAfterObserver( | ||
$this->logger, | ||
$this->merchantBusinessService | ||
); | ||
} | ||
|
||
public function testExecuteCartInitiatedNotificationNotSend() | ||
{ | ||
$observer = $this->createMock(Observer::class); | ||
$quote = $this->createMock(Quote::class); | ||
$event = $this->createMock(Event::class); | ||
$event->method('getData')->with('quote')->willReturn($quote); | ||
$observer->method('getEvent')->willReturn($event); | ||
$quote->method('getId')->willReturn(42); | ||
$this->merchantBusinessService | ||
->expects($this->once()) | ||
->method('isSendCartInitiatedNotification') | ||
->with($quote) | ||
->willReturn(false); | ||
$this->merchantBusinessService | ||
->expects($this->once()) | ||
->method('createAndSendCartInitiatedBusinessEvent') | ||
->with($quote); | ||
|
||
$this->salesQuoteSaveAfterObserver->execute($observer); | ||
} | ||
|
||
public function testExecuteCartInitiatedNotificationAlreadySend() | ||
{ | ||
$observer = $this->createMock(Observer::class); | ||
$quote = $this->createMock(Quote::class); | ||
$event = $this->createMock(Event::class); | ||
$event->method('getData')->with('quote')->willReturn($quote); | ||
$observer->method('getEvent')->willReturn($event); | ||
$quote->method('getId')->willReturn(42); | ||
$this->merchantBusinessService | ||
->expects($this->once()) | ||
->method('isSendCartInitiatedNotification') | ||
->with($quote) | ||
->willReturn(true); | ||
|
||
$this->merchantBusinessService | ||
->expects($this->never()) | ||
->method('createAndSendCartInitiatedBusinessEvent') | ||
->with($quote); | ||
|
||
$this->salesQuoteSaveAfterObserver->execute($observer); | ||
} | ||
|
||
} |
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
Oops, something went wrong.