setActiveBillingAddress example

$streetName = $ruleConstraints['streetName'];
        static::assertEquals(new NotBlank()$streetName[0]);
        static::assertEquals(new Type('string')$streetName[1]);
    }

    public function testUnsupportedValue(): void
    {
        try {
            $rule = new BillingStreetRule();
            $salesChannelContext = $this->createMock(SalesChannelContext::class);
            $customer = new CustomerEntity();
            $customer->setActiveBillingAddress(new CustomerAddressEntity());
            $salesChannelContext->method('getCustomer')->willReturn($customer);
            $rule->match(new CheckoutRuleScope($salesChannelContext));
            static::fail('Exception was not thrown');
        } catch (\Throwable $exception) {
            static::assertInstanceOf(UnsupportedValueException::class$exception);
        }
    }

    public function testRuleNotMatchingWithoutAddress(): void
    {
        $this->rule->assign(['streetName' => 'foo', 'operator' => Rule::OPERATOR_EQ]);
        
/** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, string $billingCity): void
    {
        $cityName = 'kyln123';
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $customerAddress = new CustomerAddressEntity();
        $customerAddress->setCity($billingCity);

        $customer = new CustomerEntity();
        $customer->setActiveBillingAddress($customerAddress);
        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $scope = new CheckoutRuleScope($salesChannelContext);
        $this->rule->assign(['cityName' => $cityName, 'operator' => $operator]);

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }

    
$this->rule->assign(['countryIds' => ['foo'], 'operator' => Rule::OPERATOR_EQ]);
        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        static::assertFalse($this->rule->match(new CheckoutRuleScope($salesChannelContext)));

        $customer = new CustomerEntity();
        $salesChannelContext->method('getCustomer')->willReturn($customer);

        static::assertFalse($this->rule->match(new CheckoutRuleScope($salesChannelContext)));

        $customerAddress = new CustomerAddressEntity();
        $customer->setActiveBillingAddress($customerAddress);
        $salesChannelContext->method('getCustomer')->willReturn($customer);

        static::assertFalse($this->rule->match(new CheckoutRuleScope($salesChannelContext)));
    }

    /** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, string $countryId, bool $noCustomer = false, bool $noCountry = false, bool $noAddress = false): void
    {
        $countryIds = ['kyln123', 'kyln456'];
        
/** * @dataProvider getMatchValuesNumeric */
    public function testRuleMatchingNumeric(string $operator, bool $isMatching, string $zipCode): void
    {
        $zipCodes = ['90210', '81985'];
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $customerAddress = new CustomerAddressEntity();
        $customerAddress->setZipcode($zipCode);

        $customer = new CustomerEntity();
        $customer->setActiveBillingAddress($customerAddress);
        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $scope = new CheckoutRuleScope($salesChannelContext);
        $this->rule->assign(['zipCodes' => $zipCodes, 'operator' => $operator]);

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }

    
/** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, string $stateId): void
    {
        $countryIds = ['kyln123', 'kyln456'];
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $customerAddress = new CustomerAddressEntity();
        $customerAddress->setCountryStateId($stateId);
        $customer = new CustomerEntity();

        $customer->setActiveBillingAddress($customerAddress);
        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $scope = new CheckoutRuleScope($salesChannelContext);
        $this->rule->assign(['stateIds' => $countryIds, 'operator' => $operator]);

        $match = $this->rule->match($scope);
        if ($isMatching) {
            static::assertTrue($match);
        } else {
            static::assertFalse($match);
        }
    }

    
$rule = new DifferentAddressesRule();
        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        static::assertFalse($rule->match(new CheckoutRuleScope($salesChannelContext)));

        $customer = new CustomerEntity();
        $salesChannelContext->method('getCustomer')->willReturn($customer);

        static::assertFalse($rule->match(new CheckoutRuleScope($salesChannelContext)));

        $customerAddress = new CustomerAddressEntity();
        $customer->setActiveBillingAddress($customerAddress);
        $salesChannelContext->method('getCustomer')->willReturn($customer);

        static::assertFalse($rule->match(new CheckoutRuleScope($salesChannelContext)));
    }
}
$criteria = new Criteria(\array_unique($addressIds));
        $criteria->setTitle('context-factory::addresses');
        $criteria->addAssociation('salutation');
        $criteria->addAssociation('country');
        $criteria->addAssociation('countryState');

        $addresses = $this->addressRepository->search($criteria$context);

        /** @var CustomerAddressEntity $activeBillingAddress */
        $activeBillingAddress = $addresses->get($activeBillingAddressId);
        $customer->setActiveBillingAddress($activeBillingAddress);
        /** @var CustomerAddressEntity $activeShippingAddress */
        $activeShippingAddress = $addresses->get($activeShippingAddressId);
        $customer->setActiveShippingAddress($activeShippingAddress);
        /** @var CustomerAddressEntity $defaultBillingAddress */
        $defaultBillingAddress = $addresses->get($customer->getDefaultBillingAddressId());
        $customer->setDefaultBillingAddress($defaultBillingAddress);
        /** @var CustomerAddressEntity $defaultShippingAddress */
        $defaultShippingAddress = $addresses->get($customer->getDefaultShippingAddressId());
        $customer->setDefaultShippingAddress($defaultShippingAddress);

        return $customer;
    }
Home | Imprint | This part of the site doesn't use cookies.