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

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.     /**
  16.      * @var RequestStack
  17.      */
  18.     private $requestStack;
  19.     public function __construct(
  20.         RequestStack $requestStack
  21.     ) {
  22.         $this->requestStack $requestStack;
  23.     }
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             'framework.validation.address.create' => 'disableAdditionalAddressValidation',
  31.             'framework.validation.address.update' => 'disableAdditionalAddressValidation',
  32.             'framework.validation.customer.create' => 'disableBirthdayValidation',
  33.         ];
  34.     }
  35.     public function disableAdditionalAddressValidation(BuildValidationEvent $event): void
  36.     {
  37.         $request $this->requestStack->getCurrentRequest();
  38.         if ($request === null) {
  39.             return;
  40.         }
  41.         if (\mb_strpos($request->getPathInfo(), 'swag_amazon_pay') === false) {
  42.             return;
  43.         }
  44.         $definition $event->getDefinition();
  45.         $definition->set('additionalAddressLine1', new Optional());
  46.         $definition->set('additionalAddressLine2', new Optional());
  47.         $definition->set('phoneNumber', new Optional());
  48.     }
  49.     public function disableBirthdayValidation(BuildValidationEvent $event): void
  50.     {
  51.         $request $this->requestStack->getCurrentRequest();
  52.         if ($request === null) {
  53.             return;
  54.         }
  55.         if (\mb_strpos($request->getPathInfo(), 'swag_amazon_pay') === false) {
  56.             return;
  57.         }
  58.         $definition $event->getDefinition();
  59.         $definition->set('birthdayDay', new Optional());
  60.         $definition->set('birthdayMonth', new Optional());
  61.         $definition->set('birthdayYear', new Optional());
  62.     }
  63. }