custom/plugins/SwagAmazonPay/src/Framework/EventListeners/AmazonPayAddressValidationListener.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Swag\AmazonPay\Framework\EventListeners;
  9. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\Validator\Constraints\Optional;
  13. class AmazonPayAddressValidationListener implements EventSubscriberInterface
  14. {
  15.     private RequestStack $requestStack;
  16.     public function __construct(
  17.         RequestStack $requestStack
  18.     ) {
  19.         $this->requestStack $requestStack;
  20.     }
  21.     /**
  22.      * {@inheritdoc}
  23.      */
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             'framework.validation.address.create' => 'disableAdditionalAddressValidation',
  28.             'framework.validation.address.update' => 'disableAdditionalAddressValidation',
  29.             'framework.validation.customer.create' => 'disableBirthdayValidation',
  30.         ];
  31.     }
  32.     public function disableAdditionalAddressValidation(BuildValidationEvent $event): void
  33.     {
  34.         $request $this->requestStack->getCurrentRequest();
  35.         if ($request === null) {
  36.             return;
  37.         }
  38.         if (\mb_strpos($request->getPathInfo(), 'swag_amazon_pay') === false) {
  39.             return;
  40.         }
  41.         $definition $event->getDefinition();
  42.         $definition->set('additionalAddressLine1', new Optional());
  43.         $definition->set('additionalAddressLine2', new Optional());
  44.         $definition->set('phoneNumber', new Optional());
  45.     }
  46.     public function disableBirthdayValidation(BuildValidationEvent $event): void
  47.     {
  48.         $request $this->requestStack->getCurrentRequest();
  49.         if ($request === null) {
  50.             return;
  51.         }
  52.         if (\mb_strpos($request->getPathInfo(), 'swag_amazon_pay') === false) {
  53.             return;
  54.         }
  55.         $definition $event->getDefinition();
  56.         $definition->set('birthdayDay', new Optional());
  57.         $definition->set('birthdayMonth', new Optional());
  58.         $definition->set('birthdayYear', new Optional());
  59.     }
  60. }