<?php declare(strict_types=1);
namespace Samson\Annotation;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2024
*
***/
use Samson\CustomFieldSet\Constants\CustomerCustomFieldConstants;
use Samson\Entities\CustomerExtension\CustomerExtensionEntity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
/**
* Annotation for store-api/storefront
*
* @Annotation
*/
class CustomerNeedsPasswordChange implements ConfigurationInterface
{
public const ATTRIBUTE_CUSTOMER_NEEDS_PASSWORD_CHANGE = '_customerNeedsPasswordChange';
public function getAliasName(): string
{
return 'customerNeedsPasswordChange';
}
public function allowArray(): bool
{
return false;
}
public function customerNeedsPasswordChange(SalesChannelContext $context): bool
{
$customer = $context->getCustomer();
if(empty($customer)) {
return false;
}
$isSubAccount = isset($customer->getCustomFields()[CustomerCustomFieldConstants::CUSTOM_FIELD_IS_SUB_ACCOUNT])
&& $customer->getCustomFields()[CustomerCustomFieldConstants::CUSTOM_FIELD_IS_SUB_ACCOUNT];
if (!$isSubAccount) {
return false;
}
/** @var CustomerExtensionEntity $customerExtension */
$customerExtension = $customer->getExtension('customerExtension');
if (!is_null($customerExtension) && $customerExtension->needsPasswordChange()) {
return true;
}
return false;
}
}