vendor/lnb/shopware6-lnb-subscription/src/Subscriber/Subscription/LoyaltyUpdateSubscriber.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Permission is hereby granted, free of charge, to any person obtaining a
  4.  * copy of this software and associated documentation files (the "Software"),
  5.  * to deal in the Software without restriction, including without limitation
  6.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7.  * and/or sell copies of the Software, and to permit persons to whom the
  8.  * Software is furnished to do so, subject to the following conditions:
  9.  *
  10.  * The above copyright notice and this permission notice shall be included in
  11.  * all copies or substantial portions of the Software.
  12.  *
  13.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19.  * IN THE SOFTWARE.
  20.  *
  21.  * @package    LnbSubscription
  22.  * @author     Michael Lämmlein <michael.laemmlein@liebscher-bracht.com>
  23.  * @copyright  ©2023 Liebscher & Bracht
  24.  * @license    http://www.opensource.org/licenses/mit-license.php MIT-License
  25.  * @version    1.0.0
  26.  * @since      21.03.23
  27.  */
  28. declare(strict_types=1);
  29. namespace Lnb\Shopware6\LnbSubscription\Subscriber\Subscription;
  30. use Lnb\Shopware6\LnbSubscription\Event\OrderCreatedEvent;
  31. use Lnb\Shopware6\LnbSubscription\Event\SubscriptionCreatedEvent;
  32. use Lnb\Shopware6\LnbSubscription\Service\Loyalty\SubscriptionLoyaltyUpdateService;
  33. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  34. readonly class LoyaltyUpdateSubscriber implements EventSubscriberInterface
  35. {
  36.     public function __construct(
  37.         private SubscriptionLoyaltyUpdateService $subscriptionLoyaltyUpdateService
  38.     ) {
  39.     }
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             SubscriptionCreatedEvent::class => [
  44.                 ['onInitialLoyalty'],
  45.             ],
  46.             OrderCreatedEvent::class => [
  47.                 ['onUpdateNextLoyalty', -1],
  48.             ],
  49.         ];
  50.     }
  51.     public function onInitialLoyalty(SubscriptionCreatedEvent $event): void
  52.     {
  53.         $this->subscriptionLoyaltyUpdateService->updateNextLoyalty(
  54.             $event->getSubscriptionId(),
  55.             $event->getContext()
  56.         );
  57.     }
  58.     public function onUpdateNextLoyalty(OrderCreatedEvent $event): void
  59.     {
  60.         $this->subscriptionLoyaltyUpdateService->updateNextLoyalty(
  61.             $event->getSubscriptionOrderEntity()->getId(),
  62.             $event->getContext()
  63.         );
  64.     }
  65. }