Website : phonehp.ir
backdoor
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Home
Console
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
nehpir
/
public_html
/
wp-content
/
plugins
/
woocommersa
/
includes
/
API
/
Filename :
OrdersController.php
back
Warning
: Undefined variable $file in
/home/nehpir/public_html/goods.php
on line
545
Copy
<?php namespace WooCommersa\API; if (!defined('ABSPATH')) exit; class OrdersController extends BaseController { public function __construct() { add_action('rest_api_init', [$this, 'register_routes']); } public function register_routes() { register_rest_route($this->namespace, '/orders', [ 'methods' => 'GET', 'callback' => [$this, 'get_orders'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/order-statuses', [ 'methods' => 'GET', 'callback' => [$this, 'get_statuses'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/orders/batch-update', [ 'methods' => 'POST', 'callback' => [$this, 'batch_update'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/orders/update', [ 'methods' => 'POST', 'callback' => [$this, 'update_order'], 'permission_callback' => [$this, 'permissions_check'], ]); } public function get_orders($request) { global $wpdb; $per_page = isset($request['per_page']) ? intval($request['per_page']) : 20; $page = $request['page'] ?? 1; $status = $request['status'] ?? ''; $search = sanitize_text_field($request['search'] ?? ''); $params = [ 'limit' => $per_page, 'page' => $page, 'status' => !empty($status) ? $status : 'any', 'paginate' => true, 'orderby' => 'date', 'order' => 'DESC', ]; // 1. Advanced Search Logic if (!empty($search)) { if (is_numeric($search)) { $params['post__in'] = [intval($search)]; } else { // Search by multiple fields using meta_query for best results $params['meta_query'] = [ 'relation' => 'OR', [ 'key' => '_billing_first_name', 'value' => $search, 'compare' => 'LIKE' ], [ 'key' => '_billing_last_name', 'value' => $search, 'compare' => 'LIKE' ], [ 'key' => '_billing_phone', 'value' => $search, 'compare' => 'LIKE' ], [ 'key' => '_billing_email', 'value' => $search, 'compare' => 'LIKE' ] ]; } } // 2. Date Filter Logic - Fixed for WC Compatibility if (!empty($request['date_from']) || !empty($request['date_to'])) { $start = !empty($request['date_from']) ? $request['date_from'] : ''; $end = !empty($request['date_to']) ? $request['date_to'] : ''; if ($start && $end) { $params['date_created'] = $start . '...' . $end; } elseif ($start) { $params['date_created'] = '>=' . $start; } elseif ($end) { $params['date_created'] = '<=' . $end; } } // 3. Dokan Vendor Isolation if (function_exists('dokan_is_user_seller') && dokan_is_user_seller(get_current_user_id())) { $params['author'] = get_current_user_id(); } // Handle Abandoned Status (Virtual) if ($status === 'abandoned') { $table = $wpdb->prefix . 'woocommersa_abandoned_carts'; $where = "WHERE status = 'abandoned'"; if (!empty($search)) { $where .= $wpdb->prepare(" AND (phone LIKE %s OR email LIKE %s)", '%' . $search . '%', '%' . $search . '%'); } if (!empty($request['date_from'])) { $where .= $wpdb->prepare(" AND created_at >= %s", $request['date_from'] . ' 00:00:00'); } if (!empty($request['date_to'])) { $where .= $wpdb->prepare(" AND created_at <= %s", $request['date_to'] . ' 23:59:59'); } $offset = ($page - 1) * $per_page; $results = $wpdb->get_results($wpdb->prepare( "SELECT * FROM $table $where ORDER BY created_at DESC LIMIT %d OFFSET %d", $per_page, $offset )); $total = $wpdb->get_var("SELECT COUNT(*) FROM $table $where"); $data = []; foreach ($results as $row) { $cart_data = unserialize($row->cart_data); $items_detailed = []; if (is_array($cart_data)) { foreach ($cart_data as $item) { $items_detailed[] = [ 'name' => $item['product_name'] ?? 'محصول', 'qty' => $item['quantity'] ?? 1, 'total' => $item['line_total'] ?? 0, 'image' => '' ]; } } $data[] = [ 'id' => 'abc_' . $row->id, 'order_number' => 'رها شده #' . $row->id, 'status' => 'abandoned', 'total' => (float)$row->total_amount, 'currency' => get_woocommerce_currency(), 'date' => $row->created_at, 'customer' => [ 'name' => 'مشتری رها شده', 'email' => $row->email, 'phone' => $row->phone, 'address' => '-' ], 'payment_method' => '-', 'shipping_method' => '-', 'items_count' => count($items_detailed), 'items_list' => $items_detailed, 'is_virtual' => true ]; } return new \WP_REST_Response([ 'orders' => $data, 'total' => (int)$total, 'pages' => ceil($total / $per_page), 'summary' => $this->get_order_summary($wpdb) ], 200); } try { $orders = wc_get_orders($params); } catch (\Exception $e) { return new \WP_REST_Response(['message' => 'Query error: ' . $e->getMessage()], 500); } if (!$orders || !is_object($orders) || !isset($orders->orders)) { return new \WP_REST_Response(['orders' => [], 'total' => 0, 'pages' => 0, 'summary' => ['today_count' => 0, 'today_revenue' => 0, 'pending_count' => 0]], 200); } $data = []; foreach ($orders->orders as $order) { if (!$order instanceof \WC_Order) continue; $items_detailed = []; foreach ($order->get_items() as $item) { // Ensure it's a product item before getting product object if (!$item instanceof \WC_Order_Item_Product) continue; $product = $item->get_product(); try { $items_detailed[] = [ 'name' => $item->get_name(), 'qty' => $item->get_quantity(), 'total' => $item->get_total(), 'sku' => $product ? $product->get_sku() : '', 'image' => $product ? wp_get_attachment_image_url($product->get_image_id(), 'thumbnail') : '' ]; } catch (\Exception $e) { continue; } } try { $data[] = [ 'id' => $order->get_id(), 'order_number' => $order->get_order_number(), 'status' => $order->get_status(), 'total' => (float)$order->get_total(), 'currency' => $order->get_currency(), 'date' => $order->get_date_created() ? $order->get_date_created()->date('Y-m-d H:i') : '', 'customer' => [ 'name' => trim($order->get_billing_first_name() . ' ' . $order->get_billing_last_name()), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone(), 'address' => trim($order->get_billing_address_1() . ', ' . $order->get_billing_city()) ], 'payment_method' => $order->get_payment_method_title() ?: 'نامشخص', 'shipping_method' => $order->get_shipping_method() ?: 'نامشخص', 'tracking_code' => $order->get_meta('_tracking_code') ?: '', 'note' => $order->get_customer_note() ?: '', 'items_count' => count($items_detailed), 'items_list' => $items_detailed, 'shipping_total' => (float)$order->get_shipping_total(), 'discount_total' => (float)$order->get_discount_total(), ]; } catch (\Exception $e) { continue; } } return new \WP_REST_Response([ 'orders' => $data, 'total' => (int)($orders->total ?? 0), 'pages' => (int)($orders->max_num_pages ?? 0), 'summary' => $this->get_order_summary($wpdb) ], 200); } private function get_order_summary($wpdb) { $today_count = 0; $today_revenue = 0; try { $today_stats = $wpdb->get_row(" SELECT COUNT(*) as count, SUM(total_sales) as revenue FROM {$wpdb->prefix}wc_order_stats WHERE date_created >= CURDATE() AND status NOT IN ('wc-cancelled', 'wc-trash', 'wc-failed') "); $today_count = (int)($today_stats->count ?? 0); $today_revenue = (float)($today_stats->revenue ?? 0); } catch (\Exception $e) { } return [ 'today_count' => $today_count, 'today_revenue' => $today_revenue, 'pending_count' => (int)(wc_orders_count('pending') + wc_orders_count('on-hold')) ]; } public function get_statuses() { $statuses = wc_get_order_statuses(); $data = []; foreach ($statuses as $slug => $label) { $data[$slug] = $label; } return new \WP_REST_Response($data, 200); } public function batch_update($request) { $orders_data = $request->get_json_params(); $count = 0; $history = new \WooCommersa\Repositories\HistoryRepository(); $user_id = get_current_user_id(); $batch_id = 'order_batch_' . time(); foreach ($orders_data as $data) { $id = $data['id']; // Security: Ensure vendor owns this order if (function_exists('dokan_is_user_seller') && dokan_is_user_seller($user_id)) { if (intval(get_post_field('post_author', $id)) !== $user_id) { continue; } } $order = wc_get_order($id); if ($order) { if (isset($data['status'])) { $old = $order->get_status(); $order->set_status($data['status']); $history->record($user_id, $id, 'وضعیت سفارش', $old, $data['status'], $batch_id, 'manual'); } $order->save(); $count++; } } return new \WP_REST_Response(['success' => true, 'updated' => $count], 200); } public function update_order($request) { $params = $request->get_json_params(); $id = intval($params['id'] ?? 0); $field = sanitize_text_field($params['field'] ?? ''); $value = sanitize_text_field($params['value'] ?? ''); if (!$id || !$field) { return new \WP_Error('invalid_data', 'Missing ID or field', ['status' => 400]); } $order = wc_get_order($id); if (!$order) { return new \WP_Error('invalid_order', 'Order not found', ['status' => 404]); } // Security: Ensure vendor owns this order if (function_exists('dokan_is_user_seller') && dokan_is_user_seller($user_id)) { if (intval(get_post_field('post_author', $id)) !== $user_id) { return new \WP_Error('rest_forbidden', 'شما اجازه ویرایش این سفارش را ندارید.', ['status' => 403]); } } $history = new \WooCommersa\Repositories\HistoryRepository(); $user_id = get_current_user_id(); $old_val = ''; switch ($field) { case 'status': $old_val = $order->get_status(); $order->update_status($value); $history->record($user_id, $id, 'وضعیت سفارش', $old_val, $value, '', 'manual'); break; case 'tracking_code': $old_val = $order->get_meta('_tracking_code'); $order->update_meta_data('_tracking_code', $value); $history->record($user_id, $id, 'کد رهگیری سفارش', $old_val, $value, '', 'manual'); // Trigger SMS if tracking code is set if (!empty($value)) { $sms = new \WooCommersa\Services\SMSService(); $sms->send_notification($order->get_billing_phone(), 'tracking_added', [ 'order_id' => $id, 'tracking_code' => $value, 'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() ]); } break; case 'note': $old_val = $order->get_customer_note(); $order->set_customer_note($value); $history->record($user_id, $id, 'یادداشت سفارش', $old_val, $value, '', 'manual'); break; } $order->save(); return new \WP_REST_Response(['success' => true], 200); } }