diff --git a/admin/class-hesabix-admin.php b/admin/class-hesabix-admin.php
index 4f29ae3..8a02ddd 100644
--- a/admin/class-hesabix-admin.php
+++ b/admin/class-hesabix-admin.php
@@ -1824,7 +1824,7 @@ class Hesabix_Admin
wp_send_json($response);
}
- public function adminSaveApiSettingsCallback()
+ public function admin_save_api_settingsCallback()
{
check_ajax_referer('hesabix_ajax_nonce', 'nonce');
@@ -1849,7 +1849,7 @@ class Hesabix_Admin
}
}
- public function adminTestApiConnectionCallback()
+ public function admin_test_api_connectionCallback()
{
check_ajax_referer('hesabix_ajax_nonce', 'nonce');
diff --git a/admin/partials/hesabix-admin-functions.php b/admin/partials/hesabix-admin-functions.php
index 5b67e8d..4874d16 100644
--- a/admin/partials/hesabix-admin-functions.php
+++ b/admin/partials/hesabix-admin-functions.php
@@ -54,7 +54,7 @@ class Hesabix_Admin_Functions
return __('date is not in fiscal year', 'hesabix');
}
} else {
- HesabixLogService::log(array("Cannot get FiscalDate. Error Code: $fiscalYear->ErrroCode. Error Message: $fiscalYear->ErrorMessage"));
+ HesabixLogService::log(array("Cannot get FiscalDate. Error Code: " . (string) $fiscalYear->ErrorCode . ". Error Message: " . (string) $fiscalYear->ErrorMessage));
return __('Cannot connect to Hesabix for get FiscalDate.', 'hesabix');
}
} else {
@@ -122,11 +122,22 @@ class Hesabix_Admin_Functions
$response = $hesabix->itemBatchSave($items);
if ($response->Success) {
- foreach ($response->createdItems as $item)
+ $itemsToProcess = array();
+ if (isset($response->createdItems) && !empty($response->createdItems)) {
+ $itemsToProcess = $response->createdItems;
+ } elseif (isset($response->Result) && !empty($response->Result)) {
+ $itemsToProcess = $response->Result;
+ } else {
+ HesabixLogService::log(array("No items found in response. Response structure: " . print_r($response, true)));
+ return false;
+ }
+
+ foreach ($itemsToProcess as $item) {
$wpFaService->saveProduct($item);
+ }
return true;
} else {
- HesabixLogService::log(array("Cannot add/update Hesabix items. Error Code: " . (string) $response->ErrorCode . ". Error Message: $response->ErrorMessage."));
+ HesabixLogService::log(array("Cannot add/update Hesabix items. Error Code: " . (string) $response->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage . ". response: " . print_r($response, true)));
return false;
}
}
@@ -172,7 +183,7 @@ class Hesabix_Admin_Functions
$wpFaService->saveCustomer($response->person);
return $response->person->code;
} else {
- HesabixLogService::log(array("Cannot add/update customer. Error Code: " . (string) $response->ErrroCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: $id_customer"));
+ HesabixLogService::log(array("Cannot add/update customer. Error Code: " . (string) $response->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: $id_customer"));
return false;
}
}
@@ -197,7 +208,7 @@ class Hesabix_Admin_Functions
$wpFaService->saveCustomer($response->Result);
return (int) $response->Result->code;
} else {
- HesabixLogService::log(array("Cannot add/update contact. Error Code: " . (string) $response->ErrroCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: Guest Customer"));
+ HesabixLogService::log(array("Cannot add/update contact. Error Code: " . (string) $response->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: Guest Customer"));
return false;
}
}
@@ -232,7 +243,7 @@ class Hesabix_Admin_Functions
return null;
}
} else {
- HesabixLogService::log(array("Cannot get Contact list. Error Message: (string)$response->ErrorMessage. Error Code: (string)$response->ErrorCode."));
+ HesabixLogService::log(array("Cannot get Contact list. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . "."));
}
return null;
@@ -907,7 +918,7 @@ class Hesabix_Admin_Functions
$total = $response->Result->FilteredCount;
$totalBatch = ceil($total / $rpp);
} else {
- HesabixLogService::log(array("Error while trying to get products for import. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
+ HesabixLogService::log(array("Error while trying to get products for import. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . "."));
$result["error"] = true;
return $result;
}
@@ -1094,9 +1105,9 @@ class Hesabix_Admin_Functions
if ($response->Success) {
} else {
- HesabixLogService::log(array("hesabix - Cannot set Opening quantity. Error Code: ' . $response->ErrorCode . '. Error Message: ' . $response->ErrorMessage"));
+ HesabixLogService::log(array("hesabix - Cannot set Opening quantity. Error Code: " . (string) $response->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage));
$result['error'] = true;
- if ($response->ErrorCode = 199 && $response->ErrorMessage == 'No-Shareholders-Exist') {
+ if ($response->ErrorCode == 199 && $response->ErrorMessage == 'No-Shareholders-Exist') {
$result['errorType'] = 'shareholderError';
return $result;
}
@@ -1159,7 +1170,7 @@ class Hesabix_Admin_Functions
HesabixLogService::log(array("Contact successfully added. Contact Code: " . $item->code . ". Customer ID: " . (int) $json->id_customer));
}
} else {
- HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
+ HesabixLogService::log(array("Cannot add bulk contacts. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . "."));
}
}
@@ -1373,7 +1384,7 @@ class Hesabix_Admin_Functions
$total = $response->data->FilteredCount;
$totalBatch = ceil($total / $rpp);
} else {
- HesabixLogService::log(array("Error while trying to get products for sync. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
+ HesabixLogService::log(array("Error while trying to get products for sync. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . "."));
$result["error"] = true;
return $result;
}
@@ -1402,7 +1413,7 @@ class Hesabix_Admin_Functions
self::setItemChanges($product);
}
} else {
- HesabixLogService::log(array("Error while trying to get products for sync. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
+ HesabixLogService::log(array("Error while trying to get products for sync. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . "."));
$result["error"] = true;
return $result;
}
@@ -1550,7 +1561,7 @@ class Hesabix_Admin_Functions
$api = new Hesabix_Api();
$wpFaService = new HesabixWpFaService();
$filters = array(array("Property" => "khadamat", "Operator" => "=", "Value" => 0));
- $items = $api->itemGetItems(array('Filters' => $filters));
+ $items = $api->itemGetItems(array('Filters' => $filters, 'Take' => -1));
foreach ($items->data->List as $item) {
@@ -2126,7 +2137,7 @@ class Hesabix_Admin_Functions
return false;
}
} else {
- HesabixLogService::writeLogStr('Error Occurred in Checking Mobile and NationalCode. ErrorCode: ' . $response->ErrorCode . " - ErrorMessage: " . $response->ErrorMessage);
+ HesabixLogService::writeLogStr('Error Occurred in Checking Mobile and NationalCode. ErrorCode: ' . (string) $response->ErrorCode . " - ErrorMessage: " . (string) $response->ErrorMessage);
return false;
}
}
diff --git a/admin/partials/hesabix-admin-setting.php b/admin/partials/hesabix-admin-setting.php
index c35fb4d..aaf32c2 100644
--- a/admin/partials/hesabix-admin-setting.php
+++ b/admin/partials/hesabix-admin-setting.php
@@ -1901,7 +1901,7 @@ class Hesabix_Setting
$filters = array(array("Property" => "khadamat", "Operator" => "=", "Value" => 0));
- $response = $hesabix->itemGetItems(array('Filters' => $filters));
+ $response = $hesabix->itemGetItems(array('Filters' => $filters, 'Take' => -1));
if ($response->Success) {
return $response->data->FilteredCount;
} else {
@@ -2033,10 +2033,10 @@ class Hesabix_Setting
} else {
if ($show_errors) {
echo '
';
- echo '
' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . $default_currency->ErrorMessage . '
';
+ echo '
' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . (string) $default_currency->ErrorMessage . '
';
echo '
';
}
- HesabixLogService::log(array("Cannot check the Hesabix default currency. Error Message: $default_currency->ErrorMessage. Error Code: $default_currency->ErrorCode"));
+ HesabixLogService::log(array("Cannot check the Hesabix default currency. Error Message: " . (string) $default_currency->ErrorMessage . ". Error Code: " . (string) $default_currency->ErrorCode));
}
@@ -2051,20 +2051,20 @@ class Hesabix_Setting
if ($response->ErrorCode === 108) {
if ($show_errors) {
echo '';
- echo '
' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . $response->ErrorMessage . '
';
+ echo '
' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . (string) $response->ErrorMessage . '
';
echo '
';
}
update_option('hesabix_business_expired', 1);
} else {
if ($show_errors) {
echo '';
- echo '
' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . $response->ErrorMessage . '
';
+ echo '
' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . (string) $response->ErrorMessage . '
';
echo '
';
}
update_option('hesabix_business_expired', 0);
}
- HesabixLogService::log(array("Cannot set Hesabix webHook. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode"));
+ HesabixLogService::log(array("Cannot set Hesabix webHook. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode));
}
} else {
update_option('hesabix_live_mode', 0);
@@ -2107,7 +2107,7 @@ class Hesabix_Setting
echo '' . __('Cannot get Banks detail.', 'hesabix') . '
';
echo '';
- HesabixLogService::log(array("Cannot get banking information. Error Code: $banks->ErrorCode. Error Message: $banks->ErrorMessage."));
+ HesabixLogService::log(array("Cannot get banking information. Error Code: " . (string) $banks->ErrorCode . ". Error Message: " . (string) $banks->ErrorMessage . "."));
return array('0' => __('Cannot get Banks detail.', 'hesabix'));
}
@@ -2147,7 +2147,7 @@ class Hesabix_Setting
echo '';
echo '
' . __('Cannot get Projects detail.', 'hesabix') . '
';
echo '
';
- HesabixLogService::log(array("Cannot get projects information. Error Code:$projects->ErrorCode. Error Message: $projects->ErrorMessage."));
+ HesabixLogService::log(array("Cannot get projects information. Error Code: " . (string) $projects->ErrorCode . ". Error Message: " . (string) $projects->ErrorMessage . "."));
return array('0' => __('Cannot get projects detail.', 'hesabix'));
}
@@ -2171,7 +2171,7 @@ class Hesabix_Setting
echo '';
echo '
' . __('Cannot get Salesmen detail.', 'hesabix') . '
';
echo '
';
- HesabixLogService::log(array("Cannot get salesmen information. Error Code: $salesmen->ErrorCode Error Message: .$salesmen->ErrorMessage."));
+ HesabixLogService::log(array("Cannot get salesmen information. Error Code: " . (string) $salesmen->ErrorCode . ". Error Message: " . (string) $salesmen->ErrorMessage . "."));
return array('0' => __('Cannot get salesmen detail.', 'hesabix'));
}
@@ -2422,7 +2422,7 @@ class Hesabix_Setting
echo '';
echo '
' . __('Cannot get warehouses.', 'hesabix') . '
';
echo '
';
- HesabixLogService::log(array("Cannot get warehouses. Error Code: $warehouses->ErrorCode. Error Message: .$warehouses->ErrorMessage."));
+ HesabixLogService::log(array("Cannot get warehouses. Error Code: " . (string) $warehouses->ErrorCode . ". Error Message: " . (string) $warehouses->ErrorMessage . "."));
return array('0' => __('Cannot get warehouses.', 'hesabix'));
}
diff --git a/admin/services/hesabixWpFaService.php b/admin/services/hesabixWpFaService.php
index 3b3f6b8..14ffc56 100644
--- a/admin/services/hesabixWpFaService.php
+++ b/admin/services/hesabixWpFaService.php
@@ -91,6 +91,21 @@ class HesabixWpFaService
)
);
+ if (isset($row))
+ return $this->mapWpFa($row);
+
+ // If no exact match, try to find any product with this hesabix code
+ $row = $wpdb->get_row(
+ $wpdb->prepare(
+ "SELECT *
+ FROM {$wpdb->prefix}hesabix
+ WHERE `id_hesabix` = %d
+ AND `obj_type` = %s
+ LIMIT 1",
+ $codehx,
+ $objType
+ )
+ );
if (isset($row))
return $this->mapWpFa($row);
@@ -344,18 +359,38 @@ class HesabixWpFaService
public function saveProduct($item): bool
{
$hesabix_code = 0;
+ $hesabix_uid = 0;
$id_product = 0;
$id_attribute = 0;
+
if (isset($item->code))
$hesabix_code = (int) $item->code;
if (isset($item->id))
$hesabix_uid = (int) $item->id;
+ else
+ $hesabix_uid = 0;
+
+ // Check both possible tag field names
+ $tagData = null;
if (isset($item->tags)) {
- $json = $item->tags;
- if (isset($json->id_product))
- $id_product = (int) $json->id_product;
- if (isset($json->id_attribute))
- $id_attribute = (int) $json->id_attribute;
+ if (is_string($item->tags)) {
+ $tagData = json_decode($item->tags);
+ } else {
+ $tagData = $item->tags;
+ }
+ } elseif (isset($item->Tag)) {
+ if (is_string($item->Tag)) {
+ $tagData = json_decode($item->Tag);
+ } else {
+ $tagData = $item->Tag;
+ }
+ }
+
+ if ($tagData) {
+ if (isset($tagData->id_product))
+ $id_product = (int) $tagData->id_product;
+ if (isset($tagData->id_attribute))
+ $id_attribute = (int) $tagData->id_attribute;
}
$wpFaService = new HesabixWpFaService();
@@ -363,24 +398,49 @@ class HesabixWpFaService
if (!$wpFa) {
$wpFa = WpFa::newWpFa(0, 'product', $hesabix_code, $id_product, $id_attribute, $hesabix_uid);
- $wpFaService->save($wpFa);
- HesabixLogService::log(array("Item successfully added. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ $result = $wpFaService->save($wpFa);
+ if ($result) {
+ HesabixLogService::log(array("Item successfully added. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ } else {
+ HesabixLogService::log(array("Failed to add item to database. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ return false;
+ }
} else {
$wpFa->idHesabix = $hesabix_code;
$wpFa->uidHesabix = $hesabix_uid;
- $wpFaService->update($wpFa);
- HesabixLogService::log(array("Item successfully updated. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ $result = $wpFaService->update($wpFa);
+ if ($result) {
+ HesabixLogService::log(array("Item successfully updated. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ } else {
+ HesabixLogService::log(array("Failed to update item in database. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
+ return false;
+ }
}
return true;
}
public function saveCustomer($customer): bool
{
- $json = json_decode($customer->tags);
- if ((int) $json->id_customer == 0)
+ // Handle both string and object formats for tags
+ $tagData = null;
+ if (isset($customer->tags)) {
+ if (is_string($customer->tags)) {
+ $tagData = json_decode($customer->tags);
+ } else {
+ $tagData = $customer->tags;
+ }
+ } elseif (isset($customer->Tag)) {
+ if (is_string($customer->Tag)) {
+ $tagData = json_decode($customer->Tag);
+ } else {
+ $tagData = $customer->Tag;
+ }
+ }
+
+ if (!$tagData || (int) $tagData->id_customer == 0)
return true;
- $id = $this->getWpFaId('customer', (int) $json->id_customer);
+ $id = $this->getWpFaId('customer', (int) $tagData->id_customer);
global $wpdb;
if (!$id) {
@@ -390,7 +450,7 @@ class HesabixWpFaService
'id_hesabix' => (int) $customer->code,
'uid_hesabix' => (int) $customer->id,
'obj_type' => 'customer',
- 'id_ps' => (int) $json->id_customer
+ 'id_ps' => (int) $tagData->id_customer
),
array(
'%d',
@@ -400,7 +460,7 @@ class HesabixWpFaService
)
);
- HesabixLogService::writeLogStr("Customer successfully added. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
+ HesabixLogService::writeLogStr("Customer successfully added. Customer code: " . (string) $customer->code . ". Customer ID: " . $tagData->id_customer);
} else {
$wpdb->update(
$wpdb->prefix . 'hesabix',
@@ -408,7 +468,7 @@ class HesabixWpFaService
'id_hesabix' => (int) $customer->code,
'uid_hesabix' => (int) $customer->id,
'obj_type' => 'customer',
- 'id_ps' => (int) $json->id_customer,
+ 'id_ps' => (int) $tagData->id_customer,
),
array('id' => $id),
array(
@@ -420,43 +480,91 @@ class HesabixWpFaService
array('%d')
);
- HesabixLogService::writeLogStr("Customer successfully updated. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
+ HesabixLogService::writeLogStr("Customer successfully updated. Customer code: " . (string) $customer->code . ". Customer ID: " . $tagData->id_customer);
}
return true;
}
public function saveInvoice($invoice, $orderType)
{
- $json = json_decode($invoice->Tag);
- $id = $this->getPsFaId('order', (int) $json->id_order);
+ // Handle both string and object formats for Tag
+ $tagData = null;
+ if (isset($invoice->Tag)) {
+ if (is_string($invoice->Tag)) {
+ $tagData = json_decode($invoice->Tag);
+ } else {
+ $tagData = $invoice->Tag;
+ }
+ } elseif (isset($invoice->tags)) {
+ if (is_string($invoice->tags)) {
+ $tagData = json_decode($invoice->tags);
+ } else {
+ $tagData = $invoice->tags;
+ }
+ }
+
+ if (!$tagData) {
+ HesabixLogService::log(array("No tag data found for invoice"));
+ return false;
+ }
+
+ $id = $this->getWpFaId('order', (int) $tagData->id_order);
$invoiceNumber = (int) $invoice->Number;
$objType = $orderType == 0 ? 'order' : 'returnOrder';
if (!$id) {
- Db::getInstance()->insert('ps_hesabix', array(
- 'id_hesabix' => $invoiceNumber,
- 'obj_type' => $objType,
- 'id_ps' => (int) $json->id_order,
- ));
+ global $wpdb;
+ $result = $wpdb->insert(
+ $wpdb->prefix . 'hesabix',
+ array(
+ 'id_hesabix' => $invoiceNumber,
+ 'obj_type' => $objType,
+ 'id_ps' => (int) $tagData->id_order,
+ ),
+ array(
+ '%d',
+ '%s',
+ '%d'
+ )
+ );
-
- if ($objType == 'order')
- LogService::writeLogStr("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
- else
- LogService::writeLogStr("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
+ if ($result) {
+ if ($objType == 'order')
+ HesabixLogService::log(array("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
+ else
+ HesabixLogService::log(array("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
+ } else {
+ HesabixLogService::log(array("Failed to add invoice to database: " . $wpdb->last_error));
+ return false;
+ }
} else {
- Db::getInstance()->update('ps_hesabix', array(
- 'id_hesabix' => $invoiceNumber,
- 'obj_type' => $objType,
- 'id_ps' => (int) $json->id_order,
- ), array('id' => $id), 0, true, true);
+ global $wpdb;
+ $result = $wpdb->update(
+ $wpdb->prefix . 'hesabix',
+ array(
+ 'id_hesabix' => $invoiceNumber,
+ 'obj_type' => $objType,
+ 'id_ps' => (int) $tagData->id_order,
+ ),
+ array('id' => $id),
+ array(
+ '%d',
+ '%s',
+ '%d'
+ ),
+ array('%d')
+ );
-
- if ($objType == 'order')
- LogService::writeLogStr("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
- else
- LogService::writeLogStr("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
+ if ($result) {
+ if ($objType == 'order')
+ HesabixLogService::log(array("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
+ else
+ HesabixLogService::log(array("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
+ } else {
+ HesabixLogService::log(array("Failed to update invoice in database: " . $wpdb->last_error));
+ return false;
+ }
}
return true;
@@ -465,7 +573,8 @@ class HesabixWpFaService
public function save(WpFa $wpFa)
{
global $wpdb;
- $wpdb->insert(
+
+ $result = $wpdb->insert(
$wpdb->prefix . 'hesabix',
array(
'id_hesabix' => $wpFa->idHesabix,
@@ -475,14 +584,20 @@ class HesabixWpFaService
'uid_hesabix' => (int) $wpFa->uidHesabix,
),
array(
- '%s',
+ '%d',
'%s',
'%d',
'%d',
- '%s'
+ '%d'
)
);
-
+
+ if ($result === false) {
+ HesabixLogService::log(array("Error inserting into database: " . $wpdb->last_error));
+ return false;
+ }
+
+ return true;
}
@@ -490,13 +605,13 @@ class HesabixWpFaService
{
global $wpdb;
- $idHesabix = isset($wpFa->idHesabix) ? sanitize_text_field($wpFa->idHesabix) : '';
- $uidHesabix = isset($wpFa->uidHesabix) ? sanitize_text_field($wpFa->uidHesabix) : '';
- $objType = isset($wpFa->objType) ? sanitize_text_field($wpFa->objType) : '';
+ $idHesabix = isset($wpFa->idHesabix) ? (int) $wpFa->idHesabix : 0;
+ $uidHesabix = isset($wpFa->uidHesabix) ? (int) $wpFa->uidHesabix : 0;
+ $objType = isset($wpFa->objType) ? $wpFa->objType : '';
$idWp = isset($wpFa->idWp) ? (int) $wpFa->idWp : 0;
$idWpAttribute = isset($wpFa->idWpAttribute) ? (int) $wpFa->idWpAttribute : 0;
- $wpdb->update(
+ $result = $wpdb->update(
$wpdb->prefix . 'hesabix',
array(
'id_hesabix' => $idHesabix,
@@ -507,14 +622,21 @@ class HesabixWpFaService
),
array('id' => $wpFa->id),
array(
- '%s',
+ '%d',
'%s',
'%d',
'%d',
- '%s'
+ '%d'
),
array('%d')
);
+
+ if ($result === false) {
+ HesabixLogService::log(array("Error updating database: " . $wpdb->last_error));
+ return false;
+ }
+
+ return true;
}
diff --git a/assets/js/hesabix-admin.js b/assets/js/hesabix-admin.js
index 54affca..e78a155 100644
--- a/assets/js/hesabix-admin.js
+++ b/assets/js/hesabix-admin.js
@@ -1096,7 +1096,7 @@ jQuery(function($) {
saveBtn.addClass('loading').prop('disabled', true);
const formData = {
- action: 'adminSaveApiSettings',
+ action: 'admin_save_api_settings',
nonce: hesabix_ajax.nonce,
api_key: $('#hesabix_account_api').val(),
api_address: $('#hesabix_api_address').val(),
@@ -1130,7 +1130,7 @@ jQuery(function($) {
url: ajaxurl,
type: 'POST',
data: {
- action: 'adminTestApiConnection',
+ action: 'admin_test_api_connection',
nonce: hesabix_ajax.nonce
},
success: (response) => {
diff --git a/assets/js/hesabix.js b/assets/js/hesabix.js
index 54affca..e78a155 100644
--- a/assets/js/hesabix.js
+++ b/assets/js/hesabix.js
@@ -1096,7 +1096,7 @@ jQuery(function($) {
saveBtn.addClass('loading').prop('disabled', true);
const formData = {
- action: 'adminSaveApiSettings',
+ action: 'admin_save_api_settings',
nonce: hesabix_ajax.nonce,
api_key: $('#hesabix_account_api').val(),
api_address: $('#hesabix_api_address').val(),
@@ -1130,7 +1130,7 @@ jQuery(function($) {
url: ajaxurl,
type: 'POST',
data: {
- action: 'adminTestApiConnection',
+ action: 'admin_test_api_connection',
nonce: hesabix_ajax.nonce
},
success: (response) => {
diff --git a/hesabix.php b/hesabix.php
index 2721713..c4273eb 100644
--- a/hesabix.php
+++ b/hesabix.php
@@ -9,7 +9,7 @@
* Plugin Name: Hesabix: WooCommerce
* Plugin URI: https://hesabix.ir/
* Description: Connect Hesabix Online Accounting to WooCommerce.
- * Version: 1.0.3
+ * Version: 1.0.4
* Author: Mohammad Rezai
* Author URI: https://pirouz.xyz
* License: GPL-3.0+
@@ -24,7 +24,7 @@ if (!defined('WPINC')) {
}
define('HESABIX_PLUGIN_URL', plugin_dir_url(__FILE__));
-define('HESABIX_VERSION', '1.0.3');
+define('HESABIX_VERSION', '1.0.4');
function activate_hesabix()
{
diff --git a/includes/class-hesabix-api.php b/includes/class-hesabix-api.php
index 7bfc33f..42cbffc 100644
--- a/includes/class-hesabix-api.php
+++ b/includes/class-hesabix-api.php
@@ -13,7 +13,7 @@ include_once(dirname(__DIR__) . '/admin/services/hesabixLogService.php');
class Hesabix_Api
{
- public function apiRequest($method, $data = array())
+ public function apiRequest($method, $data = array(), $timeout = 15)
{
if ($method == null)
return false;
@@ -45,6 +45,8 @@ class Hesabix_Api
HesabixLogService::log(array("Debug Mode - Data: " . print_r($data, true)));
}
+
+
$options = array(
'body' => wp_json_encode($body),
'headers' => array(
@@ -53,16 +55,13 @@ class Hesabix_Api
'activeBid' => get_option('hesabix_account_bid'),
'activeYear' => get_option('hesabix_account_year'),
),
- 'timeout' => 15,
+ 'timeout' => $timeout,
'redirection' => 5,
'blocking' => true,
'data_format' => 'body',
);
$wp_remote_post = wp_remote_post($endpoint, $options);
- if ($method == 'api/commodity/search/extra') {
-
- }
$result = json_decode(wp_remote_retrieve_body($wp_remote_post));
@@ -85,7 +84,7 @@ class Hesabix_Api
case '103':
return 'MissingData';
case '104':
- return 'MissingParameter' . '. ErrorMessage: ' . $result->ErrorMessage;
+ return 'MissingParameter' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
case '105':
return 'ApiDisabled';
case '106':
@@ -99,13 +98,13 @@ class Hesabix_Api
case '111':
return 'IdMustNotBeZero';
case '112':
- return 'ObjectNotFound' . '. ErrorMessage: ' . $result->ErrorMessage;
+ return 'ObjectNotFound' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
case '113':
return 'MissingApiKey';
case '114':
- return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . $result->ErrorMessage;
+ return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
case '190':
- return 'ApplicationError' . '. ErrorMessage: ' . $result->ErrorMessage;
+ return 'ApplicationError' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
}
} else {
return $result;
@@ -158,7 +157,7 @@ class Hesabix_Api
'items' => $contacts,
);
- return $this->apiRequest($method, $data);
+ return $this->apiRequest($method, $data, 120);
}
public function contactDelete($code)
@@ -243,7 +242,7 @@ class Hesabix_Api
'items' => $items,
);
- return $this->apiRequest($method, $data);
+ return $this->apiRequest($method, $data, 120);
}
public function itemDelete($code)
diff --git a/includes/class-hesabix-webhook.php b/includes/class-hesabix-webhook.php
index bb35d2e..91cd925 100644
--- a/includes/class-hesabix-webhook.php
+++ b/includes/class-hesabix-webhook.php
@@ -337,19 +337,11 @@ class Hesabix_Webhook
public function getObjectsByCodeList($codeList)
{
$hesabixApi = new Hesabix_Api();
-
- // $warehouse = get_option('hesabix_item_update_quantity_based_on', "-1");
- // if ($warehouse == "-1")
- // $result = $hesabixApi->itemGetItemsByCodes($codeList);
- // else {
- // $result = $hesabixApi->itemGetQuantity($warehouse, $codeList);
- // }
$result = $hesabixApi->itemGetItemsByCodes($codeList);
if (is_object($result) && $result->Success) {
- // return $warehouse == "-1" ? $result->Result->List : $result->Result;
return $result->Result->List;
}
diff --git a/includes/class-hesabix.php b/includes/class-hesabix.php
index 4c2b458..153e021 100644
--- a/includes/class-hesabix.php
+++ b/includes/class-hesabix.php
@@ -133,8 +133,8 @@ class Hesabix
$this->loader->add_filter('wp_ajax_adminUpdateProductAndVariations', $plugin_admin, 'adminUpdateProductAndVariationsCallback');
$this->loader->add_filter('wp_ajax_admin_get_home_stats', $plugin_admin, 'admin_get_home_stats_callback');
$this->loader->add_filter('wp_ajax_admin_check_for_updates', $plugin_admin, 'admin_check_for_updates_callback');
- $this->loader->add_filter('wp_ajax_adminSaveApiSettings', $plugin_admin, 'adminSaveApiSettingsCallback');
- $this->loader->add_filter('wp_ajax_adminTestApiConnection', $plugin_admin, 'adminTestApiConnectionCallback');
+ $this->loader->add_filter('wp_ajax_admin_save_api_settings', $plugin_admin, 'admin_save_api_settingsCallback');
+ $this->loader->add_filter('wp_ajax_admin_test_api_connection', $plugin_admin, 'admin_test_api_connectionCallback');
}