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 #1985 from bibich/delivery-payment-events
Delivery payment events
- Loading branch information
Showing
20 changed files
with
1,070 additions
and
209 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,66 @@ | ||
<?php | ||
/*************************************************************************************/ | ||
/* This file is part of the Thelia package. */ | ||
/* */ | ||
/* Copyright (c) OpenStudio */ | ||
/* email : dev@thelia.net */ | ||
/* web : http://www.thelia.net */ | ||
/* */ | ||
/* For the full copyright and license information, please view the LICENSE.txt */ | ||
/* file that was distributed with this source code. */ | ||
/*************************************************************************************/ | ||
|
||
|
||
namespace Thelia\Action; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Thelia\Core\Event\Delivery\DeliveryPostageEvent; | ||
use Thelia\Core\Event\TheliaEvents; | ||
|
||
/** | ||
* Class Delivery | ||
* @package Thelia\Action | ||
* @author Julien Chanséaume <julien@thelia.net> | ||
*/ | ||
class Delivery implements EventSubscriberInterface | ||
{ | ||
/** | ||
* Get postage from module using the classical module functions | ||
* | ||
* @param DeliveryPostageEvent $event | ||
*/ | ||
public function getPostage(DeliveryPostageEvent $event, $eventName, EventDispatcherInterface $dispatcher) | ||
{ | ||
$module = $event->getModule(); | ||
|
||
// dispatch event to target specific module | ||
$dispatcher->dispatch( | ||
TheliaEvents::getModuleEvent( | ||
TheliaEvents::MODULE_DELIVERY_GET_POSTAGE, | ||
$module->getCode() | ||
), | ||
$event | ||
); | ||
|
||
if ($event->isPropagationStopped()) { | ||
return; | ||
} | ||
|
||
// call legacy module method | ||
$event->setValidModule($module->isValidDelivery($event->getCountry())); | ||
if ($event->isValidModule()) { | ||
$event->setPostage($module->getPostage($event->getCountry())); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
TheliaEvents::MODULE_DELIVERY_GET_POSTAGE => ['getPostage', 128] | ||
]; | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
/*************************************************************************************/ | ||
/* This file is part of the Thelia package. */ | ||
/* */ | ||
/* Copyright (c) OpenStudio */ | ||
/* email : dev@thelia.net */ | ||
/* web : http://www.thelia.net */ | ||
/* */ | ||
/* For the full copyright and license information, please view the LICENSE.txt */ | ||
/* file that was distributed with this source code. */ | ||
/*************************************************************************************/ | ||
|
||
|
||
namespace Thelia\Action; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Thelia\Core\Event\Payment\IsValidPaymentEvent; | ||
use Thelia\Core\Event\TheliaEvents; | ||
|
||
/** | ||
* Class Payment | ||
* @package Thelia\Action | ||
* @author Julien Chanséaume <julien@thelia.net> | ||
*/ | ||
class Payment implements EventSubscriberInterface | ||
{ | ||
/** | ||
* Check if a module is valid | ||
* | ||
* @param IsValidPaymentEvent $event | ||
*/ | ||
public function isValid(IsValidPaymentEvent $event, $eventName, EventDispatcherInterface $dispatcher) | ||
{ | ||
$module = $event->getModule(); | ||
|
||
// dispatch event to target specific module | ||
$dispatcher->dispatch( | ||
TheliaEvents::getModuleEvent( | ||
TheliaEvents::MODULE_PAYMENT_IS_VALID, | ||
$module->getCode() | ||
), | ||
$event | ||
); | ||
|
||
if ($event->isPropagationStopped()) { | ||
return; | ||
} | ||
|
||
// call legacy module method | ||
$event->setValidModule($module->isValidPayment()); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
TheliaEvents::MODULE_PAYMENT_IS_VALID => ['isValid', 128], | ||
]; | ||
} | ||
} |
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.