Compare commits

..

No commits in common. "master" and "1.0.3" have entirely different histories.

10 changed files with 101 additions and 225 deletions

View file

@ -1824,7 +1824,7 @@ class Hesabix_Admin
wp_send_json($response); wp_send_json($response);
} }
public function admin_save_api_settingsCallback() public function adminSaveApiSettingsCallback()
{ {
check_ajax_referer('hesabix_ajax_nonce', 'nonce'); check_ajax_referer('hesabix_ajax_nonce', 'nonce');
@ -1849,7 +1849,7 @@ class Hesabix_Admin
} }
} }
public function admin_test_api_connectionCallback() public function adminTestApiConnectionCallback()
{ {
check_ajax_referer('hesabix_ajax_nonce', 'nonce'); check_ajax_referer('hesabix_ajax_nonce', 'nonce');

View file

@ -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: " . (string) $fiscalYear->ErrorCode . ". Error Message: " . (string) $fiscalYear->ErrorMessage)); HesabixLogService::log(array("Cannot get FiscalDate. Error Code: $fiscalYear->ErrroCode. Error Message: $fiscalYear->ErrorMessage"));
return __('Cannot connect to Hesabix for get FiscalDate.', 'hesabix'); return __('Cannot connect to Hesabix for get FiscalDate.', 'hesabix');
} }
} else { } else {
@ -122,22 +122,11 @@ class Hesabix_Admin_Functions
$response = $hesabix->itemBatchSave($items); $response = $hesabix->itemBatchSave($items);
if ($response->Success) { if ($response->Success) {
$itemsToProcess = array(); foreach ($response->createdItems as $item)
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: " . (string) $response->ErrorMessage . ". response: " . print_r($response, true))); HesabixLogService::log(array("Cannot add/update Hesabix items. Error Code: " . (string) $response->ErrorCode . ". Error Message: $response->ErrorMessage."));
return false; return false;
} }
} }
@ -183,7 +172,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->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: $id_customer")); HesabixLogService::log(array("Cannot add/update customer. Error Code: " . (string) $response->ErrroCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: $id_customer"));
return false; return false;
} }
} }
@ -208,7 +197,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->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: Guest Customer")); HesabixLogService::log(array("Cannot add/update contact. Error Code: " . (string) $response->ErrroCode . ". Error Message: " . (string) $response->ErrorMessage . ". Customer ID: Guest Customer"));
return false; return false;
} }
} }
@ -243,7 +232,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;
@ -918,7 +907,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: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . ".")); HesabixLogService::log(array("Error while trying to get products for import. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
$result["error"] = true; $result["error"] = true;
return $result; return $result;
} }
@ -1105,9 +1094,9 @@ class Hesabix_Admin_Functions
if ($response->Success) { if ($response->Success) {
} else { } else {
HesabixLogService::log(array("hesabix - Cannot set Opening quantity. Error Code: " . (string) $response->ErrorCode . ". Error Message: " . (string) $response->ErrorMessage)); HesabixLogService::log(array("hesabix - Cannot set Opening quantity. Error Code: ' . $response->ErrorCode . '. Error Message: ' . $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;
} }
@ -1170,7 +1159,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: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . ".")); HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
} }
} }
@ -1384,7 +1373,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: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . ".")); HesabixLogService::log(array("Error while trying to get products for sync. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
$result["error"] = true; $result["error"] = true;
return $result; return $result;
} }
@ -1413,7 +1402,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: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode . ".")); HesabixLogService::log(array("Error while trying to get products for sync. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
$result["error"] = true; $result["error"] = true;
return $result; return $result;
} }
@ -1561,7 +1550,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, 'Take' => -1)); $items = $api->itemGetItems(array('Filters' => $filters));
foreach ($items->data->List as $item) { foreach ($items->data->List as $item) {
@ -2137,7 +2126,7 @@ class Hesabix_Admin_Functions
return false; return false;
} }
} else { } else {
HesabixLogService::writeLogStr('Error Occurred in Checking Mobile and NationalCode. ErrorCode: ' . (string) $response->ErrorCode . " - ErrorMessage: " . (string) $response->ErrorMessage); HesabixLogService::writeLogStr('Error Occurred in Checking Mobile and NationalCode. ErrorCode: ' . $response->ErrorCode . " - ErrorMessage: " . $response->ErrorMessage);
return false; return false;
} }
} }

