PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.3
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.3
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / V2 / Proxy / Orders_Proxy_Behavior.php

Orders_Proxy_Behavior.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.3, at includes/API/V2/Proxy/Orders_Proxy_Behavior.php

91 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order catalog proxy behavior.
4 *
5 * @package WCPOS\WooCommercePOS\API\V2\Proxy
6 */
7
8 namespace WCPOS\WooCommercePOS\API\V2\Proxy;
9
10 use WCPOS\WooCommercePOS\Sync\Collection_Rules;
11 use WCPOS\WooCommercePOS\Sync\Order_Serializer;
12 use WP_REST_Request;
13
14 /**
15 * Applies the order Collection Rules plan and v2 order wire shape.
16 */
17 final class Orders_Proxy_Behavior extends Scoped_Proxy_Behavior {
18 /**
19 * Proxy request keys claimed by the order Collection Rules plan.
20 */
21 private const PARAM_MAP = array(
22 'orderby' => 'orderby',
23 'order' => 'order',
24 'pos_cashier' => 'pos_cashier',
25 'pos_store' => 'pos_store',
26 'created_via' => 'created_via',
27 'include' => array(
28 'key' => 'include',
29 'when' => 'search',
30 'parse' => 'id_list',
31 ),
32 'exclude' => array(
33 'key' => 'exclude',
34 'when' => 'search',
35 'parse' => 'id_list',
36 ),
37 );
38
39 /**
40 * The Collection Rules plan for the request in flight.
41 *
42 * @var null|\WCPOS\WooCommercePOS\Sync\Collection_Rules_Plan
43 */
44 private $plan;
45
46 /**
47 * Claim the orders params the rules table owns, then ask wc/v3 for full precision.
48 *
49 * @param array $params Query parameters to forward.
50 * @param WP_REST_Request $request Original proxy request.
51 *
52 * @return array
53 */
54 public function forwarded_params( array $params, WP_REST_Request $request ): array {
55 $this->plan = Collection_Rules::for_request( 'orders', $request, self::PARAM_MAP );
56 $params = $this->plan->forwarded_params( $params );
57 $params['dp'] = '6';
58
59 return $params;
60 }
61
62 /**
63 * Run the forward inside the Collection Rules plan for this request.
64 *
65 * @param callable $forward Forward operation.
66 *
67 * @return mixed
68 */
69 protected function run( callable $forward ) {
70 return null === $this->plan ? $forward() : $this->plan->around( $forward );
71 }
72
73 /**
74 * Apply the shared v2 order augmentations to every row.
75 *
76 * @param mixed $data Response data.
77 *
78 * @return mixed
79 */
80 public function post_process( $data ) {
81 $serializer = new Order_Serializer();
82 foreach ( (array) $data as $index => $payload ) {
83 if ( is_array( $payload ) ) {
84 $data[ $index ] = $serializer->document( $payload, Order_Serializer::V2_AUGMENTATIONS );
85 }
86 }
87
88 return $data;
89 }
90 }
91