From ca8d2ded1ea42a9cf06598b96f98b431f90b53ab Mon Sep 17 00:00:00 2001 From: iesus Date: Wed, 7 Feb 2018 11:54:13 +0100 Subject: [PATCH] try to extract first/last-names from fullname if not populated in first/last fields --- .../Checkout/Model/Payment/CreateOrder.php | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/app/code/community/Svea/Checkout/Model/Payment/CreateOrder.php b/app/code/community/Svea/Checkout/Model/Payment/CreateOrder.php index 7fbe8cd..11a2b9b 100755 --- a/app/code/community/Svea/Checkout/Model/Payment/CreateOrder.php +++ b/app/code/community/Svea/Checkout/Model/Payment/CreateOrder.php @@ -116,28 +116,42 @@ protected function _addAddressToQuote($quote, $data) $shippingAddress = new Varien_Object($data->getData('ShippingAddress')); $customer = new Varien_Object($data->getData('Customer')); + $fakeFull = explode(' ', $billingAddress->getData('FullName')); + $fakeFirst = (end($fakeFull)) ? end($fakeFull) : $notNull; + $fakeLast = (isset($fakeFull[0])) ? $fakeFull[0] : $notNull; + + $fakeFullShipping = explode(' ', $shippingAddress->getData('FullName')); + $fakeFirstShipping = (end($fakeFull)) ? end($fakeFull) : $notNull; + $fakeLastShipping = (isset($fakeFull[0])) ? $fakeFull[0] : $notNull; + + $reference = ($data->getData('CustomerReference')) - ? ($data->getData('CustomerReference')) - : false; + ? ($data->getData('CustomerReference')) + : false; $reference = (!$reference && $customer->getData('CustomerReference')) - ? ($customer->getData('CustomerReference')) - : false; + ? ($customer->getData('CustomerReference')) + : false; + + $billingFirstname = ($billingAddress->getData('FirstName')) - ? $billingAddress->getData('FirstName') - : $notNull; + ? $billingAddress->getData('FirstName') + : $fakeFirst; $billingFirstname = ($billingFirstname) - ? $billingFirstname - : $notNull; + ? $billingFirstname + : $fakeFirst; + + if (true == $customer->getData('IsCompany')) { $billingCompany = $billingAddress->getData('FullName'); $shippingCompany = $shippingAddress->getData('FullName'); $billingFirstname = ($reference) - ? $reference - : $billingFirstname; + ? $reference + : $billingFirstname; } $billingLastname = ($billingAddress->getData('LastName')) - ? $billingAddress->getData('LastName') - : $notNull; + ? $billingAddress->getData('LastName') + : $fakeLast; + $street = implode( "\n", @@ -170,13 +184,13 @@ protected function _addAddressToQuote($quote, $data) $shippingFirstname = $reference; } else { $shippingFirstname = ($shippingAddress->getData('FirstName')) - ? $shippingAddress->getData('FirstName') - : $notNull; + ? $shippingAddress->getData('FirstName') + : $fakeFirstShipping; } $shippingLastname = $shippingAddress->getData('LastName') - ? $shippingAddress->getData('LastName') - : $notNull; + ? $shippingAddress->getData('LastName') + : $fakeLastShipping; $street = implode( "\n",