';
}
public function hesabix_live_mode_notice()
{
echo '
' . __('Hesabix Plugin need to connect to Hesabix Accounting, Please check the API credential!', 'hesabix') . '
';
}
public function hesabix_business_expired_notice()
{
echo '
' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . '
';
}
public function hesabix_currency_notice()
{
echo '
' . __('Hesabix Plugin cannot works! because WooCommerce currency in not match with Hesabix.', 'hesabix') . '
';
}
public function hesabix_general_notices()
{
if (!empty($_REQUEST['submit_selected_orders_invoice_in_hesabix'])) {
if (!empty($_REQUEST['error_msg']) && $_REQUEST['error_msg'] == "select_max_10_items") {
printf(
'
%s
',
__('Error: Select maximum 10 orders. Due to some limitations in Hesabix API, sending too many requests in one minute is not possible.', 'hesabix')
);
} else {
$success_count = intval($_REQUEST['success_count']);
printf('
%s %d
', __('Selected orders invoices have been saved. Number of saved invoices: ', 'hesabix'), $success_count);
}
}
}
public function adminExportProductsCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$updateCount = wc_clean($_POST['updateCount']);
$func = new Hesabix_Admin_Functions();
$result = $func->exportProducts($batch, $totalBatch, $total, $updateCount);
if ($result['error']) {
if ($updateCount === -1) {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productExportResult=false&error=-1');
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productExportResult=false');
}
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productExportResult=true&processed=' . $result['updateCount']);
}
echo json_encode($result);
die();
}
}
public function adminImportProductsCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$updateCount = wc_clean($_POST['updateCount']);
$func = new Hesabix_Admin_Functions();
$result = $func->importProducts($batch, $totalBatch, $total, $updateCount);
$import_count = $result['updateCount'];
if ($result['error']) {
if ($import_count === -1) {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productImportResult=false&error=-1');
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productImportResult=false');
}
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productImportResult=true&processed=' . $import_count);
}
echo json_encode($result);
die();
}
}
public function adminExportProductsOpeningQuantityCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$func = new Hesabix_Admin_Functions();
$result = $func->exportOpeningQuantity($batch, $totalBatch, $total);
if ($result['error']) {
if ($result['errorType'] == 'shareholderError') {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productOpeningQuantityExportResult=false&shareholderError=true');
} else if ($result['errorType'] == 'noProduct') {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productOpeningQuantityExportResult=false&noProduct=true');
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productOpeningQuantityExportResult=false');
}
} else {
if ($result["done"] == true)
update_option('hesabix_use_export_product_opening_quantity', true);
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&productOpeningQuantityExportResult=true');
}
echo json_encode($result);
die();
}
}
public function adminExportCustomersCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$updateCount = wc_clean($_POST['updateCount']);
$func = new Hesabix_Admin_Functions();
$result = $func->exportCustomers($batch, $totalBatch, $total, $updateCount);
if ($result["error"]) {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&customerExportResult=false');
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=export&customerExportResult=true&processed=' . $result["updateCount"]);
}
echo json_encode($result);
die();
}
}
public function adminSyncChangesCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
include(dirname(__FILE__) . '/../includes/class-hesabix-webhook.php');
new Hesabix_Webhook();
wp_send_json(array(
'success' => true,
'message' => __('changes synced successfully', 'hesabix')
));
}
}
public function admin_sync_products_callback()
{
if (!wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error('Security check failed');
}
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$func = new Hesabix_Admin_Functions();
$result = $func->syncProducts($batch, $totalBatch, $total);
if ($result['error']) {
wp_send_json(array(
'success' => false,
'message' => __('Error syncing prices and inventory. Please check the logs.', 'hesabix')
));
} else {
wp_send_json(array(
'success' => true,
'message' => __('Prices and inventory synced successfully', 'hesabix')
));
}
}
}
public function admin_sync_orders_callback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$updateCount = wc_clean($_POST['updateCount']);
$from_date = wc_clean($_POST['date']);
$end_date = wc_clean($_POST['endDate']);
$func = new Hesabix_Admin_Functions();
$result = $func->syncOrders($from_date, $end_date, $batch, $totalBatch, $total, $updateCount);
if (!$result['error']) {
wp_send_json(array(
'success' => true,
'message' => __('Orders synchronized successfully.', 'hesabix')
));
} else {
wp_send_json(array(
'success' => false,
'message' => $result['error']
));
}
}
}
public function admin_update_products_callback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$func = new Hesabix_Admin_Functions();
$result = $func->updateProductsInHesabixBasedOnStore($batch, $totalBatch, $total);
if ($result['error']) {
wp_send_json(array(
'success' => false,
'message' => __('Error updating products. Please check the logs.', 'hesabix')
));
} else {
wp_send_json(array(
'success' => true,
'message' => __('Products updated successfully', 'hesabix')
));
}
}
}
public function admin_update_wc_products_callback()
{
if (!wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error('Security check failed');
}
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$batch = wc_clean($_POST['batch']);
$totalBatch = wc_clean($_POST['totalBatch']);
$total = wc_clean($_POST['total']);
$func = new Hesabix_Admin_Functions();
$result = $func->updateWooCommerceProductsBasedOnHesabix($batch, $totalBatch, $total);
if ($result['error']) {
wp_send_json(array(
'success' => false,
'message' => __('Error updating products. Please check the logs.', 'hesabix')
));
} else {
wp_send_json(array(
'success' => true,
'message' => __('Products updated successfully', 'hesabix')
));
}
}
}
public function adminUpdateProductsWithFilterCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$offset = wc_clean($_POST['offset']);
$rpp = wc_clean($_POST['rpp']);
if (abs($rpp - $offset) <= 200) {
$func = new Hesabix_Admin_Functions();
$result = $func->updateProductsInHesabixBasedOnStoreWithFilter($offset, $rpp);
if ($result['error']) {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=sync&$productUpdateWithFilterResult=false');
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=sync&$productUpdateWithFilterResult=true');
}
echo json_encode($result);
die();
} else {
$result["redirectUrl"] = admin_url('admin.php?page=hesabix-option&tab=sync&$productUpdateWithFilterResult=false');
echo json_encode($result);
die();
}
}
}
public function adminSubmitInvoiceCallback()
{
HesabixLogService::writeLogStr('Submit Invoice Manually');
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$orderId = wc_clean($_POST['orderId']);
$func = new Hesabix_Admin_Functions();
$result = $func->setOrder($orderId);
if ($result)
$func->setOrderPayment($orderId);
echo json_encode($result);
die();
}
}
public function adminClearPluginDataCallback()
{
HesabixLogService::writeLogStr('Clear Plugin Data');
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$hesabixApi = new Hesabix_Api();
$result = $hesabixApi->fixClearTags();
if (!$result->Success) {
HesabixLogService::log(array("hesabix-Cannot clear tags. Error Message: " . (string) $result->ErrorMessage . ". Error Code: " . (string) $result->ErrorCode));
}
global $wpdb;
$options = $wpdb->get_results("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%hesabix%'");
foreach ($options as $option) {
delete_option($option->option_name);
}
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}hesabix");
die();
}
}
public function adminInstallPluginDataCallback()
{
HesabixLogService::writeLogStr('Install Plugin Data');
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
require_once dirname(__FILE__) . '/includes/class-hesabix-activator.php';
Hesabix_Activator::activate();
die();
}
}
public function admin_product_add_column($columns)
{
$hesabixArray = array("hesabix_code" => "کد در حسابیکس");
$columns = $hesabixArray + $columns;
return $columns;
}
public function admin_product_export_rows($rows, $products)
{
$rowsArray = explode("\n", $rows);
$exportRows = [];
$reflection = new ReflectionClass($products);
$property = $reflection->getProperty('row_data');
$property->setAccessible(true);
$productsArray = $property->getValue($products);
$matchingArray = [];
if (!empty($productsArray)) {
foreach ($productsArray as $product) {
if (is_array($product) && isset($product['id'])) {
$wpFaService = new HesabixWpFaService();
if ($product["type"] == "variation") {
if (array_key_exists('parent_id', $product)) {
$parentId = $product['parent_id'];
$productParentId = explode(':', $parentId)[1];
$wpFa = $wpFaService->getWpFaSearch($productParentId, $product['id'], '', "product");
}
} elseif ($product["type"] == "simple" || $product["type"] == "variable") {
$wpFa = $wpFaService->getWpFaSearch($product['id'], 0, '', "product");
}
if (is_array($wpFa)) {
foreach ($wpFa as $item) {
if ($item->idWpAttribute != 0) {
$matchingArray[$item->idWpAttribute] = $item->idHesabix;
} else {
$matchingArray[$item->idWp] = $item->idHesabix;
}
}
}
}
}
}
foreach ($rowsArray as $row) {
if (empty(trim($row))) {
continue;
}
$columns = str_getcsv($row);
$inserted = false;
if (isset($columns[1])) {
foreach ($matchingArray as $wpId => $hesabixId) {
if ($columns[1] == $wpId && !$inserted) {
$columns[0] = $hesabixId;
$inserted = true;
break;
}
}
}
if (!$inserted) {
$columns[0] = "کد ندارد";
}
$exportRows[] = implode(",", $columns);
}
return implode("\n", $exportRows);
}
public function hesabix_init_internal()
{
add_rewrite_rule('hesabix-webhook.php$', 'index.php?hesabix_webhook=1', 'top');
}
private function checkForSyncChanges()
{
$syncChangesLastDate = get_option('hesabix_sync_changes_last_date');
if (!isset($syncChangesLastDate) || $syncChangesLastDate == false) {
add_option('hesabix_sync_changes_last_date', new DateTime());
$syncChangesLastDate = new DateTime();
}
$nowDateTime = new DateTime();
$diff = $nowDateTime->diff($syncChangesLastDate);
if ($diff->i >= 4) {
HesabixLogService::writeLogStr('Sync Changes Automatically');
update_option('hesabix_sync_changes_last_date', new DateTime());
require_once plugin_dir_path(dirname(__FILE__)) . '/includes/class-hesabix-webhook.php';
new Hesabix_Webhook();
}
}
public function hesabix_query_vars($query_vars)
{
$query_vars[] = 'hesabix_webhook';
return $query_vars;
}
public function custom_hesabix_column_order_list($columns)
{
$reordered_columns = array();
foreach ($columns as $key => $column) {
$reordered_columns[$key] = $column;
if ($key == 'order_status') {
$reordered_columns['hesabix-column-invoice-number'] = __('Invoice in Hesabix', 'hesabix');
$reordered_columns['hesabix-column-submit-invoice'] = __('Submit Invoice', 'hesabix');
}
}
return $reordered_columns;
}
public function custom_orders_list_column_content($column, $post_id)
{
global $wpdb;
if (get_option('woocommerce_custom_orders_table_enabled') == 'yes') {
switch ($column) {
case 'hesabix-column-invoice-number':
$product_id = $post_id->ID;
$table_name = $wpdb->prefix . 'hesabix';
$row = $wpdb->get_row(
$wpdb->prepare(
"SELECT id_hesabix FROM $table_name WHERE id_ps = %d AND obj_type = 'order'",
$product_id
)
);
if (!empty($row)) {
echo '' . $row->id_hesabix . '';
} else {
echo '';
}
break;
case 'hesabix-column-submit-invoice':
$product_id = $post_id->ID;
echo '';
echo __('Submit Invoice', 'hesabix');
echo '';
break;
}
} else {
switch ($column) {
case 'hesabix-column-invoice-number':
$row = $wpdb->get_row("SELECT `id_hesabix` FROM `" . $wpdb->prefix . "hesabix` WHERE `id_ps` = $post_id AND `obj_type` = 'order'");
if (!empty($row))
echo '' . $row->id_hesabix . '';
else
echo '';
break;
case 'hesabix-column-submit-invoice':
echo '";
echo __('Submit Invoice', 'hesabix');
echo '';
break;
}
}
}
public function hesabix_parse_request(&$wp)
{
if (array_key_exists('hesabix_webhook', $wp->query_vars)) {
include(dirname(__FILE__) . '/includes/hesabix-webhook.php');
exit();
}
}
public function custom_orders_list_bulk_action($actions)
{
$actions['submit_invoice_in_hesabix'] = __('Submit Invoice in Hesabix', 'hesabix');
return $actions;
}
public function custom_orders_list_bulk_action_run($redirect_to, $action, $post_ids)
{
if ($action !== 'submit_invoice_in_hesabix')
return $redirect_to;
HesabixLogService::writeLogStr("Submit selected orders invoice");
if (count($post_ids) > 10)
return $redirect_to = add_query_arg(array(
'submit_selected_orders_invoice_in_hesabix' => '1',
'error_msg' => 'select_max_10_items'
), $redirect_to);
$success_count = 0;
$func = new Hesabix_Admin_Functions();
foreach ($post_ids as $orderId) {
$result = $func->setOrder($orderId);
if ($result) {
$success_count++;
$func->setOrderPayment($orderId);
}
}
return $redirect_to = add_query_arg(array(
'submit_selected_orders_invoice_in_hesabix' => '1',
'success_count' => $success_count,
'error_msg' => '0'
), $redirect_to);
}
public function hesabix_hook_edit_user(WP_User $user)
{
$wpFaService = new HesabixWpFaService();
$code = isset($user) ? $wpFaService->getCustomerCodeByWpId($user->ID) : '';
?>
getWpFaByHesabixId('customer', $user_hesabix_code);
$wpFa = $wpFaService->getWpFa('customer', $id_customer);
if (!$wpFaOld || !$wpFa || $wpFaOld->id !== $wpFa->id) {
if ($wpFaOld)
$wpFaService->delete($wpFaOld);
if ($wpFa) {
$wpFa->idHesabix = $user_hesabix_code;
$wpFaService->update($wpFa);
} else {
$wpFa = new WpFa();
$wpFa->objType = 'customer';
$wpFa->idWp = $id_customer;
$wpFa->idHesabix = intval($user_hesabix_code);
$wpFaService->save($wpFa);
}
}
}
$function = new Hesabix_Admin_Functions();
if (get_option('hesabix_contact_automatically_save_in_hesabix') == 'yes')
$function->setContact($id_customer);
}
public function hesabix_hook_delete_user($id_customer)
{
$wpFaService = new HesabixWpFaService();
$id_obj = $wpFaService->getWpFaId('customer', $id_customer);
if ($id_obj != false) {
global $wpdb;
$row = $wpdb->get_row("SELECT `id_hesabix` FROM `" . $wpdb->prefix . "hesabix` WHERE `id` = $id_obj AND `obj_type` = 'customer'");
if (is_object($row)) {
$hesabixApi = new Hesabix_Api();
$hesabixApi->contactDelete($row->id_hesabix);
}
global $wpdb;
$wpdb->delete($wpdb->prefix . 'hesabix', array('id_ps' => $id_customer));
HesabixLogService::log(array("Customer deleted. Customer ID: $id_customer"));
}
}
public function hesabix_hook_order_status_change($id_order, $from, $to)
{
HesabixLogService::writeLogStr("Order Status Hook");
$function = new Hesabix_Admin_Functions();
$invoice_statuses = get_option('hesabix_invoice_status', array());
if (!is_array($invoice_statuses)) {
if (is_string($invoice_statuses) && !empty($invoice_statuses)) {
$invoice_statuses = array_map('trim', explode(',', $invoice_statuses));
} else {
$invoice_statuses = array();
}
}
foreach ($invoice_statuses as $status) {
HesabixLogService::writeLogStr("status: $status");
if ($status == $to) {
$orderResult = $function->setOrder($id_order);
if ($orderResult) {
$payment_statuses = get_option('hesabix_payment_status', array());
if (!is_array($payment_statuses)) {
if (is_string($payment_statuses) && !empty($payment_statuses)) {
$payment_statuses = array_map('trim', explode(',', $payment_statuses));
} else {
$payment_statuses = array();
}
}
foreach ($payment_statuses as $statusPayment) {
if ($statusPayment == $to)
$function->setOrderPayment($id_order);
}
}
}
}
$values = get_option('hesabix_invoice_return_status');
if (is_array($values) || is_object($values)) {
foreach ($values as $status) {
if ($status == $to)
$function->setOrder($id_order, 2, $function->getInvoiceCodeByOrderId($id_order));
}
}
}
public function hesabix_hook_new_order($id_order, $order)
{
HesabixLogService::writeLogStr("New Order Hook");
$function = new Hesabix_Admin_Functions();
$orderStatus = wc_get_order($id_order)->get_status();
$orderItems = $order->get_items();
$invoice_statuses = get_option('hesabix_invoice_status', array());
if (!is_array($invoice_statuses)) {
if (is_string($invoice_statuses) && !empty($invoice_statuses)) {
$invoice_statuses = array_map('trim', explode(',', $invoice_statuses));
} else {
$invoice_statuses = array();
}
}
foreach ($invoice_statuses as $status) {
HesabixLogService::writeLogStr("status: $status");
if ($status == $orderStatus) {
$orderResult = $function->setOrder($id_order, 0, null, $orderItems);
if ($orderResult) {
$payment_statuses = get_option('hesabix_payment_status', array());
if (!is_array($payment_statuses)) {
if (is_string($payment_statuses) && !empty($payment_statuses)) {
$payment_statuses = array_map('trim', explode(',', $payment_statuses));
} else {
$payment_statuses = array();
}
}
foreach ($payment_statuses as $statusPayment) {
if ($statusPayment == $orderStatus)
$function->setOrderPayment($id_order);
}
}
}
}
HesabixLogService::log(array($orderStatus));
$values = get_option('hesabix_invoice_return_status');
if (is_array($values) || is_object($values)) {
foreach ($values as $status) {
if ($status == $orderStatus)
$function->setOrder($id_order, 2, $function->getInvoiceCodeByOrderId($id_order), $orderItems);
}
}
}
public function hesabix_hook_payment_confirmation($id_order, $from, $to)
{
$payment_statuses = get_option('hesabix_payment_status', array());
if (!is_array($payment_statuses)) {
if (is_string($payment_statuses) && !empty($payment_statuses)) {
$payment_statuses = array_map('trim', explode(',', $payment_statuses));
} else {
$payment_statuses = array();
}
}
foreach ($payment_statuses as $status) {
if ($status == $to) {
$function = new Hesabix_Admin_Functions();
$function->setOrderPayment($id_order);
}
}
}
private $call_time = 1;
public function hesabix_hook_new_product($id_product)
{
if ($this->call_time === 1) {
$this->call_time++;
return;
} else {
$this->call_time = 1;
}
if (get_option("hesabix_do_not_submit_product_automatically", "no") === "yes")
return;
$function = new Hesabix_Admin_Functions();
$function->setItems(array($id_product));
}
public function hesabix_hook_save_product_variation($id_attribute)
{
HesabixLogService::writeLogStr("hesabix_hook_save_product_variation");
if (get_option("hesabix_do_not_submit_product_automatically", "no") === "yes" || get_option("hesabix_do_not_submit_product_automatically", "no") == "1") {
$variable_field_id = "hesabix_hesabix_item_code_" . $id_attribute;
$code = $_POST[$variable_field_id];
$id_product = $_POST['product_id'];
if ($code === "")
return;
if (isset($code)) {
global $wpdb;
$row = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_hesabix` = " . $code . " AND `obj_type` = 'product'");
if (is_object($row)) {
if ($row->id_ps == $id_product && $row->id_ps_attribute == $id_attribute) {
return false;
}
echo '
' . __('The new Item code already used for another Item', 'hesabix') . '
';
HesabixLogService::log(array("The new Item code already used for another Item. Product ID: $id_product"));
} else {
$row2 = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_ps` = $id_product AND `obj_type` = 'product' AND `id_ps_attribute` = $id_attribute");
if (is_object($row2)) {
$wpdb->update($wpdb->prefix . 'hesabix', array(
'id_hesabix' => (int) $code,
), array(
'id_ps' => $id_product,
'id_ps_attribute' => $id_attribute,
'obj_type' => 'product',
));
} else if ((int) $code !== 0) {
$wpdb->insert($wpdb->prefix . 'hesabix', array(
'id_hesabix' => (int) $code,
'id_ps' => (int) $id_product,
'id_ps_attribute' => $id_attribute,
'obj_type' => 'product',
));
}
}
}
$func = new Hesabix_Admin_Functions();
$wpFaService = new HesabixWpFaService();
$code = $wpFaService->getProductCodeByWpId($id_product, $id_attribute);
if ($code == null) {
$func->setItems(array($id_product));
}
}
}
public function hesabix_hook_delete_product($id_product)
{
HesabixLogService::writeLogStr("Product Delete Hook");
$func = new Hesabix_Admin_Functions();
$wpFaService = new HesabixWpFaService();
$hesabixApi = new Hesabix_Api();
global $wpdb;
$variations = $func->getProductVariations($id_product);
if ($variations != false) {
foreach ($variations as $variation) {
$id_attribute = $variation->get_id();
$code = $wpFaService->getProductCodeByWpId($id_product, $id_attribute);
if ($code != false) {
$hesabixApi->itemDelete($code);
$wpdb->delete($wpdb->prefix . 'hesabix', array('id_hesabix' => $code, 'obj_type' => 'product'));
HesabixLogService::log(array("Product variation deleted. Product ID: $id_product-$id_attribute"));
}
}
}
$code = $wpFaService->getProductCodeByWpId($id_product);
if ($code != false) {
$hesabixApi->itemDelete($code);
$wpdb->delete($wpdb->prefix . 'hesabix', array('id_hesabix' => $code, 'obj_type' => 'product'));
HesabixLogService::log(array("Product deleted. Product ID: $id_product"));
}
}
public function hesabix_hook_delete_product_variation($id_attribute)
{
$hesabixApi = new Hesabix_Api();
global $wpdb;
$row = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_ps_attribute` = $id_attribute AND `obj_type` = 'product'");
if (is_object($row)) {
$hesabixApi->itemDelete($row->id_hesabix);
$wpdb->delete($wpdb->prefix . 'hesabix', array('id' => $row->id));
HesabixLogService::log(array("Product variation deleted. Product ID: $row->id_ps-$id_attribute"));
}
}
public function hesabix_hook_product_options_general_product_data()
{
$wpFaService = new HesabixWpFaService();
$value = isset($_GET['post']) ? $wpFaService->getProductCodeByWpId($_GET['post']) : '';
$args = array(
'id' => 'hesabix_hesabix_item_code_0',
'label' => __('Hesabix base item code', 'hesabix'),
'desc_tip' => true,
'description' => __('The base Item code of this product in Hesabix, if you want to map this product to another item in Hesabix, enter the new Item code.', 'hesabix'),
'value' => $value,
'type' => 'number',
);
woocommerce_wp_text_input($args);
}
public function hesabix_hook_process_product_meta($post_id)
{
$itemCode = isset($_POST['hesabix_hesabix_item_code_0']) ? $_POST['hesabix_hesabix_item_code_0'] : '';
if ($itemCode === "")
return;
if (isset($itemCode)) {
global $wpdb;
$row = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_hesabix` = " . $itemCode . " AND `obj_type` = 'product'");
if (is_object($row)) {
echo '
' . __('The new Item code already used for another Item', 'hesabix') . '
';
HesabixLogService::log(array("The new Item code already used for another Item. Product ID: $post_id"));
} else {
$row2 = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "hesabix` WHERE `id_ps` = $post_id AND `obj_type` = 'product' AND `id_ps_attribute` = 0");
if (is_object($row2)) {
$wpdb->update($wpdb->prefix . 'hesabix', array(
'id_hesabix' => (int) $itemCode,
), array(
'id_ps' => $post_id,
'id_ps_attribute' => 0,
'obj_type' => 'product',
));
} else if ((int) $itemCode !== 0) {
$wpdb->insert($wpdb->prefix . 'hesabix', array(
'id_hesabix' => (int) $itemCode,
'id_ps' => (int) $post_id,
'id_ps_attribute' => 0,
'obj_type' => 'product',
));
}
}
}
}
public function hesabix_hook_product_after_variable_attributes($loop, $variation_data, $variation)
{
$wpFaService = new HesabixWpFaService();
$value = isset($_POST['product_id']) ? $wpFaService->getProductCodeByWpId($_POST['product_id'], $variation->ID) : '';
$args = array(
'id' => 'hesabix_hesabix_item_code_' . $variation->ID,
'label' => __('Hesabix variable item code', 'hesabix'),
'desc_tip' => true,
'description' => __('The variable Item code of this product variable in Hesabix, if you want to map this product to another item in Hesabix, enter the new Item code.', 'hesabix'),
'value' => $value,
);
woocommerce_wp_text_input($args);
}
public function adminCleanLogFileCallback()
{
if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
$func = new Hesabix_Admin_Functions();
$result = $func->cleanLogFile();
if ($result) {
$redirect_url = admin_url('admin.php?page=hesabix-option&tab=log&cleanLogResult=true');
} else {
$redirect_url = admin_url('admin.php?page=hesabix-option&tab=log&cleanLogResult=false');
}
echo $redirect_url;
die();
}
}
function add_hesabix_product_data_tab($product_data_tabs)
{
$product_data_tabs['hesabix'] = array(
'label' => __('Hesabix', 'hesabix'),
'target' => 'panel_product_data_hesabix',
);
return $product_data_tabs;
}
function add_hesabix_product_data_fields()
{
global $woocommerce, $post, $product;
$funcs = new Hesabix_Admin_Functions();
$items = array();
$id_product = $post->ID;
$product = wc_get_product($id_product);
if ($product->get_status() === "auto-draft") {
?>
هنوز محصول ذخیره نشده است.
پس از ذخیره محصول، در این قسمت می توانید ارتباط محصول و متغیرهای آن با حسابیکس
را مدیریت کنید.