View file

@ -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, 'Take' => -1)); $response = $hesabix->itemGetItems(array('Filters' => $filters));
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') . (string) $default_currency->ErrorMessage . '</p>'; echo '<p class="hesabix-p">' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . $default_currency->ErrorMessage . '</p>';
echo '</div>'; echo '</div>';
} }
HesabixLogService::log(array("Cannot check the Hesabix default currency. Error Message: " . (string) $default_currency->ErrorMessage . ". Error Code: " . (string) $default_currency->ErrorCode)); HesabixLogService::log(array("Cannot check the Hesabix default currency. Error Message: $default_currency->ErrorMessage. Error Code: $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') . (string) $response->ErrorMessage . '</p>'; echo '<p class="hesabix-p">' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . $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') . (string) $response->ErrorMessage . '</p>'; echo '<p class="hesabix-p">' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . $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: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode)); HesabixLogService::log(array("Cannot set Hesabix webHook. Error Message: $response->ErrorMessage. Error Code: $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: " . (string) $banks->ErrorCode . ". Error Message: " . (string) $banks->ErrorMessage . ".")); HesabixLogService::log(array("Cannot get banking information. Error Code: $banks->ErrorCode. Error Message: $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: " . (string) $projects->ErrorCode . ". Error Message: " . (string) $projects->ErrorMessage . ".")); HesabixLogService::log(array("Cannot get projects information. Error Code:$projects->ErrorCode. Error Message: $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: " . (string) $salesmen->ErrorCode . ". Error Message: " . (string) $salesmen->ErrorMessage . ".")); HesabixLogService::log(array("Cannot get salesmen information. Error Code: $salesmen->ErrorCode Error Message: .$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: " . (string) $warehouses->ErrorCode . ". Error Message: " . (string) $warehouses->ErrorMessage . ".")); HesabixLogService::log(array("Cannot get warehouses. Error Code: $warehouses->ErrorCode. Error Message: .$warehouses->ErrorMessage."));
return array('0' => __('Cannot get warehouses.', 'hesabix')); return array('0' => __('Cannot get warehouses.', 'hesabix'));
} }

View file

