PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / Addons / RequestAQuote / API / SettingsEndpoint.php

SettingsEndpoint.php in Tiered Pricing Table for WooCommerce trunk, at src/Addons/RequestAQuote/API/SettingsEndpoint.php

54 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\RequestAQuote\API;
2
3 use WP_REST_Controller;
4 use WP_REST_Server;
5
6 class SettingsEndpoint extends WP_REST_Controller {
7
8 protected $namespace = 'tier-pricing-table/v1';
9 protected $restBase = 'quote-settings';
10
11 public function register_routes() {
12 register_rest_route( $this->namespace, '/' . $this->restBase, array(
13 array(
14 'methods' => WP_REST_Server::READABLE,
15 'callback' => array( $this, 'get_items' ),
16 'permission_callback' => array( $this, 'permissions_check' ),
17 ),
18 array(
19 'methods' => WP_REST_Server::CREATABLE,
20 'callback' => array( $this, 'create_item' ),
21 'permission_callback' => array( $this, 'permissions_check' ),
22 ),
23 ) );
24 }
25
26 public function permissions_check( $request ) {
27 return current_user_can( 'manage_woocommerce' );
28 }
29
30 public function get_items( $request ) {
31 $settings = get_option( 'tier_pricing_table_quote_global_settings', array() );
32 return rest_ensure_response( $settings );
33 }
34
35 public function create_item( $request ) {
36 $settings = $request->get_param( 'settings' );
37
38 if ( ! is_array( $settings ) ) {
39 return new \WP_Error( 'invalid_data', 'Settings must be an array', array( 'status' => 400 ) );
40 }
41
42 // Ensure we always have an array
43 $current_settings = get_option( 'tier_pricing_table_quote_global_settings', array() );
44 if ( ! is_array( $current_settings ) ) {
45 $current_settings = array();
46 }
47
48 $new_settings = array_merge( $current_settings, $settings );
49 update_option( 'tier_pricing_table_quote_global_settings', $new_settings );
50
51 return rest_ensure_response( $new_settings );
52 }
53 }
54