address fixes
This commit is contained in:
parent
40d54c6b62
commit
a5f6a84741
3 changed files with 37 additions and 21 deletions
|
@ -20,6 +20,9 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||
/** @var bool $fallback_to_billing */
|
||||
protected $fallback_to_billing = false;
|
||||
|
||||
/** @var bool $fallback_to_shipping */
|
||||
protected $fallback_to_shipping = false;
|
||||
|
||||
/** @var array $data */
|
||||
protected $data = array(
|
||||
'index' => '',
|
||||
|
@ -54,6 +57,17 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $fallback_to_shipping
|
||||
*
|
||||
* @return WC_Retailcrm_Abstracts_Address
|
||||
*/
|
||||
public function setFallbackToShipping($fallback_to_shipping)
|
||||
{
|
||||
$this->fallback_to_shipping = $fallback_to_shipping;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets woocommerce address type to work with
|
||||
*
|
||||
|
@ -78,9 +92,15 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||
{
|
||||
$orderAddress = $order->get_address($this->address_type);
|
||||
|
||||
return (empty($orderAddress) && $this->fallback_to_billing)
|
||||
? $order->get_address(self::ADDRESS_TYPE_BILLING)
|
||||
: $order->get_address($this->address_type);
|
||||
if (empty($orderAddress) && $this->address_type === self::ADDRESS_TYPE_BILLING && $this->fallback_to_shipping) {
|
||||
$orderAddress = $order->get_address(self::ADDRESS_TYPE_SHIPPING);
|
||||
}
|
||||
|
||||
if (empty($orderAddress) && $this->address_type === self::ADDRESS_TYPE_SHIPPING && $this->fallback_to_billing) {
|
||||
$orderAddress = $order->get_address(self::ADDRESS_TYPE_BILLING);
|
||||
}
|
||||
|
||||
return $orderAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -257,10 +257,10 @@ if (!class_exists('WC_Retailcrm_Customers')) :
|
|||
$found = false;
|
||||
$builder = new WC_Retailcrm_Customer_Corporate_Address();
|
||||
$newAddress = $builder
|
||||
->setFallbackToBilling(true)
|
||||
->setFallbackToShipping(true)
|
||||
->setIsMain(false)
|
||||
->setExplicitIsMain(false)
|
||||
->setWCAddressType(WC_Retailcrm_Abstracts_Address::ADDRESS_TYPE_SHIPPING)
|
||||
->setWCAddressType(WC_Retailcrm_Abstracts_Address::ADDRESS_TYPE_BILLING)
|
||||
->build($customer, $order)
|
||||
->get_data();
|
||||
$addresses = $this->retailcrm->customersCorporateAddresses(
|
||||
|
|
|
@ -17,12 +17,6 @@ class WC_Retailcrm_Customer_Corporate_Address extends WC_Retailcrm_Abstracts_Add
|
|||
/** @var string $filter_name */
|
||||
protected $filter_name = 'customer_address';
|
||||
|
||||
/** @var string $address_type */
|
||||
protected $address_type = 'shipping';
|
||||
|
||||
/** @var bool $fallback_to_billing */
|
||||
protected $fallback_to_billing = false;
|
||||
|
||||
/** @var bool $isMain */
|
||||
protected $isMain = true;
|
||||
|
||||
|
@ -43,13 +37,13 @@ class WC_Retailcrm_Customer_Corporate_Address extends WC_Retailcrm_Abstracts_Add
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $fallback_to_billing
|
||||
* @param bool $fallback_to_shipping
|
||||
*
|
||||
* @return WC_Retailcrm_Customer_Corporate_Address
|
||||
*/
|
||||
public function setFallbackToBilling($fallback_to_billing)
|
||||
public function setFallbackToShipping($fallback_to_shipping)
|
||||
{
|
||||
$this->fallback_to_billing = $fallback_to_billing;
|
||||
$this->fallback_to_shipping = $fallback_to_shipping;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -93,16 +87,18 @@ class WC_Retailcrm_Customer_Corporate_Address extends WC_Retailcrm_Abstracts_Add
|
|||
'name' => $address['company'],
|
||||
'text' => $this->joinAddresses($address['address_1'], $address['address_2'])
|
||||
);
|
||||
} else {
|
||||
if (WC_Retailcrm_Abstracts_Address::ADDRESS_TYPE_SHIPPING == $this->address_type) {
|
||||
$data = $this->getCustomerBillingAddress($customer);
|
||||
} else if (self::ADDRESS_TYPE_SHIPPING === $this->address_type) {
|
||||
$data = $this->getCustomerShippingAddress($customer);
|
||||
|
||||
if (empty($address) && $this->fallback_to_billing) {
|
||||
$data = $this->getCustomerShippingAddress($customer);
|
||||
}
|
||||
} else {
|
||||
if (empty($address) && $this->fallback_to_billing) {
|
||||
$data = $this->getCustomerBillingAddress($customer);
|
||||
}
|
||||
} elseif (self::ADDRESS_TYPE_BILLING === $this->address_type) {
|
||||
$data = $this->getCustomerBillingAddress($customer);
|
||||
|
||||
if (empty($address) && $this->fallback_to_shipping) {
|
||||
$data = $this->getCustomerShippingAddress($customer);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isMain) {
|
||||
|
|
Loading…
Add table
Reference in a new issue