2024-11-03 14:45:40 +03:30
|
|
|
<?php
|
2025-08-05 17:24:52 +03:30
|
|
|
/**
|
|
|
|
* Hesabix WpFa Service
|
|
|
|
*
|
|
|
|
* @package Hesabix
|
|
|
|
* @author Mohammad Rezai
|
|
|
|
* @author URI https://pirouz.xyz
|
|
|
|
* @since 1.0.0
|
2025-08-09 14:49:29 +03:30
|
|
|
*
|
2025-08-05 17:24:52 +03:30
|
|
|
*/
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
include_once('hesabixLogService.php');
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
class WpFa
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
public $objType;
|
|
|
|
public $idHesabix;
|
|
|
|
public $idWp;
|
|
|
|
public $idWpAttribute;
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
public $uidHesabix;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newWpFa($id, $type, $idHesabix, $idWp, $idWpAttribute, $uidHesabix): WpFa
|
2024-11-03 14:45:40 +03:30
|
|
|
{
|
|
|
|
$instance = new self();
|
|
|
|
$instance->id = $id;
|
|
|
|
$instance->objType = $type;
|
|
|
|
$instance->idHesabix = $idHesabix;
|
|
|
|
$instance->idWp = $idWp;
|
|
|
|
$instance->idWpAttribute = $idWpAttribute;
|
2025-08-05 17:24:52 +03:30
|
|
|
$instance->uidHesabix = $uidHesabix;
|
2024-11-03 14:45:40 +03:30
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class HesabixWpFaService
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
public function getWpFaByWpId($objType, $idWp, $idWpAttribute = 0)
|
2024-11-03 14:45:40 +03:30
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
if (!isset($objType) || !isset($idWp))
|
|
|
|
return false;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$row = $wpdb->get_row(
|
|
|
|
$wpdb->prepare(
|
|
|
|
"SELECT *
|
2025-08-05 17:24:52 +03:30
|
|
|
FROM {$wpdb->prefix}hesabix
|
2024-11-03 14:45:40 +03:30
|
|
|
WHERE `id_ps` = %d
|
|
|
|
AND `id_ps_attribute` = %d
|
|
|
|
AND `obj_type` = %s",
|
|
|
|
$idWp,
|
|
|
|
$idWpAttribute,
|
|
|
|
$objType
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
if (isset($row))
|
|
|
|
return $this->mapWpFa($row);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWpFaByHesabixCode($objType, $codehx, $idWpAttribute = 0)
|
|
|
|
{
|
|
|
|
if (!isset($objType) || !isset($codehx))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$row = $wpdb->get_row(
|
|
|
|
$wpdb->prepare(
|
|
|
|
"SELECT *
|
|
|
|
FROM {$wpdb->prefix}hesabix
|
|
|
|
WHERE `id_hesabix` = %d
|
|
|
|
AND `id_ps_attribute` = %d
|
|
|
|
AND `obj_type` = %s",
|
|
|
|
$codehx,
|
|
|
|
$idWpAttribute,
|
|
|
|
$objType
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($row))
|
|
|
|
return $this->mapWpFa($row);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getWpFaSearch($woocommerce_search_code = '', $woocommerce_attribute_search_code = '', $hesabix_search_code = '', $obj_type_search = '')
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$conditions = [];
|
|
|
|
$params = [];
|
|
|
|
|
|
|
|
if ($woocommerce_search_code !== '') {
|
|
|
|
$conditions[] = "id_ps = %s";
|
|
|
|
$params[] = $woocommerce_search_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($woocommerce_attribute_search_code !== '' || $woocommerce_attribute_search_code === '0') {
|
|
|
|
$conditions[] = "id_ps_attribute = %s";
|
|
|
|
$params[] = $woocommerce_attribute_search_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($hesabix_search_code !== '') {
|
|
|
|
$conditions[] = "id_hesabix = %s";
|
|
|
|
$params[] = $hesabix_search_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($obj_type_search !== '' && $obj_type_search != '0') {
|
|
|
|
$conditions[] = "obj_type = %s";
|
|
|
|
$params[] = $obj_type_search;
|
|
|
|
}
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
$sql = "SELECT * FROM {$wpdb->prefix}hesabix";
|
2024-11-03 14:45:40 +03:30
|
|
|
if (!empty($conditions)) {
|
|
|
|
$sql .= " WHERE " . implode(" AND ", $conditions);
|
|
|
|
}
|
|
|
|
|
|
|
|
$prepared_sql = $wpdb->prepare($sql, ...$params);
|
|
|
|
$result = $wpdb->get_results($prepared_sql);
|
|
|
|
|
|
|
|
$wpFaObjects = array();
|
|
|
|
if (isset($result) && is_array($result) && count($result) > 0) {
|
|
|
|
foreach ($result as $item) {
|
|
|
|
$wpFaObjects[] = $this->mapWpFa($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wpFaObjects;
|
|
|
|
}
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getWpFaByHesabixId($objType, $hesabixId)
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
if (!isset($objType) || !isset($hesabixId))
|
|
|
|
return false;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$row = $wpdb->get_row(
|
|
|
|
$wpdb->prepare(
|
|
|
|
"SELECT *
|
2025-08-05 17:24:52 +03:30
|
|
|
FROM {$wpdb->prefix}hesabix
|
2024-11-03 14:45:40 +03:30
|
|
|
WHERE `id_hesabix` = %d
|
|
|
|
AND `obj_type` = %s",
|
|
|
|
$hesabixId,
|
|
|
|
$objType
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($row))
|
|
|
|
return $this->mapWpFa($row);
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getWpFaId($objType, $idWp, $idWpAttribute = 0)
|
|
|
|
{
|
|
|
|
if (!isset($objType) || !isset($idWp))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$row = $wpdb->get_row(
|
|
|
|
$wpdb->prepare(
|
|
|
|
"SELECT `id`
|
2025-08-05 17:24:52 +03:30
|
|
|
FROM {$wpdb->prefix}hesabix
|
2024-11-03 14:45:40 +03:30
|
|
|
WHERE `id_ps` = %d
|
|
|
|
AND `id_ps_attribute` = %d
|
|
|
|
AND `obj_type` = %s",
|
|
|
|
$idWp,
|
|
|
|
$idWpAttribute,
|
|
|
|
$objType
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (is_object($row))
|
2025-08-05 17:24:52 +03:30
|
|
|
return (int) $row->id;
|
2024-11-03 14:45:40 +03:30
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getWpFaIdByHesabixId($objType, $hesabixId)
|
|
|
|
{
|
|
|
|
if (!isset($objType) || !isset($hesabixId))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$row = $wpdb->get_row(
|
|
|
|
$wpdb->prepare(
|
|
|
|
"SELECT `id`
|
2025-08-05 17:24:52 +03:30
|
|
|
FROM {$wpdb->prefix}hesabix
|
2024-11-03 14:45:40 +03:30
|
|
|
WHERE `id_hesabix` = %d
|
|
|
|
AND `obj_type` = %s",
|
|
|
|
$hesabixId,
|
|
|
|
$objType
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($row))
|
2025-08-05 17:24:52 +03:30
|
|
|
return (int) $row->id;
|
2024-11-03 14:45:40 +03:30
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getProductCodeByWpId($id_product, $id_attribute = 0)
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
$obj = $this->getWpFaByWpId('product', $id_product, $id_attribute);
|
|
|
|
|
|
|
|
if ($obj != null)
|
|
|
|
return $obj->idHesabix;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProductUidByWpId($id_product, $id_attribute = 0)
|
|
|
|
{
|
|
|
|
$obj = $this->getWpFaByWpId('product', $id_product, $id_attribute);
|
|
|
|
|
|
|
|
if ($obj != null)
|
|
|
|
return $obj->uidHesabix;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProductUidByCode($code)
|
|
|
|
{
|
|
|
|
$obj = $this->getWpFaByHesabixCode('product', $code);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
if ($obj != null)
|
|
|
|
return $obj->uidHesabix;
|
|
|
|
|
|
|
|
$api = new Hesabix_Api();
|
|
|
|
$response = $api->apiRequest('api/commodity/info/' . $code);
|
|
|
|
if ($response->code == $code) {
|
|
|
|
return $response->id;
|
|
|
|
}
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getCustomerCodeByWpId($id_customer)
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
$obj = $this->getWpFaByWpId('customer', $id_customer);
|
|
|
|
|
|
|
|
if ($obj != null)
|
|
|
|
return $obj->idHesabix;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomerUidByWpId($id_customer)
|
|
|
|
{
|
|
|
|
$obj = $this->getWpFaByWpId('customer', $id_customer);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
if ($obj != null)
|
|
|
|
return $obj->uidHesabix;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
|
|
|
public function getCustomerUidByCode($code_customer)
|
|
|
|
{
|
|
|
|
$obj = $this->getWpFaByHesabixCode('customer', $code_customer);
|
|
|
|
|
|
|
|
if ($obj != null)
|
|
|
|
return $obj->uidHesabix;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getInvoiceCodeByWpId($id_order)
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
$obj = $this->getWpFaByWpId('order', $id_order);
|
|
|
|
|
|
|
|
if ($obj != null)
|
|
|
|
return $obj->idHesabix;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInvoiceUidByWpId($id_order)
|
|
|
|
{
|
|
|
|
$obj = $this->getWpFaByWpId('order', $id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
if ($obj != null)
|
|
|
|
return $obj->uidHesabix;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function getProductAndCombinations($idWp)
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$sql = $wpdb->prepare(
|
|
|
|
"SELECT *
|
2025-08-05 17:24:52 +03:30
|
|
|
FROM {$wpdb->prefix}hesabix
|
2024-11-03 14:45:40 +03:30
|
|
|
WHERE `obj_type` = 'product'
|
|
|
|
AND `id_ps` = %d",
|
|
|
|
$idWp
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $wpdb->get_results($sql);
|
|
|
|
|
|
|
|
|
|
|
|
$wpFaObjects = array();
|
|
|
|
if (isset($result) && is_array($result) && count($result) > 0) {
|
|
|
|
foreach ($result as $item)
|
|
|
|
$wpFaObjects[] = $this->mapWpFa($item);
|
|
|
|
return $wpFaObjects;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function mapWpFa($sqlObj): WpFa
|
|
|
|
{
|
|
|
|
$wpFa = new WpFa();
|
|
|
|
|
|
|
|
$wpFa->id = $sqlObj->id;
|
|
|
|
$wpFa->idHesabix = $sqlObj->id_hesabix;
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpFa->uidHesabix = $sqlObj->uid_hesabix;
|
2024-11-03 14:45:40 +03:30
|
|
|
$wpFa->idWp = $sqlObj->id_ps;
|
|
|
|
$wpFa->idWpAttribute = $sqlObj->id_ps_attribute;
|
|
|
|
$wpFa->objType = $sqlObj->obj_type;
|
|
|
|
|
|
|
|
return $wpFa;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function saveProduct($item): bool
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
$hesabix_code = 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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
$wpFaService = new HesabixWpFaService();
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpFa = $wpFaService->getWpFaByHesabixId('product', $hesabix_code);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
if (!$wpFa) {
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpFa = WpFa::newWpFa(0, 'product', $hesabix_code, $id_product, $id_attribute, $hesabix_uid);
|
2024-11-03 14:45:40 +03:30
|
|
|
$wpFaService->save($wpFa);
|
2025-08-05 17:24:52 +03:30
|
|
|
HesabixLogService::log(array("Item successfully added. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
|
2024-11-03 14:45:40 +03:30
|
|
|
} else {
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpFa->idHesabix = $hesabix_code;
|
|
|
|
$wpFa->uidHesabix = $hesabix_uid;
|
2024-11-03 14:45:40 +03:30
|
|
|
$wpFaService->update($wpFa);
|
2025-08-05 17:24:52 +03:30
|
|
|
HesabixLogService::log(array("Item successfully updated. Item code: $hesabix_code. Product ID: $id_product-$id_attribute"));
|
2024-11-03 14:45:40 +03:30
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function saveCustomer($customer): bool
|
|
|
|
{
|
2025-08-05 17:24:52 +03:30
|
|
|
$json = json_decode($customer->tags);
|
|
|
|
if ((int) $json->id_customer == 0)
|
|
|
|
return true;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
$id = $this->getWpFaId('customer', (int) $json->id_customer);
|
2024-11-03 14:45:40 +03:30
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
if (!$id) {
|
|
|
|
$wpdb->insert(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array(
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_hesabix' => (int) $customer->code,
|
|
|
|
'uid_hesabix' => (int) $customer->id,
|
2024-11-03 14:45:40 +03:30
|
|
|
'obj_type' => 'customer',
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_ps' => (int) $json->id_customer
|
2024-11-03 14:45:40 +03:30
|
|
|
),
|
|
|
|
array(
|
2025-08-05 17:24:52 +03:30
|
|
|
'%d',
|
2024-11-03 14:45:40 +03:30
|
|
|
'%d',
|
|
|
|
'%s',
|
|
|
|
'%d'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
HesabixLogService::writeLogStr("Customer successfully added. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
|
2024-11-03 14:45:40 +03:30
|
|
|
} else {
|
|
|
|
$wpdb->update(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array(
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_hesabix' => (int) $customer->code,
|
|
|
|
'uid_hesabix' => (int) $customer->id,
|
2024-11-03 14:45:40 +03:30
|
|
|
'obj_type' => 'customer',
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_ps' => (int) $json->id_customer,
|
2024-11-03 14:45:40 +03:30
|
|
|
),
|
|
|
|
array('id' => $id),
|
|
|
|
array(
|
2025-08-05 17:24:52 +03:30
|
|
|
'%d',
|
2024-11-03 14:45:40 +03:30
|
|
|
'%d',
|
|
|
|
'%s',
|
|
|
|
'%d'
|
|
|
|
),
|
|
|
|
array('%d')
|
|
|
|
);
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
HesabixLogService::writeLogStr("Customer successfully updated. Customer code: " . (string) $customer->code . ". Customer ID: $json->id_customer");
|
2024-11-03 14:45:40 +03:30
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function saveInvoice($invoice, $orderType)
|
|
|
|
{
|
|
|
|
$json = json_decode($invoice->Tag);
|
2025-08-05 17:24:52 +03:30
|
|
|
$id = $this->getPsFaId('order', (int) $json->id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
$invoiceNumber = (int) $invoice->Number;
|
2024-11-03 14:45:40 +03:30
|
|
|
$objType = $orderType == 0 ? 'order' : 'returnOrder';
|
|
|
|
|
|
|
|
if (!$id) {
|
|
|
|
Db::getInstance()->insert('ps_hesabix', array(
|
|
|
|
'id_hesabix' => $invoiceNumber,
|
|
|
|
'obj_type' => $objType,
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_ps' => (int) $json->id_order,
|
2024-11-03 14:45:40 +03:30
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
if ($objType == 'order')
|
2025-08-05 17:24:52 +03:30
|
|
|
LogService::writeLogStr("Invoice successfully added. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
else
|
2025-08-05 17:24:52 +03:30
|
|
|
LogService::writeLogStr("Return Invoice successfully added. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
} else {
|
|
|
|
Db::getInstance()->update('ps_hesabix', array(
|
|
|
|
'id_hesabix' => $invoiceNumber,
|
|
|
|
'obj_type' => $objType,
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_ps' => (int) $json->id_order,
|
2024-11-03 14:45:40 +03:30
|
|
|
), array('id' => $id), 0, true, true);
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
if ($objType == 'order')
|
2025-08-05 17:24:52 +03:30
|
|
|
LogService::writeLogStr("Invoice successfully updated. invoice number: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
else
|
2025-08-05 17:24:52 +03:30
|
|
|
LogService::writeLogStr("Return Invoice successfully updated. Customer code: " . (string) $invoice->Number . ", order id: " . $json->id_order);
|
2024-11-03 14:45:40 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function save(WpFa $wpFa)
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->insert(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array(
|
|
|
|
'id_hesabix' => $wpFa->idHesabix,
|
|
|
|
'obj_type' => $wpFa->objType,
|
2025-08-05 17:24:52 +03:30
|
|
|
'id_ps' => (int) $wpFa->idWp,
|
|
|
|
'id_ps_attribute' => (int) $wpFa->idWpAttribute,
|
|
|
|
'uid_hesabix' => (int) $wpFa->uidHesabix,
|
2024-11-03 14:45:40 +03:30
|
|
|
),
|
|
|
|
array(
|
|
|
|
'%s',
|
|
|
|
'%s',
|
|
|
|
'%d',
|
2025-08-05 17:24:52 +03:30
|
|
|
'%d',
|
|
|
|
'%s'
|
2024-11-03 14:45:40 +03:30
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
public function update(WpFa $wpFa)
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$idHesabix = isset($wpFa->idHesabix) ? sanitize_text_field($wpFa->idHesabix) : '';
|
2025-08-05 17:24:52 +03:30
|
|
|
$uidHesabix = isset($wpFa->uidHesabix) ? sanitize_text_field($wpFa->uidHesabix) : '';
|
2024-11-03 14:45:40 +03:30
|
|
|
$objType = isset($wpFa->objType) ? sanitize_text_field($wpFa->objType) : '';
|
2025-08-05 17:24:52 +03:30
|
|
|
$idWp = isset($wpFa->idWp) ? (int) $wpFa->idWp : 0;
|
|
|
|
$idWpAttribute = isset($wpFa->idWpAttribute) ? (int) $wpFa->idWpAttribute : 0;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
$wpdb->update(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array(
|
|
|
|
'id_hesabix' => $idHesabix,
|
|
|
|
'obj_type' => $objType,
|
|
|
|
'id_ps' => $idWp,
|
|
|
|
'id_ps_attribute' => $idWpAttribute,
|
2025-08-05 17:24:52 +03:30
|
|
|
'uid_hesabix' => $uidHesabix,
|
2024-11-03 14:45:40 +03:30
|
|
|
),
|
|
|
|
array('id' => $wpFa->id),
|
|
|
|
array(
|
|
|
|
'%s',
|
|
|
|
'%s',
|
|
|
|
'%d',
|
2025-08-05 17:24:52 +03:30
|
|
|
'%d',
|
|
|
|
'%s'
|
2024-11-03 14:45:40 +03:30
|
|
|
),
|
|
|
|
array('%d')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function delete(WpFa $wpFa)
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
$id = isset($wpFa->id) ? (int) $wpFa->id : 0;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
$wpdb->delete(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array('id' => $id),
|
|
|
|
array('%d')
|
|
|
|
);
|
|
|
|
}
|
2025-08-05 17:24:52 +03:30
|
|
|
|
2024-11-03 14:45:40 +03:30
|
|
|
public function deleteAll($productId)
|
|
|
|
{
|
|
|
|
global $wpdb;
|
|
|
|
|
2025-08-05 17:24:52 +03:30
|
|
|
$productId = isset($productId) ? (int) $productId : 0;
|
2024-11-03 14:45:40 +03:30
|
|
|
|
|
|
|
$wpdb->delete(
|
2025-08-05 17:24:52 +03:30
|
|
|
$wpdb->prefix . 'hesabix',
|
2024-11-03 14:45:40 +03:30
|
|
|
array('id_ps' => $productId),
|
|
|
|
array('%d')
|
|
|
|
);
|
|
|
|
}
|
2025-08-09 14:49:29 +03:30
|
|
|
}
|