From 91e8973fe7c89955069edc085acd7dadbae01a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alda=20Vigd=C3=ADs=20Skarph=C3=A9=C3=B0insd=C3=B3ttir?= Date: Thu, 4 Jul 2024 11:04:36 +0200 Subject: [PATCH] Creating the customer for an order in DK using separate HTTP calls This is because DK can't take in payment terms, payment methods and ledger codes in the same call as the order. --- src/Export/Order.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Export/Order.php b/src/Export/Order.php index 127443c..bfa3bc8 100644 --- a/src/Export/Order.php +++ b/src/Export/Order.php @@ -4,6 +4,7 @@ namespace NineteenEightyFour\NineteenEightyWoo\Export; +use Automattic\WooCommerce\Admin\API\Customers; use NineteenEightyFour\NineteenEightyWoo\Brick\Math\BigDecimal; use NineteenEightyFour\NineteenEightyWoo\Service\DKApiRequest; use NineteenEightyFour\NineteenEightyWoo\Config; @@ -134,13 +135,12 @@ public static function to_dk_order_body( WC_Order $wc_order ): array { $customer_array['Number'] = OrderHelper::get_kennitala( $wc_order ); if ( ! ExportCustomer::is_in_dk( OrderHelper::get_kennitala( $wc_order ) ) ) { - $customer_array['Name'] = $wc_order->get_formatted_billing_full_name(); - $customer_array['Address1'] = $wc_order->get_billing_address_1(); - $customer_array['Address2'] = $wc_order->get_billing_address_2(); - $customer_array['City'] = $wc_order->get_billing_city(); - $customer_array['ZipCode'] = $wc_order->get_billing_postcode(); - $customer_array['Phone'] = $wc_order->get_billing_phone(); - $customer_array['Email'] = $wc_order->get_billing_email(); + if ( 0 === $wc_order->get_customer_id() ) { + Customer::create_in_dk_from_order( $wc_order ); + } else { + $wc_customer = new WC_Customer( $wc_order->get_customer_id() ); + Customer::create_in_dk( $wc_customer ); + } } $recipient_array['Name'] = $wc_order->get_formatted_billing_full_name(); @@ -152,10 +152,6 @@ public static function to_dk_order_body( WC_Order $wc_order ): array { $store_location = wc_get_base_location(); - if ( $wc_order->get_billing_country() !== $store_location['country'] ) { - $customer_array['Country'] = $wc_order->get_billing_country(); - } - if ( $wc_order->get_shipping_country() !== $store_location['country'] ) { $recipient_array['Country'] = $wc_order->get_shipping_country(); }