setZipcode example

public function hydrate(array $data)
    {
        $address = new Address();
        $address->setId((int) $data['__address_id']);
        $address->setCompany($data['__address_company']);
        $address->setDepartment($data['__address_department']);
        $address->setSalutation($data['__address_salutation']);
        $address->setTitle($data['__address_title']);
        $address->setFirstname($data['__address_firstname']);
        $address->setLastname($data['__address_lastname']);
        $address->setStreet($data['__address_street']);
        $address->setZipcode($data['__address_zipcode']);
        $address->setCity($data['__address_city']);
        $address->setCountryId((int) $data['__address_country_id']);
        $address->setStateId((int) $data['__address_state_id']);
        $address->setVatId($data['__address_ustid']);
        $address->setPhone($data['__address_phone']);
        $address->setAdditionalAddressLine1($data['__address_additional_address_line1']);
        $address->setAdditionalAddressLine2($data['__address_additional_address_line2']);

        if ($address->getCountryId()) {
            $address->setCountry(
                $this->countryHydrator->hydrateCountry($data)
            );
private function getCustomer(): CustomerEntity
    {
        $faker = Factory::create();

        $billingAddress = new CustomerAddressEntity();
        $billingAddress->setId('SWAG-ADDRESS-ID-1');
        $billingAddress->setSalutationId($this->getValidSalutationId());
        $billingAddress->setFirstName($faker->firstName);
        $billingAddress->setLastName($faker->lastName);
        $billingAddress->setStreet($faker->streetAddress);
        $billingAddress->setZipcode($faker->postcode);
        $billingAddress->setCity($faker->city);
        $billingAddress->setCountryId('SWAG-AREA-COUNTRY-ID-1');

        $customer = new CustomerEntity();
        $customer->setId('SWAG-CUSTOMER-ID-1');
        $customer->setDefaultBillingAddress($billingAddress);
        $customer->setEmail('test@example.com');
        $customer->setSalutationId($this->getValidSalutationId());
        $customer->setFirstName($faker->firstName);
        $customer->setLastName($faker->lastName);
        $customer->setCustomerNumber('Test');

        


    /** * @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);

        $location = new ShippingLocation(new CountryEntity(), null, $customerAddress);
        $salesChannelContext->method('getShippingLocation')->willReturn($location);
        $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);
        }

        $country = new CountryEntity();
        $country->setId('country-id');

        return $country;
    }

    private function getAddress(): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $address->setId('address-id');
        $address->setZipcode('2');
        $address->setCountry($this->getCountry());

        return $address;
    }
}
class BillingZipCodeRuleTest extends TestCase
{
    public function testEqualsWithSingleCode(): void
    {
        $rule = (new BillingZipCodeRule())->assign(['zipCodes' => ['ABC123']]);

        $cart = new Cart('test');

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

        $billing = new CustomerAddressEntity();
        $billing->setZipcode('ABC123');

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);

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

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }
->method('getShippingLocation')
            ->willReturn($location);

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

    private function createAddress(string $code): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $address->setZipcode($code);
        $address->setCountry(new CountryEntity());

        return $address;
    }
}
static::assertEquals(new ArrayOfType('string')$zipCodes[1]);
    }

    /** * @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 {
            

        $customer = new CustomerEntity();
        $customer->setId('1');
        $customer->setCustomerNumber('');
        $customer->setFirstName('');
        $customer->setLastName('');

        $address = new CustomerAddressEntity();
        $address->setId('');
        $address->setFirstName('');
        $address->setLastName('');
        $address->setZipcode('');
        $address->setCity('');

        return [
            new ProfileSalutationMissingError($customer),
            new BillingAddressSalutationMissingError($address),
            new ShippingAddressSalutationMissingError($address),
        ];
    }

    /** * @param array<BundleFixture> $bundles */
return $customer;
    }

    private function getCustomerAddress(): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $address->setId('billing-address-id');
        $address->setSalutationId('billing-address-salutation-id');
        $address->setFirstName('billing-address-first-name');
        $address->setLastName('billing-address-last-name');
        $address->setStreet('billing-address-street');
        $address->setZipcode('billing-address-zipcode');
        $address->setCity('billing-address-city');
        $address->setCountryId('billing-address-country-id');

        return $address;
    }

    private function getOrderCustomer(): OrderCustomerEntity
    {
        $customer = new OrderCustomerEntity();
        $customer->setId('order-customer-id');
        $customer->setCustomerId('customer-id');
        

        $country = new CountryEntity();
        $country->setId('country-id');

        return $country;
    }

    private function getAddress(): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $address->setId('address-id');
        $address->setZipcode('zip-code');
        $address->setCountry($this->getCountry());

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