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 :
PricingController.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; use WooCommersa\Repositories\PricingRepository; use WooCommersa\Services\PricingService; class PricingController extends BaseController { private $repository; private $service; public function __construct() { $this->repository = new PricingRepository(); $this->service = new PricingService(); add_action('rest_api_init', [$this, 'register_routes']); } public function register_routes() { register_rest_route($this->namespace, '/pricing-rules', [ 'methods' => ['GET', 'POST'], 'callback' => [$this, 'handle_rules'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/pricing-rules/(?P<id>\d+)', [ 'methods' => ['DELETE', 'PATCH'], 'callback' => [$this, 'handle_single_rule'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/pricing-rules/settings', [ 'methods' => ['GET', 'POST'], 'callback' => [$this, 'handle_settings'], 'permission_callback' => [$this, 'permissions_check'], ]); register_rest_route($this->namespace, '/pricing-rules/apply', [ 'methods' => 'POST', 'callback' => [$this, 'apply_all_rules'], 'permission_callback' => [$this, 'permissions_check'], ]); } public function handle_settings($request) { if ($request->get_method() === 'POST') { $params = $request->get_json_params(); update_option('woocommersa_pricing_settings', $params); // Sync with main settings $main = get_option('woocommersa_settings', []); $main['enable_automation'] = (bool)($params['enabled'] ?? false); if (isset($params['schedule'])) { $main['automation_interval'] = $params['schedule']; } update_option('woocommersa_settings', $main); return new \WP_REST_Response(['success' => true], 200); } $main = get_option('woocommersa_settings', []); $settings = get_option('woocommersa_pricing_settings', [ 'enabled' => $main['enable_automation'] ?? false, 'schedule' => $main['automation_interval'] ?? 'daily' ]); // Ensure consistency with main switch if (isset($main['enable_automation'])) { $settings['enabled'] = (bool)$main['enable_automation']; } if (isset($main['automation_interval'])) { $settings['schedule'] = $main['automation_interval']; } return new \WP_REST_Response($settings, 200); } public function apply_all_rules($request) { $params = $request->get_json_params(); $ids = $params['ids'] ?? []; if (empty($ids)) { $rules = $this->repository->get_active(); $ids = array_map(function($r) { return $r->id; }, $rules); } $total_affected = 0; foreach ($ids as $id) { $total_affected += $this->service->apply_rule($id); } return new \WP_REST_Response([ 'success' => true, 'affected_count' => $total_affected, 'message' => __('عملیات با موفقیت انجام شد.', 'woocommersa') ], 200); } public function handle_rules($request) { if ($request->get_method() === 'POST') { $params = $request->get_json_params(); $data = [ 'name' => sanitize_text_field($params['name']), 'conditions' => json_encode($params['conditions']), 'action_type' => sanitize_text_field($params['action_type']), 'action_value' => sanitize_text_field($params['action_value']), 'target_price' => sanitize_text_field($params['target_price'] ?? 'regular_price'), 'min_margin_percent' => floatval($params['min_margin_percent'] ?? 0), 'status' => $params['status'] ?? 'active' ]; if (!empty($params['id'])) { $data['id'] = (int)$params['id']; } $this->repository->save($data); return new \WP_REST_Response(['success' => true], 200); } return new \WP_REST_Response($this->repository->get_all(), 200); } public function handle_single_rule($request) { $id = $request['id']; if ($request->get_method() === 'DELETE') { $this->repository->delete($id); } else { $params = $request->get_params(); $this->repository->update_status($id, $params['status']); } return new \WP_REST_Response(['success' => true], 200); } public function apply_rule($request) { $id = $request['id']; $count = $this->service->apply_rule($id); return new \WP_REST_Response(['message' => sprintf(__('%d محصول بروزرسانی شد.', 'woocommersa'), $count)], 200); } }