@ -91,21 +91,6 @@ 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);
@ -359,38 +344,18 @@ 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)) {
if (is_string($item->tags)) { $json = $item->tags;
$tagData = json_decode($item->tags); if (isset($json->id_product))
} else { $id_product = (int) $json->id_product;
$tagData = $item->tags; if (isset($json->id_attribute))
} $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();
@ -398,49 +363,24 @@ 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);
$result = $wpFaService->save($wpFa); $wpFaService->save($wpFa);
if ($result) { HesabixLogService::log(array("Item successfully added. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
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;
$result = $wpFaService->update($wpFa); $wpFaService->update($wpFa);
if ($result) { HesabixLogService::log(array("Item successfully updated. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
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
{ {
// Handle both string and object formats for tags $json = json_decode($customer->tags);
$tagData = null; if ((int) $json->id_customer == 0)
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) $tagData->id_customer); $id = $this->getWpFaId('customer', (int) $json->id_customer);
global $wpdb; global $wpdb;
if (!$id) { if (!$id) {
@ -450,7 +390,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) $tagData->id_customer 'id_ps' => (int) $json->id_customer
), ),
array( array(
'%d', '%d',
@ -460,7 +400,7 @@ class HesabixWpFaService
) )
); );
HesabixLogService::writeLogStr("Customer successfully added. Customer code: " . (string) $customer->code . ". Customer ID: " . $tagData->id_customer); HesabixLogService::writeLogStr("Customer successfully added. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
} else { } else {
$wpdb->update( $wpdb->update(
$wpdb->prefix . 'hesabix', $wpdb->prefix . 'hesabix',
@ -468,7 +408,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) $tagData->id_customer, 'id_ps' => (int) $json->id_customer,
), ),
array('id' => $id), array('id' => $id),
array( array(
@ -480,91 +420,43 @@ class HesabixWpFaService
array('%d') array('%d')
); );
HesabixLogService::writeLogStr("Customer successfully updated. Customer code: " . (string) $customer->code . ". Customer ID: " . $tagData->id_customer); HesabixLogService::writeLogStr("Customer successfully updated. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
} }
return true; return true;
} }
public function saveInvoice($invoice, $orderType) public function saveInvoice($invoice, $orderType)
{ {
// Handle both string and object formats for Tag $json = json_decode($invoice->Tag);
$tagData = null; $id = $this->getPsFaId('order', (int) $json->id_order);
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) {
global $wpdb; Db::getInstance()->insert('ps_hesabix', array(
$result = $wpdb->insert( 'id_hesabix' => $invoiceNumber,
$wpdb->prefix . 'hesabix', 'obj_type' => $objType,
array( 'id_ps' => (int) $json->id_order,
'id_hesabix' => $invoiceNumber, ));
'obj_type' => $objType,
'id_ps' => (int) $tagData->id_order,
),
array(
'%d',
'%s',
'%d'
)
);
if ($result) {
if ($objType == 'order') if ($objType == 'order')
HesabixLogService::log(array("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order)); LogService::writeLogStr("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
else else
HesabixLogService::log(array("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $tagData->id_order)); LogService::writeLogStr("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
} else {
HesabixLogService::log(array("Failed to add invoice to database: " . $wpdb->last_error));
return false;
}
} else { } else {
global $wpdb; Db::getInstance()->update('ps_hesabix', array(
$result = $wpdb->update( 'id_hesabix' => $invoiceNumber,
$wpdb->prefix . 'hesabix', 'obj_type' => $objType,
array( 'id_ps' => (int) $json->id_order,
'id_hesabix' => $invoiceNumber, ), array('id' => $id), 0, true, true);
'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')
HesabixLogService::log(array("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $tagData->id_order)); LogService::writeLogStr("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
else else
HesabixLogService::log(array("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $tagData->id_order)); LogService::writeLogStr("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
} else {
HesabixLogService::log(array("Failed to update invoice in database: " . $wpdb->last_error));
return false;
}
} }
return true; return true;
@ -573,8 +465,7 @@ 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,
@ -584,20 +475,14 @@ class HesabixWpFaService
'uid_hesabix' => (int) $wpFa->uidHesabix, 'uid_hesabix' => (int) $wpFa->uidHesabix,
), ),
array( array(
'%d', '%s',
'%s', '%s',
'%d', '%d',
'%d', '%d',
'%d' '%s'
) )
); );
if ($result === false) {
HesabixLogService::log(array("Error inserting into database: " . $wpdb->last_error));
return false;
}
return true;
} }
@ -605,13 +490,13 @@ class HesabixWpFaService
{ {
global $wpdb; global $wpdb;
$idHesabix = isset($wpFa->idHesabix) ? (int) $wpFa->idHesabix : 0; $idHesabix = isset($wpFa->idHesabix) ? sanitize_text_field($wpFa->idHesabix) : '';
$uidHesabix = isset($wpFa->uidHesabix) ? (int) $wpFa->uidHesabix : 0; $uidHesabix = isset($wpFa->uidHesabix) ? sanitize_text_field($wpFa->uidHesabix) : '';
$objType = isset($wpFa->objType) ? $wpFa->objType : ''; $objType = isset($wpFa->objType) ? sanitize_text_field($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;
$result = $wpdb->update( $wpdb->update(
$wpdb->prefix . 'hesabix', $wpdb->prefix . 'hesabix',
array( array(
'id_hesabix' => $idHesabix, 'id_hesabix' => $idHesabix,
@ -622,21 +507,14 @@ class HesabixWpFaService
), ),
array('id' => $wpFa->id), array('id' => $wpFa->id),
array( array(
'%d', '%s',
'%s', '%s',
'%d', '%d',
'%d', '%d',
'%d' '%s'
), ),
array('%d') array('%d')
); );
if ($result === false) {
HesabixLogService::log(array("Error updating database: " . $wpdb->last_error));
return false;
}
return true;
} }

View file

@ -1096,7 +1096,7 @@ jQuery(function($) {
saveBtn.addClass('loading').prop('disabled', true); saveBtn.addClass('loading').prop('disabled', true);
const formData = { const formData = {
action: 'admin_save_api_settings', action: 'adminSaveApiSettings',
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: 'admin_test_api_connection', action: 'adminTestApiConnection',
nonce: hesabix_ajax.nonce nonce: hesabix_ajax.nonce
}, },
success: (response) => { success: (response) => {

View file

@ -1096,7 +1096,7 @@ jQuery(function($) {
saveBtn.addClass('loading').prop('disabled', true); saveBtn.addClass('loading').prop('disabled', true);
const formData = { const formData = {
action: 'admin_save_api_settings', action: 'adminSaveApiSettings',
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: 'admin_test_api_connection', action: 'adminTestApiConnection',
nonce: hesabix_ajax.nonce nonce: hesabix_ajax.nonce
}, },
success: (response) => { success: (response) => {

View file

@ -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.4 * Version: 1.0.2
* 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.4'); define('HESABIX_VERSION', '1.0.2');
function activate_hesabix() function activate_hesabix()
{ {

View file

@ -13,7 +13,7 @@ include_once(dirname(__DIR__) . '/admin/services/hesabixLogService.php');
class Hesabix_Api class Hesabix_Api
{ {
public function apiRequest($method, $data = array(), $timeout = 15) public function apiRequest($method, $data = array())
{ {
if ($method == null) if ($method == null)
return false; return false;
@ -45,8 +45,6 @@ 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(
@ -55,13 +53,16 @@ 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' => $timeout, 'timeout' => 15,
'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));
@ -84,7 +85,7 @@ class Hesabix_Api
case '103': case '103':
return 'MissingData'; return 'MissingData';
case '104': case '104':
return 'MissingParameter' . '. ErrorMessage: ' . (string) $result->ErrorMessage; return 'MissingParameter' . '. ErrorMessage: ' . $result->ErrorMessage;
case '105': case '105':
return 'ApiDisabled'; return 'ApiDisabled';
case '106': case '106':
@ -98,13 +99,13 @@ class Hesabix_Api
case '111': case '111':
return 'IdMustNotBeZero'; return 'IdMustNotBeZero';
case '112': case '112':
return 'ObjectNotFound' . '. ErrorMessage: ' . (string) $result->ErrorMessage; return 'ObjectNotFound' . '. ErrorMessage: ' . $result->ErrorMessage;
case '113': case '113':
return 'MissingApiKey'; return 'MissingApiKey';
case '114': case '114':
return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . (string) $result->ErrorMessage; return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . $result->ErrorMessage;
case '190': case '190':
return 'ApplicationError' . '. ErrorMessage: ' . (string) $result->ErrorMessage; return 'ApplicationError' . '. ErrorMessage: ' . $result->ErrorMessage;
} }
} else { } else {
return $result; return $result;
@ -157,7 +158,7 @@ class Hesabix_Api
'items' => $contacts, 'items' => $contacts,
); );
return $this->apiRequest($method, $data, 120); return $this->apiRequest($method, $data);
} }
public function contactDelete($code) public function contactDelete($code)
@ -242,7 +243,7 @@ class Hesabix_Api
'items' => $items, 'items' => $items,
); );
return $this->apiRequest($method, $data, 120); return $this->apiRequest($method, $data);
} }
public function itemDelete($code) public function itemDelete($code)

View file

@ -338,10 +338,18 @@ 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;
} }

View file

@ -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_admin_save_api_settings', $plugin_admin, 'admin_save_api_settingsCallback'); $this->loader->add_filter('wp_ajax_adminSaveApiSettings', $plugin_admin, 'adminSaveApiSettingsCallback');
$this->loader->add_filter('wp_ajax_admin_test_api_connection', $plugin_admin, 'admin_test_api_connectionCallback'); $this->loader->add_filter('wp_ajax_adminTestApiConnection', $plugin_admin, 'adminTestApiConnectionCallback');
} }