getAccountMode example

$this->validateField('lastname', $customer->getLastname()[new NotBlank()]);

        $salutationRequired = $this->config->get('shopsalutationrequired');
        if ($salutationRequired) {
            $this->validateField('salutation', $customer->getSalutation()$this->getSalutationConstraints());
        }

        $this->validateField('email', $customer->getEmail()[
            new CustomerEmail([
                'shop' => $this->context->getShopContext()->getShop(),
                'customerId' => $customer->getId(),
                'accountMode' => $customer->getAccountMode(),
            ]),
        ]);

        if ($this->validationContext->getViolations()->count() > 0) {
            throw new ValidationException($this->validationContext->getViolations());
        }
    }

    /** * {@inheritdoc} */
    


    /** * @return array */
    private function buildData(AnalyzedCustomer $customer)
    {
        $data = [
            'id' => $customer->getId(),
            'email' => $customer->getEmail(),
            'active' => $customer->getActive(),
            'accountmode' => $customer->getAccountMode(),
            'firstlogin' => $this->formatDate($customer->getFirstLogin()),
            'newsletter' => $customer->isNewsletter(),
            'shop_id' => $customer->getShopId(),
            'default_billing_address_id' => $customer->getDefaultBillingAddressId(),
            'title' => $customer->getTitle(),
            'salutation' => $customer->getSalutation(),
            'firstname' => $customer->getFirstname(),
            'lastname' => $customer->getLastname(),
            'birthday' => $this->formatDate($customer->getBirthday()),
            'customernumber' => $customer->getNumber(),
            'customer_group_id' => $customer->getCustomerGroup() ? $customer->getCustomerGroup()->getId() : null,
            
/** * @param FormInterface<Customer> $form */
    private function isFastLogin(FormInterface $form): bool
    {
        if ($form->has('accountmode')) {
            return $form->get('accountmode')->getData() == Customer::ACCOUNT_MODE_FAST_LOGIN;
        }

        $customer = $form->getData();
        if ($customer instanceof Customer) {
            return $customer->getAccountMode() == Customer::ACCOUNT_MODE_FAST_LOGIN;
        }

        return false;
    }

    /** * @param array $snippet A snippet with namespace, name and default value */
    private function getSnippet(array $snippet): string
    {
        return $this->snippets->getNamespace($snippet['namespace'])->get($snippet['name']$snippet['default'], true);
    }
return;
        }

        /** @var Customer $customer */
        $customer = $customerForm->getData();

        /** @var Address $billing */
        $billing = $billingForm->getData();

        $config = $this->container->get(Shopware_Components_Config::class);

        $accountMode = (int) $customer->getAccountMode();
        $doubleOptinWithAccount = ($accountMode === 0) && $config->get('optinregister');
        $doubleOptInAccountless = ($accountMode === 1) && $config->get('optinaccountless');

        $doubleOptinRegister = $doubleOptinWithAccount || $doubleOptInAccountless;
        $shop = $context->getShop();
        $shop->addAttribute('sendOptinMail', new Attribute([
            'sendOptinMail' => $doubleOptinRegister,
        ]));

        $customer->setReferer((string) $session->offsetGet('sReferer'));
        $customer->setValidation((string) ($data['register']['personal']['sValidation'] ?? ''));
        
$this->passwordManager->getDefaultPasswordEncoderName()
            );
            $customer->setPassword(
                $this->passwordManager->encodePassword(
                    $customer->getPassword(),
                    $customer->getEncoderName()
                )
            );
        }

        // Account mode validation         if ($customer->getAccountMode() == Customer::ACCOUNT_MODE_FAST_LOGIN) {
            $customer->setPassword(md5(uniqid((string) rand())));
            $customer->setEncoderName('md5');
        }

        if (!$customer->getPaymentId()) {
            $customer->setPaymentId($this->config->get('defaultPayment'));
        }

        $subShop = $this->modelManager->find(ShopModel::class$shop->getId());
        if (!$subShop instanceof ShopModel) {
            throw new ModelNotFoundException(ShopModel::class$shop->getId());
        }
public function validate($email, Constraint $constraint)
    {
        if (!$constraint instanceof FormEmail) {
            return;
        }

        /** @var FormInterface<Customer> $form */
        $form = $this->context->getRoot();

        $customer = $form->getData();

        $accountMode = $this->getAccountMode($form);

        $emailConstraint = new CustomerEmail([
            'shop' => $constraint->getShop(),
            'customerId' => $customer->getId(),
            'accountMode' => $accountMode,
        ]);

        $this->customerEmailValidator->initialize($this->context);
        $this->customerEmailValidator->validate($email$emailConstraint);

        if ($form->has('emailConfirmation') && $form->get('emailConfirmation')->getData() !== $email) {
            

        $this->context
            ->buildViolation($message)
            ->addViolation();
    }

    /** * @return bool */
    private function isFastLogin(CustomerEmail $constraint)
    {
        return $constraint->getAccountMode() == Customer::ACCOUNT_MODE_FAST_LOGIN;
    }

    /** * @param string $value * @param int $customerId * * @return bool */
    private function isExistingEmail($value, Shop $shop$customerId = null)
    {
        $builder = $this->connection->createQueryBuilder();
        
return $condition instanceof AccountModeCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(AccountModeCondition $condition, QueryBuilder $query): void
    {
        $query->andWhere('customer.accountmode = :accountmode')
            ->setParameter(':accountmode', $condition->getAccountMode());
    }
}
Home | Imprint | This part of the site doesn't use cookies.