setFirstLogin example


    public function testIfMatchesCorrect(
        string $operator,
        bool $isMatching,
        float $daysPassed,
        ?\DateTimeImmutable $day,
        bool $noCustomer = false
    ): void {
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $customer = new CustomerEntity();
        $customer->setFirstLogin($day);

        if ($noCustomer) {
            $customer = null;
        }
        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $scope = $this->createMock(CheckoutRuleScope::class);
        $scope->method('getSalesChannelContext')->willReturn($salesChannelContext);
        $scope->method('getCurrentTime')->willReturn(self::getTestTimestamp());

        $this->rule->assign([
            'operator' => $operator,
            
class IsNewCustomerRuleTest extends TestCase
{
    public function testIsNewCustomer(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        $rule = new IsNewCustomerRule();

        $cart = new Cart('test');

        $customer = new CustomerEntity();
        $customer->setFirstLogin(new \DateTime());

        $context = $this->createMock(SalesChannelContext::class);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    
private function saveCustomer(ShopStruct $shop, Customer $customer): void
    {
        if ($customer->getValidation() !== ContextService::FALLBACK_CUSTOMER_GROUP) {
            $customer->setCustomerType(Customer::CUSTOMER_TYPE_BUSINESS);
        }

        $customerConfirmed = !$customer->getDoubleOptinRegister() || $customer->getDoubleOptinConfirmDate() !== null;
        $customer->setActive($customerConfirmed);

        if (!$customerConfirmed) {
            // Reset login information if Double-Opt-In is active             $customer->setFirstLogin(null);
            $customer->setLastLogin(null);
            $customer->setDoubleOptinEmailSentDate(new DateTime());
        }

        // Password validation         if ($customer->getPassword()) {
            $customer->setEncoderName(
                $this->passwordManager->getDefaultPasswordEncoderName()
            );
            $customer->setPassword(
                $this->passwordManager->encodePassword(
                    
$redirection = [
                'controller' => 'checkout',
                'action' => 'confirm',
            ];
        } else {
            $redirection = [
                'controller' => 'account',
                'action' => 'index',
            ];
        }

        $customer->setFirstLogin($date);
        $customer->setDoubleOptinConfirmDate($date);
        $customer->setActive(true);
        $customer->setRegisterOptInId(null);

        $modelManager->persist($customer);
        $modelManager->flush();

        $sql = "DELETE FROM `s_core_optin` WHERE `hash` = ? AND type = 'swRegister'";
        $connection->executeQuery($sql[$this->Request()->get('sConfirmation')]);

        $this->saveRegisterSuccess($data$customer);
        
$customer->setBirthday(new DateTime($data['__customer_birthday']));
        }

        if ($customer->getBirthday()) {
            $customer->setAge($customer->getBirthday()->diff(new DateTime())->y);
        }

        if (!empty($data['__customer_lockeduntil'])) {
            $customer->setLockedUntil(new DateTime($data['__customer_lockeduntil']));
        }
        if (!empty($data['__customer_firstlogin'])) {
            $customer->setFirstLogin(new DateTime($data['__customer_firstlogin']));
        }
        if (!empty($data['__customer_lastlogin'])) {
            $customer->setLastLogin(new DateTime($data['__customer_lastlogin']));
        }

        if ($data['__customer_customergroup']) {
            $customer->setCustomerGroup(
                $this->customerGroupHydrator->hydrate($data)
            );
        }

        
->find($paymentId);
            $paymentData->setPaymentMean($payment);
        }

        $params = $this->prepareCustomerData($params$customer$paymentData);

        // Set parameter to the customer model.         $customer->fromArray($params);

        // If user will be activated, but the first login is still 0, because he was in doi-process         if ($customer->getActive() && (!$customer->getFirstLogin() || $customer->getFirstLogin()->getTimestamp() === 0)) {
            $customer->setFirstLogin(new DateTime());
        }

        $password = $this->Request()->getParam('newPassword');

        // Encode the password with md5         if (!empty($password)) {
            $customer->setPassword($password);
        }

        if (!$customer->getNumber() && Shopware()->Config()->get('shopwareManagedCustomerNumbers')) {
            /** @var NumberRangeIncrementerInterface $incrementer */
            
Home | Imprint | This part of the site doesn't use cookies.