1
0
mirror of synced 2025-01-31 07:11:42 +03:00

Fix error with empty 'paidAt'

This commit is contained in:
Dima Uryvskiy 2022-06-28 18:27:39 +03:00 committed by GitHub
parent 88ca4e9c11
commit 20a2992551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 33 deletions

View File

@ -397,8 +397,8 @@ if (!class_exists('WC_Retailcrm_Orders')) :
$orderData['discountManualPercent'] = 0;
if (!$update && $order->get_total() > 0) {
$this->order_payment->is_new = true;
$orderData['payments'][] = $this->order_payment->build($order)->get_data();
$this->order_payment->isNew = true;
$orderData['payments'][] = $this->order_payment->build($order)->get_data();
}
if (!empty($this->customFields)) {
@ -432,8 +432,8 @@ if (!class_exists('WC_Retailcrm_Orders')) :
*/
protected function sendPayment($order, $update = false, $externalId = false)
{
$this->order_payment->is_new = !$update;
$payment = $this->order_payment->build($order, $externalId)->get_data();
$this->order_payment->isNew = !$update;
$payment = $this->order_payment->build($order, $externalId)->get_data();
$integrationPayments = get_option('retailcrm_integration_payments');

View File

@ -12,23 +12,20 @@
*/
class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
{
/** @var string */
protected $filter_name = 'order_payment';
/** @var array */
protected $data = array(
protected $data = [
'type' => '',
'order' => [],
'externalId' => '',
'type' => '',
'order' => array()
);
];
/** @var bool */
public $is_new = true;
public $isNew = true;
/**
* @var array
*/
protected $settings = array();
protected $settings = [];
/**
* WC_Retailcrm_Order_Item constructor.
@ -49,39 +46,41 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
public function build($order, $externalId = false)
{
$this->reset_data();
$data = [];
$paymentData = [];
if (!$this->is_new) {
$data['externalId'] = $externalId;
if (!$this->isNew) {
$paymentData['externalId'] = $externalId;
} else {
$data['externalId'] = uniqid($order->get_id() . "-");
$paymentData['externalId'] = uniqid($order->get_id() . '-');
}
$data['order'] = [
$paymentData['order'] = [
'externalId' => $order->get_id()
];
if ($order->is_paid()) {
$data['status'] = 'paid';
$paymentData['status'] = 'paid';
if (isset($this->settings[$order->get_payment_method()])) {
$data['type'] = $this->settings[$order->get_payment_method()];
$paymentData['type'] = $this->settings[$order->get_payment_method()];
}
}
if ($order->get_date_paid()) {
$data['paidAt'] = $order->get_date_paid()->date('Y-m-d H:i:s');
$paidAt = $order->get_date_paid();
if (!empty($paidAt)) {
$paymentData['paidAt'] = $paidAt->date('Y-m-d H:i:s');
}
if ($this->is_new) {
if ($this->isNew) {
if (isset($this->settings[$order->get_payment_method()])) {
$data['type'] = $this->settings[$order->get_payment_method()];
$paymentData['type'] = $this->settings[$order->get_payment_method()];
} else {
$data = [];
$paymentData = [];
}
}
$this->set_data_fields($data);
$this->set_data_fields($paymentData);
return $this;
}
@ -96,20 +95,21 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
$data = parent::get_data();
if (empty($data['type'])) {
return array();
return [];
}
return $data;
// Need to clear the array from empty values
return array_filter($data);
}
public function reset_data()
{
$this->data = array(
$this->data = [
'externalId' => '',
'type' => '',
'status' => '',
'paidAt' => '',
'order' => array()
);
'order' => []
];
}
}
}

View File

@ -68,7 +68,7 @@ class WC_Retailcrm_Order_Payment_Test extends WC_Retailcrm_Test_Case_Helper
{
$settings = $this->getOptions();
$order_payment = new WC_Retailcrm_Order_Payment($settings);
$order_payment->is_new = false;
$order_payment->isNew = false;
$data = $order_payment->build($this->order, $externalId)->get_data();