This commit is contained in:
Hesabix 2024-01-13 09:11:16 +00:00
parent 18e8d7a99e
commit ebdd691308
6 changed files with 16 additions and 246 deletions

View file

@ -662,89 +662,20 @@ class Ssbhesabix_Admin_Functions
} }
} }
//======================================================================================================================== //========================================================================================================================
public function exportProducts($batch, $totalBatch, $total, $updateCount) public function exportProducts()
{ {
HesabixLogService::writeLogStr("Exporting Products"); HesabixLogService::writeLogStr("Exporting Products");
try { try {
$wpFaService = new HesabixWpFaService();
$extraSettingRPP = get_option("ssbhesabix_set_rpp_for_export_products");
$rpp=500;
if($extraSettingRPP) {
if($extraSettingRPP != '-1' && $extraSettingRPP != '0') {
$rpp=$extraSettingRPP;
}
}
$result = array(); $result = array();
$result["error"] = false; $result["error"] = false;
global $wpdb; global $wpdb;
if ($batch == 1) { $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "posts` WHERE post_type = 'product' AND post_status IN('publish','private')");
$total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "posts` $products = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "posts` WHERE post_type = 'product' AND post_status IN('publish','private')");
WHERE post_type = 'product' AND post_status IN('publish','private')");
$totalBatch = ceil($total / $rpp);
}
$offset = ($batch - 1) * $rpp; $hesabix = new Ssbhesabix_Api();
$products = $wpdb->get_results("SELECT ID FROM `" . $wpdb->prefix . "posts` $response = $hesabix->settingExportProdects(array('data'=>$products));
WHERE post_type = 'product' AND post_status IN('publish','private') ORDER BY 'ID' ASC LIMIT $offset,$rpp"); $result["updateCount"] = $total;
$items = array();
foreach ($products as $item) {
$id_product = $item->ID;
$product = new WC_Product($id_product);
$id_obj = $wpFaService->getWpFaId('product', $id_product, 0);
if (!$id_obj) {
$hesabixItem = ssbhesabixItemService::mapProduct($product, $id_product);
array_push($items, $hesabixItem);
$updateCount++;
}
$variations = $this->getProductVariations($id_product);
if ($variations) {
foreach ($variations as $variation) {
$id_attribute = $variation->get_id();
$id_obj = $wpFaService->getWpFaId('product', $id_product, $id_attribute);
if (!$id_obj) {
$hesabixItem = ssbhesabixItemService::mapProductVariation($product, $variation, $id_product);
array_push($items, $hesabixItem);
$updateCount++;
}
}
}
}
if (!empty($items)) {
$count = 0;
$hesabix = new Ssbhesabix_Api();
$response = $hesabix->itemBatchSave($items);
if ($response->Success) {
foreach ($response->Result as $item) {
$json = json_decode($item->Tag);
global $wpdb;
$wpdb->insert($wpdb->prefix . 'ssbhesabix', array(
'id_hesabix' => (int)$item->Code,
'obj_type' => 'product',
'id_ps' => (int)$json->id_product,
'id_ps_attribute' => (int)$json->id_attribute,
));
HesabixLogService::log(array("Item successfully added. Item Code: " . (string)$item->Code . ". Product ID: $json->id_product - $json->id_attribute"));
}
$count += count($response->Result);
} else {
HesabixLogService::log(array("Cannot add bulk item. Error Message: " . (string)$response->ErrorMessage . ". Error Code: " . (string)$response->ErrorCode . "."));
}
sleep(2);
}
$result["batch"] = $batch;
$result["totalBatch"] = $totalBatch;
$result["total"] = $total;
$result["updateCount"] = $updateCount;
return $result; return $result;
} catch(Error $error) { } catch(Error $error) {
HesabixLogService::writeLogStr("Error in export products: " . $error->getMessage()); HesabixLogService::writeLogStr("Error in export products: " . $error->getMessage());

View file

@ -86,94 +86,6 @@ class Ssbhesabix_Setting {
</li> </li>
</ul> </ul>
</div> </div>
<div class="alert alert-warning hesabix-f mt-4">
<strong style="font-size: 1rem;">نکات</strong>
<br>
<ul class="mt-2">
<li> *
پیشنهاد می شود قبل از شروع کار با افزونه، حتما ویدیو خودآموز افزونه را مشاهده نمایید.
</li>
</ul>
</div>
<!--////////////////////////video timing in the first page of the plugin////////////////////////////////////////////-->
<div class="row" style="margin-left: 10px;">
<div class="col">
<h4 class="h4 hesabix-tab-page-title mt-4"><?php esc_attr_e( 'Plugin Tutorial Video', 'ssbhesabix' ); ?></h4>
<video controls poster="https://hesabix.ir/img/woocommerc-plugin-help-cover.jpg"
id="hesabix-tutorial-video" style="border: 1px solid gray" class="mt-3">
<source src="https://hesabix.ir/file/woocommerce/woocommerce-plugin-tutorial.mp4"
type="video/mp4"></source>
</video>
</div>
<div class="col-3">
<h4 class="h4 hesabix-tab-page-title mt-4 mb-3"><?php esc_attr_e( 'Titles', 'ssbhesabix' ); ?></h4>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(0)">
نصب افزونه
<br><strong class="text-info">00:00</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(75)">
اتصال افزونه به حسابیکس
<br><strong class="text-info">01:15</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(246)">
تنظیمات افزونه
<br><strong class="text-info">04:06</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(520)">
تعریف محصول و لینک کردن محصول به حسابیکس
<br><strong class="text-info">08:40</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1378)">
خروجی محصولات به حسابیکس
<br><strong class="text-info">22:58</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1462)">
خروجی موجودی اول دوره محصولات به حسابیکس
<br><strong class="text-info">24:22</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1495)">
خروجی مشتریان
<br><strong class="text-info">24:55</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1525)">
ورود محصولات از حسابیکس به فروشگاه
<br><strong class="text-info">25:25</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1592)">
همسان سازی قیمت و موجودی محصولات
<br><strong class="text-info">26:32</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1645)">
همسان سازی سفارشات
<br><strong class="text-info">27:25</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1758)">
بروزرسانی محصولات در حسابیکس بر اساس فروشگاه
<br><strong class="text-info">29:18</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(1805)">
سفارشات و ثبت فاکتور در حسابیکس
<br><strong class="text-info">30:05</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(2120)">
پشتیبان گیری از جدول افزونه در دیتابیس
<br><strong class="text-info">35:20</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(2502)">
لاگ رویدادها و خطاها
<br><strong class="text-info">41:42</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(3046)">
حذف محصولات
<br><strong class="text-info">50:46</strong>
</div>
<div class="hesabix-plugin-tutorial-chapter" onclick="hesabixTutorialJumpTo(3143)">
محصول پیش نویس
<br><strong class="text-info">52:23</strong>
</div>
</div>
</div>
<?php <?php
} }
@ -1107,10 +1019,6 @@ class Ssbhesabix_Setting {
<label class="fw-bold mb-2">نکات مهم:</label> <label class="fw-bold mb-2">نکات مهم:</label>
<ul> <ul>
<li>با انجام این عملیات محصولات لینک نشده از فروشگاه وارد حسابیکس می شوند.</li> <li>با انجام این عملیات محصولات لینک نشده از فروشگاه وارد حسابیکس می شوند.</li>
<li>اگر محصولات از قبل هم در فروشگاه تعریف شده اند و هم در حسابیکس و به هم لینک نشده اند باید از
گزینه
همسان سازی دستی محصولات استفاده کنید.
</li>
<li>با انجام این عملیات موجودی محصولات وارد حسابیکس نمی شود و برای وارد کردن موجودی محصولات <li>با انجام این عملیات موجودی محصولات وارد حسابیکس نمی شود و برای وارد کردن موجودی محصولات
فروشگاه فروشگاه
در حسابیکس، باید از گزینه استخراج موجودی اول دوره استفاده کنید. در حسابیکس، باید از گزینه استخراج موجودی اول دوره استفاده کنید.
@ -1475,24 +1383,13 @@ class Ssbhesabix_Setting {
//============================================================================================= //=============================================================================================
public static function getSubscriptionInfo() { public static function getSubscriptionInfo() {
$businessName = ''; $businessName = '';
$credit = '';
$expireDate = '';
$plan = '';
$hesabix = new Ssbhesabix_Api(); $hesabix = new Ssbhesabix_Api();
$response = $hesabix->settingGetSubscriptionInfo(); $response = $hesabix->settingGetSubscriptionInfo();
if ( $response->Success ) { if ( $response->Success ) {
$businessName = $response->Result->Name; $businessName = $response->Result->name;
$credit = $response->Result->Credit;
$expireDate = $response->Result->ExpireDate;
$plan = $response->Result->Subscription;
} }
return array( return array(
"businessName" => $businessName, "businessName" => $businessName,
"credit" => $credit,
"expireDate" => $expireDate,
"plan" => $plan
); );
} }
//============================================================================================= //=============================================================================================

View file

@ -1,64 +0,0 @@
<?php
class HesabixLogService
{
public static function writeLogStr($str)
{
$fileName = WP_CONTENT_DIR . '/ssbhesabix-' . date("20y-m-d") . '.txt';
$dateTime = new DateTimeImmutable( 'now', wp_timezone() );
$date = $dateTime->format('[Y-m-d H:i:s] ');
$str = $date . $str;
$str = mb_convert_encoding($str, 'UTF-8');
file_put_contents($fileName, PHP_EOL . $str, FILE_APPEND);
}
public static function writeLogObj($obj)
{
$fileName = WP_CONTENT_DIR . '/ssbhesabix-' . date("20y-m-d") . '.txt';
ob_start();
var_dump($obj);
file_put_contents($fileName, PHP_EOL . ob_get_flush(), FILE_APPEND);
}
public static function log($params)
{
$fileName = WP_CONTENT_DIR . '/ssbhesabix-' . date("20y-m-d") . '.txt';
$log = '';
$dateTime = new DateTimeImmutable( 'now', wp_timezone() );
$date = $dateTime->format('[Y-m-d H:i:s] ');
foreach ($params as $message) {
if (is_array($message) || is_object($message)) {
$log .= $date . print_r($message, true) . "\n";
} elseif (is_bool($message)) {
$log .= $date . ($message ? 'true' : 'false') . "\n";
} else {
$log .= $date . $message . "\n";
}
}
$log = mb_convert_encoding($log, 'UTF-8');
file_put_contents($fileName, PHP_EOL . $log, FILE_APPEND);
}
public static function readLog($URL)
{
return file_exists($URL) ? file_get_contents($URL) : '';
}
public static function clearLog()
{
$fileName = WP_CONTENT_DIR . '/ssbhesabix-' . date("20y-m-d") . '.txt';
if (file_exists($fileName)) {
file_put_contents($fileName, "");
}
}
public static function getLogFilePath()
{
return WP_CONTENT_DIR . '/ssbhesabix-' . date("20y-m-d") . '.txt';
}
}

View file

@ -434,8 +434,14 @@ class Ssbhesabix_Api
//================================================================================================ //================================================================================================
public function settingGetSubscriptionInfo() public function settingGetSubscriptionInfo()
{ {
$method = 'setting/getBusinessInfo'; $method = 'hooks/setting/getBusinessInfo';
return $this->apiRequest($method); return $this->apiRequest($method);
} }
//================================================================================================ //================================================================================================
//================================================================================================
public function settingExportProdects($data)
{
$method = 'hooks/commodity/import';
return $this->apiRequest($method,$data);
}
} }

View file

@ -26,7 +26,7 @@ class Ssbhesabix_i18n {
load_plugin_textdomain( load_plugin_textdomain(
'ssbhesabix', 'ssbhesabix',
false, false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages1/' dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
); );
} }

View file

@ -64,7 +64,7 @@ class Ssbhesabix
if (defined('SSBHESABIX_VERSION')) { if (defined('SSBHESABIX_VERSION')) {
$this->version = SSBHESABIX_VERSION; $this->version = SSBHESABIX_VERSION;
} else { } else {
$this->version = '2.0.93'; $this->version = '0.1.1';
} }
$this->plugin_name = 'ssbhesabix'; $this->plugin_name = 'ssbhesabix';