Add validate countryIso. Fix bug with duplicate customer address
This commit is contained in:
parent
5407d9111f
commit
6a7c565cb4
@ -84,7 +84,7 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||||||
if ($order instanceof WC_Order && empty($customerBillingAddress)) {
|
if ($order instanceof WC_Order && empty($customerBillingAddress)) {
|
||||||
return array(
|
return array(
|
||||||
'index' => $order->get_billing_postcode(),
|
'index' => $order->get_billing_postcode(),
|
||||||
'countryIso' => $order->get_billing_country(),
|
'countryIso' => $this->validateCountryCode($order->get_billing_country()),
|
||||||
'region' => $this->get_state_name($order->get_billing_country(), $order->get_billing_state()),
|
'region' => $this->get_state_name($order->get_billing_country(), $order->get_billing_state()),
|
||||||
'city' => $order->get_billing_city(),
|
'city' => $order->get_billing_city(),
|
||||||
'text' => $this->joinAddresses($order->get_billing_address_1(), $order->get_billing_address_2())
|
'text' => $this->joinAddresses($order->get_billing_address_1(), $order->get_billing_address_2())
|
||||||
@ -92,7 +92,7 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||||||
} else {
|
} else {
|
||||||
return array(
|
return array(
|
||||||
'index' => $customer->get_billing_postcode(),
|
'index' => $customer->get_billing_postcode(),
|
||||||
'countryIso' => $customer->get_billing_country(),
|
'countryIso' => $this->validateCountryCode($customer->get_billing_country()),
|
||||||
'region' => $this->get_state_name($customer->get_billing_country(), $customer->get_billing_state()),
|
'region' => $this->get_state_name($customer->get_billing_country(), $customer->get_billing_state()),
|
||||||
'city' => $customer->get_billing_city(),
|
'city' => $customer->get_billing_city(),
|
||||||
'text' => $this->joinAddresses($customer->get_billing_address_1(), $customer->get_billing_address_2())
|
'text' => $this->joinAddresses($customer->get_billing_address_1(), $customer->get_billing_address_2())
|
||||||
@ -100,6 +100,20 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate countryIso. Check if a given code represents a valid ISO 3166-1 alpha-2 code.
|
||||||
|
*
|
||||||
|
* @param $countryCode
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function validateCountryCode($countryCode)
|
||||||
|
{
|
||||||
|
$countries = new WC_Countries();
|
||||||
|
|
||||||
|
return $countries->country_exists($countryCode) ? $countryCode : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Glue two addresses
|
* Glue two addresses
|
||||||
*
|
*
|
||||||
|
@ -245,11 +245,11 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface
|
|||||||
*/
|
*/
|
||||||
private static function setBillingAddressToOrder($wcOrder, $address)
|
private static function setBillingAddressToOrder($wcOrder, $address)
|
||||||
{
|
{
|
||||||
$wcOrder->set_billing_state(self::arrayValue($address, 'region', '--'));
|
$wcOrder->set_billing_state(self::arrayValue($address, 'region', ''));
|
||||||
$wcOrder->set_billing_postcode(self::arrayValue($address, 'index', '--'));
|
$wcOrder->set_billing_postcode(self::arrayValue($address, 'index', ''));
|
||||||
$wcOrder->set_billing_country(self::arrayValue($address, 'country', '--'));
|
$wcOrder->set_billing_country(self::arrayValue($address, 'country', ''));
|
||||||
$wcOrder->set_billing_city(self::arrayValue($address, 'city', '--'));
|
$wcOrder->set_billing_city(self::arrayValue($address, 'city', ''));
|
||||||
$wcOrder->set_billing_address_1(self::arrayValue($address, 'text', '--'));
|
$wcOrder->set_billing_address_1(self::arrayValue($address, 'text', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,11 +262,11 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface
|
|||||||
*/
|
*/
|
||||||
private static function setShippingAddressToOrder($wcOrder, $address)
|
private static function setShippingAddressToOrder($wcOrder, $address)
|
||||||
{
|
{
|
||||||
$wcOrder->set_shipping_state(self::arrayValue($address, 'region', '--'));
|
$wcOrder->set_shipping_state(self::arrayValue($address, 'region', ''));
|
||||||
$wcOrder->set_shipping_postcode(self::arrayValue($address, 'index', '--'));
|
$wcOrder->set_shipping_postcode(self::arrayValue($address, 'index', ''));
|
||||||
$wcOrder->set_shipping_country(self::arrayValue($address, 'country', '--'));
|
$wcOrder->set_shipping_country(self::arrayValue($address, 'country', ''));
|
||||||
$wcOrder->set_shipping_city(self::arrayValue($address, 'city', '--'));
|
$wcOrder->set_shipping_city(self::arrayValue($address, 'city', ''));
|
||||||
$wcOrder->set_shipping_address_1(self::arrayValue($address, 'text', '--'));
|
$wcOrder->set_shipping_address_1(self::arrayValue($address, 'text', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user