Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
69625d47d8 | ||
![]() |
99fdeed88a | ||
![]() |
dce1fa4d23 | ||
|
f720175e2d |
10
README.md
10
README.md
|
@ -12,7 +12,7 @@ Modern, localized, and secure WooCommerce integration with Hesabix Cloud Account
|
|||
|
||||
== 🧩 Overview ==
|
||||
|
||||
**Hesabix for WooCommerce** connects your online store with [Hesabix](https://hesabix.com), the powerful cloud-based accounting system built for Persian businesses.
|
||||
**Hesabix for WooCommerce** connects your online store with [Hesabix](https://hesabix.ir), the powerful cloud-based accounting system built for Persian businesses.
|
||||
|
||||
From real-time product, order, and customer sync to full Persian date support, this plugin is everything a modern Iranian online store needs to automate its bookkeeping.
|
||||
|
||||
|
@ -53,7 +53,7 @@ From real-time product, order, and customer sync to full Persian date support, t
|
|||
1. Upload the plugin to `/wp-content/plugins/hesabix-woocommerce/`
|
||||
2. Activate via **Plugins > Hesabix for WooCommerce**
|
||||
3. Go to **WooCommerce > Hesabix Settings**
|
||||
4. Enter your API Key (get it from your [Hesabix account](https://app.hesabix.com))
|
||||
4. Enter your API Key (get it from your [Hesabix account](https://app.hesabix.ir))
|
||||
5. Test connection and start syncing!
|
||||
|
||||
== ❓ Frequently Asked Questions ==
|
||||
|
@ -83,9 +83,9 @@ Yes — we follow WordPress best practices including nonce verification, secure
|
|||
|
||||
== 🌐 Resources ==
|
||||
|
||||
- [Official Website](https://hesabix.com)
|
||||
- [User Guide](https://hesabix.com/school)
|
||||
- [Support](https://hesabix.com/support)
|
||||
- [Official Website](https://hesabix.ir)
|
||||
- [User Guide](https://hesabix.ir/school)
|
||||
- [Support](https://hesabix.ir/support)
|
||||
|
||||
== 👨💻 Credits ==
|
||||
|
||||
|
|
|
@ -1778,7 +1778,8 @@ class Hesabix_Admin
|
|||
}
|
||||
|
||||
try {
|
||||
$plugin_stats = wp_remote_get('https://hesabix.dragonizzer.ir/api/wordpress/plugin/stats');
|
||||
$plugin_stats = wp_remote_get('https://app.hesabix.ir/api/wordpress/plugin/stats');
|
||||
error_log(print_r($plugin_stats['body'], true));
|
||||
|
||||
if ($plugin_stats && !is_wp_error($plugin_stats) && $plugin_stats['response']['code'] == 200) {
|
||||
|
||||
|
@ -1823,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');
|
||||
|
||||
|
@ -1848,7 +1849,7 @@ class Hesabix_Admin
|
|||
}
|
||||
}
|
||||
|
||||
public function adminTestApiConnectionCallback()
|
||||
public function admin_test_api_connectionCallback()
|
||||
{
|
||||
check_ajax_referer('hesabix_ajax_nonce', 'nonce');
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 '<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>';
|
||||
}
|
||||
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 '<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>';
|
||||
}
|
||||
update_option('hesabix_business_expired', 1);
|
||||
} else {
|
||||
if ($show_errors) {
|
||||
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>';
|
||||
}
|
||||
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 '<p class="hesabix-p">' . __('Cannot get Banks detail.', 'hesabix') . '</p>';
|
||||
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'));
|
||||
}
|
||||
|
@ -2147,7 +2147,7 @@ class Hesabix_Setting
|
|||
echo '<div class="error">';
|
||||
echo '<p class="hesabix-p">' . __('Cannot get Projects detail.', 'hesabix') . '</p>';
|
||||
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'));
|
||||
}
|
||||
|
@ -2171,7 +2171,7 @@ class Hesabix_Setting
|
|||
echo '<div class="error">';
|
||||
echo '<p class="hesabix-p">' . __('Cannot get Salesmen detail.', 'hesabix') . '</p>';
|
||||
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'));
|
||||
}
|
||||
|
@ -2422,7 +2422,7 @@ class Hesabix_Setting
|
|||
echo '<div class="error">';
|
||||
echo '<p class="hesabix-p">' . __('Cannot get warehouses.', 'hesabix') . '</p>';
|
||||
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'));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* @author Mohammad Rezai
|
||||
* @author URI https://pirouz.xyz
|
||||
* @since 1.0.0
|
||||
*
|
||||
*/
|
||||
|
||||
include_once('hesabixLogService.php');
|
||||
|
@ -90,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);
|
||||
|
@ -343,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();
|
||||
|
@ -362,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) {
|
||||
|
@ -389,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',
|
||||
|
@ -399,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',
|
||||
|
@ -407,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(
|
||||
|
@ -419,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;
|
||||
|
@ -464,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,
|
||||
|
@ -474,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -489,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,
|
||||
|
@ -506,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;
|
||||
}
|
||||
|
||||
|
|
@ -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) => {
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* Plugin Name: Hesabix: WooCommerce
|
||||
* Plugin URI: https://hesabix.ir/
|
||||
* Description: Connect Hesabix Online Accounting to WooCommerce.
|
||||
* Version: 1.0.0
|
||||
* 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.0');
|
||||
define('HESABIX_VERSION', '1.0.4');
|
||||
|
||||
function activate_hesabix()
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -338,18 +338,10 @@ class Hesabix_Webhook
|
|||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue