diff --git a/src/include/api/class-wc-retailcrm-client-v5.php b/src/include/api/class-wc-retailcrm-client-v5.php index 7ae24ff..3ec37cd 100644 --- a/src/include/api/class-wc-retailcrm-client-v5.php +++ b/src/include/api/class-wc-retailcrm-client-v5.php @@ -893,7 +893,7 @@ class WC_Retailcrm_Client_V5 ); } - if (empty($entity) || !in_array($entity, ['customer', 'order', 'customer_corporate', 'company'])) { + if (empty($entity) || !in_array($entity, array('customer', 'order', 'customer_corporate', 'company'))) { throw new \InvalidArgumentException( sprintf( 'Parameter `entity` must contain a data & value must be %s', diff --git a/src/include/api/class-wc-retailcrm-proxy.php b/src/include/api/class-wc-retailcrm-proxy.php index 9ff3112..9256055 100644 --- a/src/include/api/class-wc-retailcrm-proxy.php +++ b/src/include/api/class-wc-retailcrm-proxy.php @@ -70,12 +70,14 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : */ private function methodsWithoutDebugResponse() { - return array_map( - function ($val) { - return get_class($this->retailcrm) . '::' . $val; - }, - array('statusesList', 'paymentTypesList', 'deliveryTypesList', 'orderMethodsList') - ); + $methodsList = array('statusesList', 'paymentTypesList', 'deliveryTypesList', 'orderMethodsList'); + + foreach ($methodsList as $key => $method) { + $method = get_class($this->retailcrm) . '::' . $method; + $methodsList[$key] = $method; + } + + return $methodsList; } public function __call($method, $arguments) @@ -87,13 +89,13 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : try { WC_Retailcrm_Logger::debug( $called, - empty($arguments) ? '[no params]' : print_r($arguments, true) + array(empty($arguments) ? '[no params]' : print_r($arguments, true)) ); /** @var \WC_Retailcrm_Response $response */ $response = call_user_func_array(array($this->retailcrm, $method), $arguments); if (is_string($response)) { - WC_Retailcrm_Logger::debug($called, $response); + WC_Retailcrm_Logger::debug($called, array($response)); return $response; } @@ -105,9 +107,9 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : $called, $this->methodsWithoutDebugResponse() )) { - WC_Retailcrm_Logger::debug($called, '[request was successful, but response is omitted]'); + WC_Retailcrm_Logger::debug($called, array('[request was successful, but response is omitted]')); } else { - WC_Retailcrm_Logger::debug($called, $response->getRawResponse()); + WC_Retailcrm_Logger::debug($called, array($response->getRawResponse())); } } @@ -123,22 +125,22 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) : $result .= self::reduceErrors($response['errors']); } - WC_Retailcrm_Logger::debug($called, $response->getErrorString()); - WC_Retailcrm_Logger::debug($called, $response->getRawResponse()); + WC_Retailcrm_Logger::debug($called, array($response->getErrorString())); + WC_Retailcrm_Logger::debug($called, array($response->getRawResponse())); } WC_Retailcrm_Logger::add(sprintf("[%s] %s", $called, $result)); } catch (WC_Retailcrm_Exception_Curl $exception) { - WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, $exception->getMessage()); - WC_Retailcrm_Logger::debug('', $exception->getTraceAsString()); + WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, array($exception->getMessage())); + WC_Retailcrm_Logger::debug('', array($exception->getTraceAsString())); WC_Retailcrm_Logger::add(sprintf("[%s] %s - %s", $called, $exception->getMessage(), $result)); } catch (WC_Retailcrm_Exception_Json $exception) { - WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, $exception->getMessage()); - WC_Retailcrm_Logger::debug('', $exception->getTraceAsString()); + WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, array($exception->getMessage())); + WC_Retailcrm_Logger::debug('', array($exception->getTraceAsString())); WC_Retailcrm_Logger::add(sprintf("[%s] %s - %s", $called, $exception->getMessage(), $result)); } catch (InvalidArgumentException $exception) { - WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, $exception->getMessage()); - WC_Retailcrm_Logger::debug('', $exception->getTraceAsString()); + WC_Retailcrm_Logger::debug(get_class($this->retailcrm).'::'.$called, array($exception->getMessage())); + WC_Retailcrm_Logger::debug('', array($exception->getTraceAsString())); WC_Retailcrm_Logger::add(sprintf("[%s] %s - %s", $called, $exception->getMessage(), $result)); } diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index c127c2c..6de59a5 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -157,10 +157,14 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : $customers = WC_Retailcrm_History_Assembler::assemblyCustomer($history); WC_Retailcrm_Plugin::$history_run = true; <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> WIP: Change client in the order (not ready at this point; also tests should fail) ======= WC_Retailcrm_Logger::debug(__METHOD__, 'Assembled customers history:', $customers); >>>>>>> WIP: Logic for company replacement via component (which was surprisingly easy to implement) +======= + WC_Retailcrm_Logger::debug(__METHOD__, array('Assembled customers history:', $customers)); +>>>>>>> Compatibility fixes for php 5.3 foreach ($customers as $crmCustomer) { if (!isset($crmCustomer['externalId'])) { @@ -187,7 +191,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : $wcCustomer->save(); } - WC_Retailcrm_Logger::debug(__METHOD__, 'Updated WC_Customer:', $wcCustomer); + WC_Retailcrm_Logger::debug(__METHOD__, array('Updated WC_Customer:', $wcCustomer)); } catch (\Exception $exception) { WC_Retailcrm_Logger::error(sprintf( 'Error while trying to process history: %s', @@ -244,7 +248,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : if (!empty($history)) { $last_change = end($history); $historyAssembly = WC_Retailcrm_History_Assembler::assemblyOrder($history); - WC_Retailcrm_Logger::debug(__METHOD__, 'Assembled orders history:', $historyAssembly); + WC_Retailcrm_Logger::debug(__METHOD__, array('Assembled orders history:', $historyAssembly)); WC_Retailcrm_Plugin::$history_run = true; foreach ($historyAssembly as $orderHistory) { @@ -922,8 +926,10 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) : WC_Retailcrm_Logger::debug( __METHOD__, - 'processing order', - $order + array( + 'processing order', + $order + ) ); if (isset($order['customer'])) { diff --git a/src/include/components/class-wc-retailcrm-customer-switcher.php b/src/include/components/class-wc-retailcrm-customer-switcher.php index 0cd8500..ab7692c 100644 --- a/src/include/components/class-wc-retailcrm-customer-switcher.php +++ b/src/include/components/class-wc-retailcrm-customer-switcher.php @@ -36,34 +36,42 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface { $this->data->validate(); - WC_Retailcrm_Logger::debug(__METHOD__, 'state', $this->data); + WC_Retailcrm_Logger::debug(__METHOD__, array('state', $this->data)); - if (!empty($this->data->getNewCustomer())) { + $newCustomer = $this->data->getNewCustomer(); + $newContact = $this->data->getNewContact(); + $newCompany = $this->data->getNewCompanyName(); + + if (!empty($newCustomer)) { WC_Retailcrm_Logger::debug( __METHOD__, - 'Changing to individual customer for order', - $this->data->getWcOrder()->get_id() + array( + 'Changing to individual customer for order', + $this->data->getWcOrder()->get_id() + ) ); - $this->processChangeToRegular($this->data->getWcOrder(), $this->data->getNewCustomer()); + $this->processChangeToRegular($this->data->getWcOrder(), $newCustomer); } else { - if (!empty($this->data->getNewContact())) { + if (!empty($newContact)) { WC_Retailcrm_Logger::debug( __METHOD__, - 'Changing to contact person customer for order', - $this->data->getWcOrder()->get_id() + array( + 'Changing to contact person customer for order', + $this->data->getWcOrder()->get_id() + ) ); - $this->processChangeToRegular($this->data->getWcOrder(), $this->data->getNewContact()); + $this->processChangeToRegular($this->data->getWcOrder(), $newContact); } - if (!empty($this->data->getNewCompanyName())) { + if (!empty($newCompany)) { WC_Retailcrm_Logger::debug( __METHOD__, - sprintf( + array(sprintf( 'Replacing old order id=`%d` company `%s` with new company `%s`', $this->data->getWcOrder()->get_id(), $this->data->getWcOrder()->get_billing_company(), - $this->data->getNewCompanyName() - ) + $newCompany + )) ); $this->processCompanyChange(); } @@ -86,10 +94,12 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface WC_Retailcrm_Logger::debug( __METHOD__, - 'Switching in order', - $wcOrder->get_id(), - 'to', - $newCustomer + array( + 'Switching in order', + $wcOrder->get_id(), + 'to', + $newCustomer + ) ); if (isset($newCustomer['externalId'])) { @@ -99,18 +109,22 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface $wcOrder->set_customer_id($wcCustomer->get_id()); WC_Retailcrm_Logger::debug( __METHOD__, - 'Set customer to', - $wcCustomer->get_id(), - 'in order', - $wcOrder->get_id() + array( + 'Set customer to', + $wcCustomer->get_id(), + 'in order', + $wcOrder->get_id() + ) ); } } else { $wcOrder->set_customer_id(0); WC_Retailcrm_Logger::debug( __METHOD__, - 'Set customer to 0 (guest) in order', - $wcOrder->get_id() + array( + 'Set customer to 0 (guest) in order', + $wcOrder->get_id() + ) ); } @@ -148,8 +162,10 @@ class WC_Retailcrm_Customer_Switcher implements WC_Retailcrm_Builder_Interface } } - if (!empty(self::singleCustomerPhone($newCustomer))) { - $wcOrder->set_billing_phone(self::singleCustomerPhone($newCustomer)); + $customerPhone = self::singleCustomerPhone($newCustomer); + + if (!empty($customerPhone)) { + $wcOrder->set_billing_phone($customerPhone); } $wcOrder->set_billing_company(''); diff --git a/src/include/components/class-wc-retailcrm-logger.php b/src/include/components/class-wc-retailcrm-logger.php index 319ecb4..46d1f22 100644 --- a/src/include/components/class-wc-retailcrm-logger.php +++ b/src/include/components/class-wc-retailcrm-logger.php @@ -81,7 +81,7 @@ if (!class_exists('WC_Retailcrm_Logger') && class_exists('WC_Log_Levels')): * @param string $method * @param array $messages */ - public static function debug($method, ...$messages) + public static function debug($method, $messages) { if (retailcrm_is_debug()) { if (!empty($method) && !empty($messages)) { diff --git a/src/include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php b/src/include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php index 2ad5dc6..afbd792 100644 --- a/src/include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php +++ b/src/include/customer/woocommerce/class-wc-retailcrm-wc-customer-builder.php @@ -145,7 +145,7 @@ class WC_Retailcrm_WC_Customer_Builder extends WC_Retailcrm_Abstract_Builder public function build() { $this->checkBuilderValidity(); - WC_Retailcrm_Logger::debug(__METHOD__, 'Building WC_Customer from data:', $this->data); + WC_Retailcrm_Logger::debug(__METHOD__, array('Building WC_Customer from data:', $this->data)); $this->customer->set_first_name($this->dataValue('firstName', $this->customer->get_first_name())); $this->customer->set_last_name($this->dataValue('lastName', $this->customer->get_last_name())); $this->customer->set_billing_email($this->dataValue('email', $this->customer->get_billing_email())); @@ -159,9 +159,9 @@ class WC_Retailcrm_WC_Customer_Builder extends WC_Retailcrm_Abstract_Builder } } - if (!empty($this->dataValue('address'))) { - $address = $this->dataValue('address'); + $address = $this->dataValue('address'); + if (!empty($address)) { $this->customer->set_billing_state(self::arrayValue( $address, 'region', diff --git a/src/include/models/class-wc-retailcrm-customer-switcher-result.php b/src/include/models/class-wc-retailcrm-customer-switcher-result.php index 0664db5..d6b193c 100644 --- a/src/include/models/class-wc-retailcrm-customer-switcher-result.php +++ b/src/include/models/class-wc-retailcrm-customer-switcher-result.php @@ -57,9 +57,11 @@ class WC_Retailcrm_Customer_Switcher_Result { WC_Retailcrm_Logger::debug( __METHOD__, - 'Saving customer and order:', - $this->wcCustomer, - $this->wcOrder + array( + 'Saving customer and order:', + $this->wcCustomer, + $this->wcOrder + ) ); if (!empty($this->wcCustomer)) { diff --git a/src/include/models/class-wc-retailcrm-customer-switcher-state.php b/src/include/models/class-wc-retailcrm-customer-switcher-state.php index 256016b..d75412a 100644 --- a/src/include/models/class-wc-retailcrm-customer-switcher-state.php +++ b/src/include/models/class-wc-retailcrm-customer-switcher-state.php @@ -116,20 +116,22 @@ class WC_Retailcrm_Customer_Switcher_State */ public function validate() { - if (empty($this->getWcOrder())) { + if (empty($this->wcOrder)) { throw new \InvalidArgumentException('Empty WC_Order.'); } - if (empty($this->getNewCustomer()) && empty($this->getNewContact()) && empty($this->getNewCompanyName())) { + if (empty($this->newCustomer) && empty($this->newContact) && empty($this->newCompanyName)) { throw new \InvalidArgumentException('New customer, new contact and new company is empty.'); } - if (!empty($this->getNewCustomer()) && !empty($this->getNewContact())) { + if (!empty($this->newCustomer) && !empty($this->newContact)) { WC_Retailcrm_Logger::debug( __METHOD__, - 'State data (customer and contact):' . PHP_EOL, - $this->getNewCustomer(), - $this->getNewContact() + array( + 'State data (customer and contact):' . PHP_EOL, + $this->getNewCustomer(), + $this->getNewContact() + ) ); throw new \InvalidArgumentException( 'Too much data in state - cannot determine which customer should be used.'