custom/static-plugins/SamsonCustomer/src/Annotation/CustomerNeedsPasswordChange.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Samson\Annotation;
  3. /***
  4.  *
  5.  * This file is part of the "SAMSON Shop" project.
  6.  *
  7.  * For the full copyright and license information, please read the
  8.  * LICENSE.txt file that was distributed with this source code.
  9.  *
  10.  *  (c) 2024
  11.  *
  12.  ***/
  13. use Samson\CustomFieldSet\Constants\CustomerCustomFieldConstants;
  14. use Samson\Entities\CustomerExtension\CustomerExtensionEntity;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
  16. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  17. /**
  18.  * Annotation for store-api/storefront
  19.  *
  20.  * @Annotation
  21.  */
  22. class CustomerNeedsPasswordChange implements ConfigurationInterface
  23. {
  24.     public const ATTRIBUTE_CUSTOMER_NEEDS_PASSWORD_CHANGE '_customerNeedsPasswordChange';
  25.     public function getAliasName(): string
  26.     {
  27.         return 'customerNeedsPasswordChange';
  28.     }
  29.     public function allowArray(): bool
  30.     {
  31.         return false;
  32.     }
  33.     public function customerNeedsPasswordChange(SalesChannelContext $context): bool
  34.     {
  35.         $customer $context->getCustomer();
  36.         if(empty($customer)) {
  37.             return false;
  38.         }
  39.         $isSubAccount = isset($customer->getCustomFields()[CustomerCustomFieldConstants::CUSTOM_FIELD_IS_SUB_ACCOUNT])
  40.             && $customer->getCustomFields()[CustomerCustomFieldConstants::CUSTOM_FIELD_IS_SUB_ACCOUNT];
  41.         if (!$isSubAccount) {
  42.             return false;
  43.         }
  44.         /** @var CustomerExtensionEntity $customerExtension */
  45.         $customerExtension $customer->getExtension('customerExtension');
  46.         if (!is_null($customerExtension) && $customerExtension->needsPasswordChange()) {
  47.             return true;
  48.         }
  49.         return false;
  50.     }
  51. }