prepareAddressData example

        if (isset($data['cleared'])) {
            $data['paymentStatus'] = $this->getManager()->find(Status::class$data['cleared']);
        } else {
            unset($data['paymentStatus']);
        }

        // The documents will be created over the "createDocumentAction" so we have to unset the array element, otherwise the         // created documents models would be overwritten.         // For now the paymentInstances information is not editable, so it's just discarded at this point         unset($data['documents']$data['paymentInstances']);

        $data['billing'] = $this->prepareAddressData($data['billing'][0]);
        $data['shipping'] = $this->prepareAddressData($data['shipping'][0]);

        // Unset calculated values         unset($data['invoiceAmountNet']$data['invoiceAmountEuro']);

        // At last, we return the prepared associated data         return $data;
    }

    /** * Creates the status mail order for the passed order id and new status object. * * @return array{mail: Enlight_Components_Mail, data: array<string, mixed>}|null */
$customer = $this->getContainer()->get(ModelManager::class)->find(CustomerModel::class$customerId);
        if (!$customer) {
            throw new NotFoundException(sprintf('Customer by id %s not found', $customerId));
        }

        $this->setupContext($customer->getShop()->getId());

        if (!$params['country']) {
            throw new CustomValidationException('A country is required.');
        }

        $params = $this->prepareAddressData($params);

        $address = new AddressModel();
        $address->fromArray($params);

        $this->addressService->create($address$customer);

        if (!empty($params['__options_set_default_billing_address'])) {
            $this->addressService->setDefaultBillingAddress($address);
        }

        if (!empty($params['__options_set_default_shipping_address'])) {
            

    private function createAddress(?array $data = null): ?AddressModel
    {
        if (empty($data)) {
            return null;
        }

        if (empty($data['country'])) {
            throw new CustomValidationException('A country is required.');
        }

        $data = $this->prepareAddressData($data);

        $address = new AddressModel();
        $address->fromArray($data);

        return $address;
    }

    /** * Resolves ids to models * * @param array<string, mixed> $data * * @return array<string, mixed> */
Home | Imprint | This part of the site doesn't use cookies.