public function updatePindoProduct() {
check_ajax_referer('pindo_nonce');
$product_id = isset($_POST['product_id']) ? intval($_POST['product_id']) : 0;
$product = wc_get_product($product_id);
if (!$product) {
wp_send_json_error(array(
'message' => 'ناموفق!',
'details' => 'محصول یافت نشد'
));
}
$pindo_id = get_post_meta($product_id, '_pindo_id', true);
if (!$pindo_id) {
wp_send_json_error(array(
'message' => 'ناموفق!',
'details' => 'کد پیندو یافت نشد'
));
}
try {
// Get Request
$ch = curl_init();
$get_url = "https://api.pindo.ir/v2/advertisement/edit/{$pindo_id}/";
curl_setopt($ch, CURLOPT_URL, $get_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$get_headers = array(
'authority: api.pindo.ir',
'accept: application/json, text/plain, */*',
'accept-encoding: gzip, deflate, br, zstd',
'accept-language: en-US,en;q=0.9,fa;q=0.8',
'cookie: _hjSessionUser_2774459=eyJpZCI6IjQ4ZTkwMTI0LTQ0YmMtNTNmNC05NTVmLTRmMDQ3NTg3ZmY1MSIsImNyZWF0ZWQiOjE3Mjg0Njc2MTAwMjgsImV4aXN0aW5nIjp0cnVlfQ==; _ga=GA1.1.473728403.1728467609; _ga_SWEYGC70YD=GS1.1.1728999884.6.0.1728999889.0.0.0; tracker_glob_new=dwZcHLp; analytics_campaign={%22source%22:%22google%22%2C%22medium%22:%22organic%22}; _clck=6ijut%7C2%7Cfrd%7C0%7C1744; _ga_WCQ0L5EFBD=GS1.1.1733123685.13.1.1733123697.48.0.0; tracker_session=3zNW39v; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTczMzkwMjI4N30.DvA7oh0wZBPY7suM89vVul_B6iIK7hkQarr4BlZKGmQ; refresh_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTc0MTU5MTg4N30.moKlgUIgGgYyww878DHC68rYgTYdVXpFdfagdaVix3Q; TS01c1e68c=01023105918b50e0f0601439303c077da431090c5c736afc3028974ca9d7361e42191ec5e3b6df9d85e9dbf5bd3fd34e38235933ea9ba43bf734bf4433d08314022221eccff0621fb8a724acd02e8c4c0322b1b494168c801df73394a8268c495c8a3e755050d9a88b69f1766437f34fb119b9235f',
'authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTczMzkwMjI4N30.DvA7oh0wZBPY7suM89vVul_B6iIK7hkQarr4BlZKGmQ',
'cache-control: no-cache',
'client: desktop',
'clientid: a4d5b2b8-b261-4569-90e0-0f0be307ca3c',
'origin: https://www.pindo.ir',
'pragma: no-cache',
'priority: u=1, i',
'referer: https://www.pindo.ir/',
'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile: ?1',
'sec-ch-ua-platform: "Android"',
'sec-fetch-dest: empty',
'sec-fetch-mode: cors',
'sec-fetch-site: same-site',
'supernova-optimize-response: 1',
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36',
'x-requested-with: XMLHttpRequest'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $get_headers);
$get_response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code !== 200) {
throw new Exception("خطا در دریافت اطلاعات از پیندو. کد خطا: " . $http_code);
}
$existing_data = json_decode($get_response, true);
error_log('GET Response: ' . print_r($existing_data, true));
if (!isset($existing_data['data']['advertisement'])) {
throw new Exception("خطا در دریافت اطلاعات آگهی");
}
$current_data = $existing_data['data']['advertisement'];
// محاسبه قیمتها
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$stock = $product->get_stock_quantity() ?? 0;
$price_percent = get_option('pindo_price_percent', 0);
$original_price = round($regular_price * (1 + ($price_percent/100)), -3);
$data = array(
'product_id' => (int)$current_data['id'],
'category_id' => $current_data['category']['id'],
'save_as_draft' => false,
'image_ids' => array(),
'video_ids' => array(null),
'title' => $current_data['title'],
'product_situation' => $current_data['product_situation']['id'],
'description' => $current_data['description'],
'original_price' => (string)$original_price,
'price' => $sale_price ? (string)round($sale_price * (1 + ($price_percent/100)), -3) : '',
'safe_payment' => true,
'bank_account' => "6104338980569806",
'safe_payment_stock' => (string)max(0, $stock),
'shipping_area' => 2,
'shipping_fee' => array('id' => 2)
);
$json_data = json_encode($data);
$content_length = strlen($json_data);
// Post Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.pindo.ir/v1/advertisement/edit/{$pindo_id}/submit/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_ENCODING, '');
$post_headers = array(
'authority: api.pindo.ir',
'accept: application/json, text/plain, */*',
'accept-encoding: gzip, deflate, br, zstd',
'accept-language: en-US,en;q=0.9,fa;q=0.8',
'authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTczMzkwMjI4N30.DvA7oh0wZBPY7suM89vVul_B6iIK7hkQarr4BlZKGmQ',
'cache-control: no-cache',
'client: desktop',
'clientid: a4d5b2b8-b261-4569-90e0-0f0be307ca3c',
'content-type: application/json',
'content-length: ' . $content_length,
'cookie: _hjSessionUser_2774459=eyJpZCI6IjQ4ZTkwMTI0LTQ0YmMtNTNmNC05NTVmLTRmMDQ3NTg3ZmY1MSIsImNyZWF0ZWQiOjE3Mjg0Njc2MTAwMjgsImV4aXN0aW5nIjp0cnVlfQ==; _ga=GA1.1.473728403.1728467609; _ga_SWEYGC70YD=GS1.1.1728999884.6.0.1728999889.0.0.0; tracker_glob_new=dwZcHLp; analytics_campaign={%22source%22:%22google%22%2C%22medium%22:%22organic%22}; _clck=6ijut%7C2%7Cfrd%7C0%7C1744; _ga_WCQ0L5EFBD=GS1.1.1733123685.13.1.1733123697.48.0.0; tracker_session=3zNW39v; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTczMzkwMjI4N30.DvA7oh0wZBPY7suM89vVul_B6iIK7hkQarr4BlZKGmQ; refresh_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1NDkzNzA0LCJleHBpcmVfdGltZSI6MTc0MTU5MTg4N30.moKlgUIgGgYyww878DHC68rYgTYdVXpFdfagdaVix3Q; TS01c1e68c=01023105918b50e0f0601439303c077da431090c5c736afc3028974ca9d7361e42191ec5e3b6df9d85e9dbf5bd3fd34e38235933ea9ba43bf734bf4433d08314022221eccff0621fb8a724acd02e8c4c0322b1b494168c801df73394a8268c495c8a3e755050d9a88b69f1766437f34fb119b9235f',
'origin: https://www.pindo.ir',
'pragma: no-cache',
'priority: u=1, i',
'referer: https://www.pindo.ir/',
'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile: ?1',
'sec-ch-ua-platform: "Android"',
'sec-fetch-dest: empty',
'sec-fetch-mode: cors',
'sec-fetch-site: same-site',
'supernova-optimize-response: 1',
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36',
'x-requested-with: XMLHttpRequest'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $post_headers);
error_log('POST Request Data: ' . print_r($data, true));
error_log('POST Headers: ' . print_r($post_headers, true));
$response = curl_exec($ch);
error_log('POST Response: ' . $response);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
error_log('POST Response Code: ' . $http_code);
curl_close($ch);
if ($http_code !== 200) {
$error_response = json_decode($response, true);
$error_message = isset($error_response['message']) ? $error_response['message'] : '';
throw new Exception($error_message ? $error_message : "خطا در ارسال اطلاعات به پیندو. کد خطا: " . $http_code);
}
$body = json_decode($response, true);
global $wpdb;
$wpdb->insert(
$wpdb->prefix . 'pindo_logs',
array(
'product_id' => $product_id,
'response' => wp_json_encode($body),
'status' => isset($body['status']) && $body['status'] == 200 ? 'success' : 'error',
'created_at' => current_time('mysql')
)
);
if (isset($body['status']) && $body['status'] == 200) {
update_post_meta($product_id, '_pindo_last_update', current_time('mysql'));
wp_send_json_success(array(
'message' => 'موفق!',
'status' => 'success',
'last_update' => jdate('Y/m/d H:i:s')
));
} else {
throw new Exception($body['message'] ?? ($body['data']['message'] ?? 'پاسخ دریافتی از پیندو نامعتبر است'));
}
} catch (Exception $e) {
error_log('خطای بهروزرسانی پیندو: ' . $e->getMessage());
wp_send_json_error(array(
'message' => 'ناموفق!',
'details' => $e->getMessage()
));
}
}
دستگاه جوش چیست؟
گاهی ممکن است شما در خانه نیاز به تعمیر اساسی داشته باشید، وجود یک دستگاه جوش قابل حمل ضروری است. در این صورت هر زمان که نیاز به تعمیر هر سازهای داشتید، میتوانید فوراً از دستگاه جوش خود استفاده کرده و آن سازه را تعمیر کنید تا طول عمر سازه افزایش یابد ، در غیر […]
امیرحسین متین فر
آذر 19, 1401