Billing example

// Copy customer number into billing address from customer         $result[0]['customer']['defaultBillingAddress']['number'] = $customer->getNumber();

        // 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']);

        


        $billing = $order->getBilling();
        $shipping = $order->getShipping();

        // Check if the shipping and billing model already exist. If not create a new instance.         if (!$shipping instanceof Shipping) {
            $shipping = new Shipping();
        }

        if (!$billing instanceof Billing) {
            $billing = new Billing();
        }
        // Get all passed order data         $data = $this->Request()->getParams();

        if ($order->getChanged() !== null) {
            try {
                $changed = new DateTime($data['changed']);
            } catch (Exception $e) {
                // If we have an invalid date caused by imports                 $changed = $order->getChanged();
            }

            


        $country = $this->getContainer()->get(ModelManager::class)->find(CountryModel::class$billing['countryId']);
        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'];
        
Home | Imprint | This part of the site doesn't use cookies.