Update version to 1.0.4 and fix bugs
This commit is contained in:
parent
99fdeed88a
commit
69625d47d8
|
@ -1824,7 +1824,7 @@ class Hesabix_Admin
|
||||||
wp_send_json($response);
|
wp_send_json($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function adminSaveApiSettingsCallback()
|
public function admin_save_api_settingsCallback()
|
||||||
{
|
{
|
||||||
check_ajax_referer('hesabix_ajax_nonce', 'nonce');
|
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');
|
check_ajax_referer('hesabix_ajax_nonce', 'nonce');
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Hesabix_Admin_Functions
|
||||||
return __('date is not in fiscal year', 'hesabix');
|
return __('date is not in fiscal year', 'hesabix');
|
||||||
}
|
}
|
||||||
} else {
|
} 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');
|
return __('Cannot connect to Hesabix for get FiscalDate.', 'hesabix');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -122,11 +122,22 @@ class Hesabix_Admin_Functions
|
||||||
|
|
||||||
$response = $hesabix->itemBatchSave($items);
|
$response = $hesabix->itemBatchSave($items);
|
||||||
if ($response->Success) {
|
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);
|
$wpFaService->saveProduct($item);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +183,7 @@ class Hesabix_Admin_Functions
|
||||||
$wpFaService->saveCustomer($response->person);
|
$wpFaService->saveCustomer($response->person);
|
||||||
return $response->person->code;
|
return $response->person->code;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +208,7 @@ class Hesabix_Admin_Functions
|
||||||
$wpFaService->saveCustomer($response->Result);
|
$wpFaService->saveCustomer($response->Result);
|
||||||
return (int) $response->Result->code;
|
return (int) $response->Result->code;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +243,7 @@ class Hesabix_Admin_Functions
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
return null;
|
||||||
|
@ -907,7 +918,7 @@ class Hesabix_Admin_Functions
|
||||||
$total = $response->Result->FilteredCount;
|
$total = $response->Result->FilteredCount;
|
||||||
$totalBatch = ceil($total / $rpp);
|
$totalBatch = ceil($total / $rpp);
|
||||||
} else {
|
} 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;
|
$result["error"] = true;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1094,9 +1105,9 @@ class Hesabix_Admin_Functions
|
||||||
if ($response->Success) {
|
if ($response->Success) {
|
||||||
|
|
||||||
} else {
|
} 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;
|
$result['error'] = true;
|
||||||
if ($response->ErrorCode = 199 && $response->ErrorMessage == 'No-Shareholders-Exist') {
|
if ($response->ErrorCode == 199 && $response->ErrorMessage == 'No-Shareholders-Exist') {
|
||||||
$result['errorType'] = 'shareholderError';
|
$result['errorType'] = 'shareholderError';
|
||||||
return $result;
|
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));
|
HesabixLogService::log(array("Contact successfully added. Contact Code: " . $item->code . ". Customer ID: " . (int) $json->id_customer));
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
$total = $response->data->FilteredCount;
|
||||||
$totalBatch = ceil($total / $rpp);
|
$totalBatch = ceil($total / $rpp);
|
||||||
} else {
|
} 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;
|
$result["error"] = true;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1402,7 +1413,7 @@ class Hesabix_Admin_Functions
|
||||||
self::setItemChanges($product);
|
self::setItemChanges($product);
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
$result["error"] = true;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1561,7 @@ class Hesabix_Admin_Functions
|
||||||
$api = new Hesabix_Api();
|
$api = new Hesabix_Api();
|
||||||
$wpFaService = new HesabixWpFaService();
|
$wpFaService = new HesabixWpFaService();
|
||||||
$filters = array(array("Property" => "khadamat", "Operator" => "=", "Value" => 0));
|
$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) {
|
foreach ($items->data->List as $item) {
|
||||||
|
|
||||||
|
@ -2126,7 +2137,7 @@ class Hesabix_Admin_Functions
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1901,7 +1901,7 @@ class Hesabix_Setting
|
||||||
|
|
||||||
$filters = array(array("Property" => "khadamat", "Operator" => "=", "Value" => 0));
|
$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) {
|
if ($response->Success) {
|
||||||
return $response->data->FilteredCount;
|
return $response->data->FilteredCount;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2033,10 +2033,10 @@ class Hesabix_Setting
|
||||||
} else {
|
} else {
|
||||||
if ($show_errors) {
|
if ($show_errors) {
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . $default_currency->ErrorMessage . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . (string) $default_currency->ErrorMessage . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
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 ($response->ErrorCode === 108) {
|
||||||
if ($show_errors) {
|
if ($show_errors) {
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . $response->ErrorMessage . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . (string) $response->ErrorMessage . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
update_option('hesabix_business_expired', 1);
|
update_option('hesabix_business_expired', 1);
|
||||||
} else {
|
} else {
|
||||||
if ($show_errors) {
|
if ($show_errors) {
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . $response->ErrorMessage . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . (string) $response->ErrorMessage . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
update_option('hesabix_business_expired', 0);
|
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 {
|
} else {
|
||||||
update_option('hesabix_live_mode', 0);
|
update_option('hesabix_live_mode', 0);
|
||||||
|
@ -2107,7 +2107,7 @@ class Hesabix_Setting
|
||||||
echo '<p class="hesabix-p">' . __('Cannot get Banks detail.', 'hesabix') . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot get Banks detail.', 'hesabix') . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
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'));
|
return array('0' => __('Cannot get Banks detail.', 'hesabix'));
|
||||||
}
|
}
|
||||||
|
@ -2147,7 +2147,7 @@ class Hesabix_Setting
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot get Projects detail.', 'hesabix') . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot get Projects detail.', 'hesabix') . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
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'));
|
return array('0' => __('Cannot get projects detail.', 'hesabix'));
|
||||||
}
|
}
|
||||||
|
@ -2171,7 +2171,7 @@ class Hesabix_Setting
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot get Salesmen detail.', 'hesabix') . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot get Salesmen detail.', 'hesabix') . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
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'));
|
return array('0' => __('Cannot get salesmen detail.', 'hesabix'));
|
||||||
}
|
}
|
||||||
|
@ -2422,7 +2422,7 @@ class Hesabix_Setting
|
||||||
echo '<div class="error">';
|
echo '<div class="error">';
|
||||||
echo '<p class="hesabix-p">' . __('Cannot get warehouses.', 'hesabix') . '</p>';
|
echo '<p class="hesabix-p">' . __('Cannot get warehouses.', 'hesabix') . '</p>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
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'));
|
return array('0' => __('Cannot get warehouses.', 'hesabix'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
if (isset($row))
|
||||||
return $this->mapWpFa($row);
|
return $this->mapWpFa($row);
|
||||||
|
@ -344,18 +359,38 @@ class HesabixWpFaService
|
||||||
public function saveProduct($item): bool
|
public function saveProduct($item): bool
|
||||||
{
|
{
|
||||||
$hesabix_code = 0;
|
$hesabix_code = 0;
|
||||||
|
$hesabix_uid = 0;
|
||||||
$id_product = 0;
|
$id_product = 0;
|
||||||
$id_attribute = 0;
|
$id_attribute = 0;
|
||||||
|
|
||||||
if (isset($item->code))
|
if (isset($item->code))
|
||||||
$hesabix_code = (int) $item->code;
|
$hesabix_code = (int) $item->code;
|
||||||
if (isset($item->id))
|
if (isset($item->id))
|
||||||
$hesabix_uid = (int) $item->id;
|
$hesabix_uid = (int) $item->id;
|
||||||
|
else
|
||||||
|
$hesabix_uid = 0;
|
||||||
|
|
||||||
|
// Check both possible tag field names
|
||||||
|
$tagData = null;
|
||||||
if (isset($item->tags)) {
|
if (isset($item->tags)) {
|
||||||
$json = $item->tags;
|
if (is_string($item->tags)) {
|
||||||
if (isset($json->id_product))
|
$tagData = json_decode($item->tags);
|
||||||
$id_product = (int) $json->id_product;
|
} else {
|
||||||
if (isset($json->id_attribute))
|
$tagData = $item->tags;
|
||||||
$id_attribute = (int) $json->id_attribute;
|
}
|
||||||
|
} 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();
|
$wpFaService = new HesabixWpFaService();
|
||||||
|
@ -363,24 +398,49 @@ class HesabixWpFaService
|
||||||
|
|
||||||
if (!$wpFa) {
|
if (!$wpFa) {
|
||||||
$wpFa = WpFa::newWpFa(0, 'product', $hesabix_code, $id_product, $id_attribute, $hesabix_uid);
|
$wpFa = WpFa::newWpFa(0, 'product', $hesabix_code, $id_product, $id_attribute, $hesabix_uid);
|
||||||
$wpFaService->save($wpFa);
|
$result = $wpFaService->save($wpFa);
|
||||||
HesabixLogService::log(array("Item successfully added. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
|
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 {
|
} else {
|
||||||
$wpFa->idHesabix = $hesabix_code;
|
$wpFa->idHesabix = $hesabix_code;
|
||||||
$wpFa->uidHesabix = $hesabix_uid;
|
$wpFa->uidHesabix = $hesabix_uid;
|
||||||
$wpFaService->update($wpFa);
|
$result = $wpFaService->update($wpFa);
|
||||||
HesabixLogService::log(array("Item successfully updated. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCustomer($customer): bool
|
public function saveCustomer($customer): bool
|
||||||
{
|
{
|
||||||
$json = json_decode($customer->tags);
|
// Handle both string and object formats for tags
|
||||||
if ((int) $json->id_customer == 0)
|
$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;
|
return true;
|
||||||
|
|
||||||
$id = $this->getWpFaId('customer', (int) $json->id_customer);
|
$id = $this->getWpFaId('customer', (int) $tagData->id_customer);
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
@ -390,7 +450,7 @@ class HesabixWpFaService
|
||||||
'id_hesabix' => (int) $customer->code,
|
'id_hesabix' => (int) $customer->code,
|
||||||
'uid_hesabix' => (int) $customer->id,
|
'uid_hesabix' => (int) $customer->id,
|
||||||
'obj_type' => 'customer',
|
'obj_type' => 'customer',
|
||||||
'id_ps' => (int) $json->id_customer
|
'id_ps' => (int) $tagData->id_customer
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'%d',
|
'%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 {
|
} else {
|
||||||
$wpdb->update(
|
$wpdb->update(
|
||||||
$wpdb->prefix . 'hesabix',
|
$wpdb->prefix . 'hesabix',
|
||||||
|
@ -408,7 +468,7 @@ class HesabixWpFaService
|
||||||
'id_hesabix' => (int) $customer->code,
|
'id_hesabix' => (int) $customer->code,
|
||||||
'uid_hesabix' => (int) $customer->id,
|
'uid_hesabix' => (int) $customer->id,
|
||||||
'obj_type' => 'customer',
|
'obj_type' => 'customer',
|
||||||
'id_ps' => (int) $json->id_customer,
|
'id_ps' => (int) $tagData->id_customer,
|
||||||
),
|
),
|
||||||
array('id' => $id),
|
array('id' => $id),
|
||||||
array(
|
array(
|
||||||
|
@ -420,43 +480,91 @@ class HesabixWpFaService
|
||||||
array('%d')
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveInvoice($invoice, $orderType)
|
public function saveInvoice($invoice, $orderType)
|
||||||
{
|
{
|
||||||
$json = json_decode($invoice->Tag);
|
// Handle both string and object formats for Tag
|
||||||
$id = $this->getPsFaId('order', (int) $json->id_order);
|
$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;
|
$invoiceNumber = (int) $invoice->Number;
|
||||||
$objType = $orderType == 0 ? 'order' : 'returnOrder';
|
$objType = $orderType == 0 ? 'order' : 'returnOrder';
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
Db::getInstance()->insert('ps_hesabix', array(
|
global $wpdb;
|
||||||
'id_hesabix' => $invoiceNumber,
|
$result = $wpdb->insert(
|
||||||
'obj_type' => $objType,
|
$wpdb->prefix . 'hesabix',
|
||||||
'id_ps' => (int) $json->id_order,
|
array(
|
||||||
));
|
'id_hesabix' => $invoiceNumber,
|
||||||
|
'obj_type' => $objType,
|
||||||
|
'id_ps' => (int) $tagData->id_order,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'%d',
|
||||||
|
'%s',
|
||||||
|
'%d'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
if ($objType == 'order')
|
if ($objType == 'order')
|
||||||
LogService::writeLogStr("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
HesabixLogService::log(array("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
|
||||||
else
|
else
|
||||||
LogService::writeLogStr("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
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 {
|
} else {
|
||||||
Db::getInstance()->update('ps_hesabix', array(
|
global $wpdb;
|
||||||
'id_hesabix' => $invoiceNumber,
|
$result = $wpdb->update(
|
||||||
'obj_type' => $objType,
|
$wpdb->prefix . 'hesabix',
|
||||||
'id_ps' => (int) $json->id_order,
|
array(
|
||||||
), array('id' => $id), 0, true, true);
|
'id_hesabix' => $invoiceNumber,
|
||||||
|
'obj_type' => $objType,
|
||||||
|
'id_ps' => (int) $tagData->id_order,
|
||||||
|
),
|
||||||
|
array('id' => $id),
|
||||||
|
array(
|
||||||
|
'%d',
|
||||||
|
'%s',
|
||||||
|
'%d'
|
||||||
|
),
|
||||||
|
array('%d')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
if ($objType == 'order')
|
if ($objType == 'order')
|
||||||
LogService::writeLogStr("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
HesabixLogService::log(array("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order));
|
||||||
else
|
else
|
||||||
LogService::writeLogStr("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
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;
|
return true;
|
||||||
|
@ -465,7 +573,8 @@ class HesabixWpFaService
|
||||||
public function save(WpFa $wpFa)
|
public function save(WpFa $wpFa)
|
||||||
{
|
{
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$wpdb->insert(
|
|
||||||
|
$result = $wpdb->insert(
|
||||||
$wpdb->prefix . 'hesabix',
|
$wpdb->prefix . 'hesabix',
|
||||||
array(
|
array(
|
||||||
'id_hesabix' => $wpFa->idHesabix,
|
'id_hesabix' => $wpFa->idHesabix,
|
||||||
|
@ -475,14 +584,20 @@ class HesabixWpFaService
|
||||||
'uid_hesabix' => (int) $wpFa->uidHesabix,
|
'uid_hesabix' => (int) $wpFa->uidHesabix,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'%s',
|
'%d',
|
||||||
'%s',
|
'%s',
|
||||||
'%d',
|
'%d',
|
||||||
'%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;
|
global $wpdb;
|
||||||
|
|
||||||
$idHesabix = isset($wpFa->idHesabix) ? sanitize_text_field($wpFa->idHesabix) : '';
|
$idHesabix = isset($wpFa->idHesabix) ? (int) $wpFa->idHesabix : 0;
|
||||||
$uidHesabix = isset($wpFa->uidHesabix) ? sanitize_text_field($wpFa->uidHesabix) : '';
|
$uidHesabix = isset($wpFa->uidHesabix) ? (int) $wpFa->uidHesabix : 0;
|
||||||
$objType = isset($wpFa->objType) ? sanitize_text_field($wpFa->objType) : '';
|
$objType = isset($wpFa->objType) ? $wpFa->objType : '';
|
||||||
$idWp = isset($wpFa->idWp) ? (int) $wpFa->idWp : 0;
|
$idWp = isset($wpFa->idWp) ? (int) $wpFa->idWp : 0;
|
||||||
$idWpAttribute = isset($wpFa->idWpAttribute) ? (int) $wpFa->idWpAttribute : 0;
|
$idWpAttribute = isset($wpFa->idWpAttribute) ? (int) $wpFa->idWpAttribute : 0;
|
||||||
|
|
||||||
$wpdb->update(
|
$result = $wpdb->update(
|
||||||
$wpdb->prefix . 'hesabix',
|
$wpdb->prefix . 'hesabix',
|
||||||
array(
|
array(
|
||||||
'id_hesabix' => $idHesabix,
|
'id_hesabix' => $idHesabix,
|
||||||
|
@ -507,14 +622,21 @@ class HesabixWpFaService
|
||||||
),
|
),
|
||||||
array('id' => $wpFa->id),
|
array('id' => $wpFa->id),
|
||||||
array(
|
array(
|
||||||
'%s',
|
'%d',
|
||||||
'%s',
|
'%s',
|
||||||
'%d',
|
'%d',
|
||||||
'%d',
|
'%d',
|
||||||
'%s'
|
'%d'
|
||||||
),
|
),
|
||||||
array('%d')
|
array('%d')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($result === false) {
|
||||||
|
HesabixLogService::log(array("Error updating database: " . $wpdb->last_error));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ jQuery(function($) {
|
||||||
saveBtn.addClass('loading').prop('disabled', true);
|
saveBtn.addClass('loading').prop('disabled', true);
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
action: 'adminSaveApiSettings',
|
action: 'admin_save_api_settings',
|
||||||
nonce: hesabix_ajax.nonce,
|
nonce: hesabix_ajax.nonce,
|
||||||
api_key: $('#hesabix_account_api').val(),
|
api_key: $('#hesabix_account_api').val(),
|
||||||
api_address: $('#hesabix_api_address').val(),
|
api_address: $('#hesabix_api_address').val(),
|
||||||
|
@ -1130,7 +1130,7 @@ jQuery(function($) {
|
||||||
url: ajaxurl,
|
url: ajaxurl,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
action: 'adminTestApiConnection',
|
action: 'admin_test_api_connection',
|
||||||
nonce: hesabix_ajax.nonce
|
nonce: hesabix_ajax.nonce
|
||||||
},
|
},
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ jQuery(function($) {
|
||||||
saveBtn.addClass('loading').prop('disabled', true);
|
saveBtn.addClass('loading').prop('disabled', true);
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
action: 'adminSaveApiSettings',
|
action: 'admin_save_api_settings',
|
||||||
nonce: hesabix_ajax.nonce,
|
nonce: hesabix_ajax.nonce,
|
||||||
api_key: $('#hesabix_account_api').val(),
|
api_key: $('#hesabix_account_api').val(),
|
||||||
api_address: $('#hesabix_api_address').val(),
|
api_address: $('#hesabix_api_address').val(),
|
||||||
|
@ -1130,7 +1130,7 @@ jQuery(function($) {
|
||||||
url: ajaxurl,
|
url: ajaxurl,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
action: 'adminTestApiConnection',
|
action: 'admin_test_api_connection',
|
||||||
nonce: hesabix_ajax.nonce
|
nonce: hesabix_ajax.nonce
|
||||||
},
|
},
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* Plugin Name: Hesabix: WooCommerce
|
* Plugin Name: Hesabix: WooCommerce
|
||||||
* Plugin URI: https://hesabix.ir/
|
* Plugin URI: https://hesabix.ir/
|
||||||
* Description: Connect Hesabix Online Accounting to WooCommerce.
|
* Description: Connect Hesabix Online Accounting to WooCommerce.
|
||||||
* Version: 1.0.3
|
* Version: 1.0.4
|
||||||
* Author: Mohammad Rezai
|
* Author: Mohammad Rezai
|
||||||
* Author URI: https://pirouz.xyz
|
* Author URI: https://pirouz.xyz
|
||||||
* License: GPL-3.0+
|
* License: GPL-3.0+
|
||||||
|
@ -24,7 +24,7 @@ if (!defined('WPINC')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
define('HESABIX_PLUGIN_URL', plugin_dir_url(__FILE__));
|
define('HESABIX_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||||
define('HESABIX_VERSION', '1.0.3');
|
define('HESABIX_VERSION', '1.0.4');
|
||||||
|
|
||||||
function activate_hesabix()
|
function activate_hesabix()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ include_once(dirname(__DIR__) . '/admin/services/hesabixLogService.php');
|
||||||
class Hesabix_Api
|
class Hesabix_Api
|
||||||
{
|
{
|
||||||
|
|
||||||
public function apiRequest($method, $data = array())
|
public function apiRequest($method, $data = array(), $timeout = 15)
|
||||||
{
|
{
|
||||||
if ($method == null)
|
if ($method == null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,6 +45,8 @@ class Hesabix_Api
|
||||||
HesabixLogService::log(array("Debug Mode - Data: " . print_r($data, true)));
|
HesabixLogService::log(array("Debug Mode - Data: " . print_r($data, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'body' => wp_json_encode($body),
|
'body' => wp_json_encode($body),
|
||||||
'headers' => array(
|
'headers' => array(
|
||||||
|
@ -53,16 +55,13 @@ class Hesabix_Api
|
||||||
'activeBid' => get_option('hesabix_account_bid'),
|
'activeBid' => get_option('hesabix_account_bid'),
|
||||||
'activeYear' => get_option('hesabix_account_year'),
|
'activeYear' => get_option('hesabix_account_year'),
|
||||||
),
|
),
|
||||||
'timeout' => 15,
|
'timeout' => $timeout,
|
||||||
'redirection' => 5,
|
'redirection' => 5,
|
||||||
'blocking' => true,
|
'blocking' => true,
|
||||||
'data_format' => 'body',
|
'data_format' => 'body',
|
||||||
);
|
);
|
||||||
|
|
||||||
$wp_remote_post = wp_remote_post($endpoint, $options);
|
$wp_remote_post = wp_remote_post($endpoint, $options);
|
||||||
if ($method == 'api/commodity/search/extra') {
|
|
||||||
|
|
||||||
}
|
|
||||||
$result = json_decode(wp_remote_retrieve_body($wp_remote_post));
|
$result = json_decode(wp_remote_retrieve_body($wp_remote_post));
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ class Hesabix_Api
|
||||||
case '103':
|
case '103':
|
||||||
return 'MissingData';
|
return 'MissingData';
|
||||||
case '104':
|
case '104':
|
||||||
return 'MissingParameter' . '. ErrorMessage: ' . $result->ErrorMessage;
|
return 'MissingParameter' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
|
||||||
case '105':
|
case '105':
|
||||||
return 'ApiDisabled';
|
return 'ApiDisabled';
|
||||||
case '106':
|
case '106':
|
||||||
|
@ -99,13 +98,13 @@ class Hesabix_Api
|
||||||
case '111':
|
case '111':
|
||||||
return 'IdMustNotBeZero';
|
return 'IdMustNotBeZero';
|
||||||
case '112':
|
case '112':
|
||||||
return 'ObjectNotFound' . '. ErrorMessage: ' . $result->ErrorMessage;
|
return 'ObjectNotFound' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
|
||||||
case '113':
|
case '113':
|
||||||
return 'MissingApiKey';
|
return 'MissingApiKey';
|
||||||
case '114':
|
case '114':
|
||||||
return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . $result->ErrorMessage;
|
return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
|
||||||
case '190':
|
case '190':
|
||||||
return 'ApplicationError' . '. ErrorMessage: ' . $result->ErrorMessage;
|
return 'ApplicationError' . '. ErrorMessage: ' . (string) $result->ErrorMessage;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -158,7 +157,7 @@ class Hesabix_Api
|
||||||
'items' => $contacts,
|
'items' => $contacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->apiRequest($method, $data);
|
return $this->apiRequest($method, $data, 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function contactDelete($code)
|
public function contactDelete($code)
|
||||||
|
@ -243,7 +242,7 @@ class Hesabix_Api
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->apiRequest($method, $data);
|
return $this->apiRequest($method, $data, 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function itemDelete($code)
|
public function itemDelete($code)
|
||||||
|
|
|
@ -338,18 +338,10 @@ class Hesabix_Webhook
|
||||||
{
|
{
|
||||||
$hesabixApi = new Hesabix_Api();
|
$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);
|
$result = $hesabixApi->itemGetItemsByCodes($codeList);
|
||||||
|
|
||||||
|
|
||||||
if (is_object($result) && $result->Success) {
|
if (is_object($result) && $result->Success) {
|
||||||
// return $warehouse == "-1" ? $result->Result->List : $result->Result;
|
|
||||||
return $result->Result->List;
|
return $result->Result->List;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,8 +133,8 @@ class Hesabix
|
||||||
$this->loader->add_filter('wp_ajax_adminUpdateProductAndVariations', $plugin_admin, 'adminUpdateProductAndVariationsCallback');
|
$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_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_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_admin_save_api_settings', $plugin_admin, 'admin_save_api_settingsCallback');
|
||||||
$this->loader->add_filter('wp_ajax_adminTestApiConnection', $plugin_admin, 'adminTestApiConnectionCallback');
|
$this->loader->add_filter('wp_ajax_admin_test_api_connection', $plugin_admin, 'admin_test_api_connectionCallback');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue