setCountry example

$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)
            );
        }
        if ($address->getStateId()) {
            $address->setState(
                $this->countryHydrator->hydrateState($data)
            );
        }

        if ($data['__addressAttribute_id']) {
            $this->attributeHydrator->addAttribute($address$data, 'addressAttribute');
        }
$country = new CountryEntity();
        $customer = new CustomerEntity();

        $country->setId($countryId);
        if ($noCountry) {
            $country = null;
        }

        if (!$noAddress) {
            if ($country) {
                $customerAddress->setCountry($country);
            }

            $customer->setActiveBillingAddress($customerAddress);
        }

        if ($noCustomer) {
            $customer = null;
        }

        $salesChannelContext->method('getCustomer')->willReturn($customer);
        $scope = new CheckoutRuleScope($salesChannelContext);
        
$address = new OrderAddressEntity();
        $address->setId('order-address-id');
        $address->setSalutationId('order-address-salutation-id');
        $address->setFirstName('order-address-first-name');
        $address->setLastName('order-address-last-name');
        $address->setStreet('order-address-street');
        $address->setZipcode('order-address-zipcode');
        $address->setCity('order-address-city');
        $address->setCountryId('order-address-country-id');
        $address->setCountryStateId('order-address-country-state-id');
        $address->setCountry($country);
        $address->setCountryState($countryState);

        return $address;
    }

    private function getDeliveryCollection(bool $withoutAddress = false): DeliveryCollection
    {
        $country = new CountryEntity();
        $country->setId('country-id');
        $country->setName('country-name');

        
->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;
    }
}

        $this->setCompany((string) $address->getCompany());
        $this->setDepartment((string) $address->getDepartment());
        $this->setSalutation((string) $address->getSalutation());
        $this->setFirstName((string) $address->getFirstname());
        $this->setLastName((string) $address->getLastname());
        $this->setStreet((string) $address->getStreet());
        $this->setCity((string) $address->getCity());
        $this->setZipCode((string) $address->getZipcode());
        $this->setAdditionalAddressLine1((string) $address->getAdditionalAddressLine1());
        $this->setAdditionalAddressLine2((string) $address->getAdditionalAddressLine2());
        $this->setCountry($address->getCountry());
        $this->setPhone((string) $address->getPhone());
        $this->setVatId((string) $address->getVatId());
        $this->setTitle($address->getTitle());

        if ($address->getState()) {
            $this->setState($address->getState());
        } else {
            $this->setState(null);
        }

        $attributeData = Shopware()->Models()->toArray($address->getAttribute());
        
$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;
    }
}
$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;
    }
}
if (!$country instanceof CountryModel) {
            throw new NotFoundException(sprintf('Billing Country by id %s not found', $billing['countryId']));
        }

        if (!$order->getCustomer() instanceof CustomerModel) {
            throw new NotFoundException(sprintf('Order with ID "%s" has no customer', $order->getId()));
        }

        $billingAddress = new Billing();
        $billingAddress->fromArray($billing);
        $billingAddress->setCustomer($order->getCustomer());
        $billingAddress->setCountry($country);
        $billingAddress->setState($state);

        $violations = $this->getManager()->validate($billingAddress);
        if ($violations->count() > 0) {
            throw new ValidationException($violations);
        }

        $shipping = $params['shipping'];
        $country = null;
        $state = null;

        

    }

    private function createAddress(string $street): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $state = new CountryStateEntity();
        $country = new CountryEntity();
        $state->setCountryId('SWAG-AREA-COUNTRY-ID-1');

        $address->setStreet($street);
        $address->setCountry($country);
        $address->setCountryState($state);

        return $address;
    }
}
// Casting null values to empty strings to fulfill the restrictions of the s_order_billingaddress table         $billingAddress = array_map(function D$value) {
            return (string) $value;
        }$result[0]['customer']['defaultBillingAddress']);

        $billingCountry = $this->get('models')->find(Country::class$result[0]['customer']['defaultBillingAddress']['countryId']);

        // Create new entry in s_order_billingaddress         $billingModel = new Shopware\Models\Order\Billing();
        $billingModel->fromArray($billingAddress);
        $billingModel->setCountry($billingCountry);
        $billingModel->setCustomer($customer);
        $billingModel->setOrder($orderModel);
        $this->get('models')->persist($billingModel);

        // Casting null values to empty strings to fulfill the restrictions of the s_order_shippingaddress table         $shippingAddress = array_map(function D$value) {
            return (string) $value;
        }$result[0]['customer']['defaultShippingAddress']);

        $shippingCountry = $this->get('models')->find(Country::class$result[0]['customer']['defaultShippingAddress']['countryId']);

        
$country->setCompanyTax(new TaxFreeConfig(false, Defaults::CURRENCY, 0));
            $country->setName('Germany');
        }
        if (!$state) {
            $state = new CountryStateEntity();
            $state->setId('bd5e2dcf547e4df6bb1ff58a554bc69e');
            $state->setCountryId($country->getId());
        }

        if (!$shipping) {
            $shipping = new CustomerAddressEntity();
            $shipping->setCountry($country);
            $shipping->setCountryState($state);
        }

        if (!$paymentMethod) {
            $paymentMethod = (new PaymentMethodEntity())->assign(
                [
                    'id' => '19d144ffe15f4772860d59fca7f207c1',
                    'handlerIdentifier' => SyncTestPaymentHandler::class,
                    'name' => 'Generated Payment',
                    'active' => true,
                ]
            );

        $this->setCompany((string) $address->getCompany());
        $this->setDepartment((string) $address->getDepartment());
        $this->setSalutation((string) $address->getSalutation());
        $this->setFirstName((string) $address->getFirstname());
        $this->setLastName((string) $address->getLastname());
        $this->setStreet((string) $address->getStreet());
        $this->setCity((string) $address->getCity());
        $this->setZipCode((string) $address->getZipcode());
        $this->setAdditionalAddressLine1((string) $address->getAdditionalAddressLine1());
        $this->setAdditionalAddressLine2((string) $address->getAdditionalAddressLine2());
        $this->setCountry($address->getCountry());
        $this->setPhone($address->getPhone());
        $this->setTitle($address->getTitle());
        if ($address->getState()) {
            $this->setState($address->getState());
        } else {
            $this->setState(null);
        }

        $attributeData = Shopware()->Models()->toArray($address->getAttribute());
        $this->setAttribute($attributeData);
    }

    

        $rule = (new BillingCountryRule())->assign(['countryIds' => ['SWAG-AREA-COUNTRY-ID-1']]);

        $cart = new Cart('test');

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

        $country = new CountryEntity();
        $country->setId('SWAG-AREA-COUNTRY-ID-1');

        $billing = new CustomerAddressEntity();
        $billing->setCountry($country);

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

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

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }
Home | Imprint | This part of the site doesn't use cookies.