PluginProbe
seQura / 4.3.0
seQura v4.3.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
← All changes | src/Controllers/Hooks/Order/class-order-controller.php +75 -15 3.0.24.3.0 View file →
@@ -9,9 +9,10 @@
9 9 namespace SeQura\WC\Controllers\Hooks\Order;
10 10
11 11 use SeQura\Core\Infrastructure\Logger\LogContextData;
12 12 use SeQura\WC\Controllers\Controller;
13 -use SeQura\WC\Services\Interface_Logger_Service;
13 +use SeQura\WC\Services\Cart\Interface_Cart_Service;
14 +use SeQura\WC\Services\Log\Interface_Logger_Service;
14 15 use SeQura\WC\Services\Order\Interface_Order_Service;
15 16 use Throwable;
16 17 use WC_Order;
17 18
@@ -27,19 +28,28 @@
27 28 */
28 29 private $order_service;
29 30
30 31 /**
32 + * Cart service
33 + *
34 + * @var Interface_Cart_Service
35 + */
36 + private $cart_service;
37 +
38 + /**
31 39 * Constructor
32 40 */
33 41 public function __construct(
34 42 Interface_Logger_Service $logger,
35 43 string $templates_path,
36 - Interface_Order_Service $order_service
44 + Interface_Order_Service $order_service,
45 + Interface_Cart_Service $cart_service
37 46 ) {
38 47 parent::__construct( $logger, $templates_path );
39 48 $this->order_service = $order_service;
49 + $this->cart_service = $cart_service;
40 50
41 - add_action( 'admin_notices', array( $this, 'display_notices' ) );
51 + \add_action( 'admin_notices', array( $this, 'display_notices' ) );
42 52 }
43 53
44 54 /**
45 55 * Add support to custom meta query vars for the order query
@@ -48,9 +58,9 @@
48 58 * @param array $query_vars Query vars from WC_Order_Query.
49 59 * @param WC_Order_Data_Store_CPT $order_data_store WC_Order_Data_Store instance.
50 60 * @return array modified $query
51 61 */
52 - public function handle_custom_query_vars( array $wp_query_args, array $query_vars, $order_data_store ): array {
62 + public function handle_custom_query_vars( $wp_query_args, $query_vars, $order_data_store ) {
53 63 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
54 64 $custom_query_vars = array(
55 65 $this->order_service->get_sent_to_sequra_meta_key(),
56 66 );
@@ -70,10 +80,17 @@
70 80 }
71 81
72 82 /**
73 83 * Trigger the sync of the order status with SeQura
84 + *
85 + * @param int $order_id Order ID.
86 + * @param string $old_status Old status.
87 + * @param string $new_status New status.
88 + * @param WC_Order $order Order object.
89 + *
90 + * @return void
74 91 */
75 - public function handle_order_status_changed( int $order_id, string $old_status, string $new_status, WC_Order $order ): void {
92 + public function handle_order_status_changed( $order_id, $old_status, $new_status, $order ) {
76 93 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
77 94 try {
78 95 $this->order_service->update_sequra_order_status( $order, $old_status, $new_status );
79 96 } catch ( Throwable $e ) {
@@ -87,9 +104,9 @@
87 104 new LogContextData( 'new_status', $new_status ),
88 105 )
89 106 );
90 107
91 - set_transient(
108 + \set_transient(
92 109 $this->get_notices_transient( $order_id ),
93 110 array(
94 111 array(
95 112 'notice' => __( 'An error occurred while updating the order data in seQura.', 'sequra' ), // TODO: improve message with link to simba.
@@ -103,35 +120,39 @@
103 120 }
104 121
105 122 /**
106 123 * Get the transient key for notices related to an order
124 + *
125 + * @param int $order_id Order ID.
107 126 */
108 - private function get_notices_transient( int $order_id ): string {
127 + private function get_notices_transient( $order_id ): string {
109 128 return 'sequra_notices_order_' . $order_id;
110 129 }
111 130
112 131 /**
113 132 * Display notices related to an order
133 + *
134 + * @return void
114 135 */
115 - public function display_notices(): void {
136 + public function display_notices() {
116 137 // phpcs:ignore WordPress.Security.NonceVerification
117 - if ( ! is_admin() || ! isset( $_GET['post'], $_GET['action'] ) || 'edit' !== $_GET['action'] ) {
138 + if ( ! \is_admin() || ! isset( $_GET['post'], $_GET['action'] ) || 'edit' !== $_GET['action'] ) {
118 139 return;
119 140 }
120 141
121 - $order = wc_get_order( absint( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
142 + $order = wc_get_order( \absint( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
122 143 if ( ! $order instanceof WC_Order ) {
123 144 return;
124 145 }
125 146
126 147 $transient_key = $this->get_notices_transient( $order->get_id() );
127 - $notices = (array) get_transient( $transient_key );
148 + $notices = (array) \get_transient( $transient_key );
128 149 if ( ! empty( $notices ) ) {
129 - delete_transient( $transient_key );
150 + \delete_transient( $transient_key );
130 151 }
131 152 foreach ( $notices as $notice ) {
132 153 ob_start();
133 - wc_get_template( 'admin/notice.php', $notice, '', $this->templates_path );
154 + \wc_get_template( 'admin/notice.php', $notice, '', $this->templates_path );
134 155 echo ob_get_clean(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
135 156 }
136 157 }
137 158
@@ -136,12 +157,51 @@
136 157 }
137 158
138 159 /**
139 160 * Show a link to the seQura back office in the order details page
161 + *
162 + * @param WC_Order $order Order object.
163 + * @return void
140 164 */
141 - public function show_link_to_sequra_back_office( WC_Order $order ): void {
165 + public function show_link_to_sequra_back_office( $order ): void {
142 166 $args = array(
143 167 'sequra_link' => $this->order_service->get_link_to_sequra_back_office( $order ),
144 168 );
145 - wc_get_template( 'admin/order_details.php', $args, '', $this->templates_path );
169 + \wc_get_template( 'admin/order_details.php', $args, '', $this->templates_path );
170 + }
171 +
172 + /**
173 + * Cleanup orders
174 + *
175 + * @return void
176 + */
177 + public function cleanup_orders() {
178 + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
179 + $this->order_service->cleanup_orders();
180 + }
181 +
182 + /**
183 + * Respond to the sequra_order_migration_add_indexes hook
184 + *
185 + * @param string $hook Hook name that triggered the action.
186 + */
187 + public function migrate_orders_to_use_indexes( $hook ) {
188 + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
189 +
190 + if ( $this->order_service->is_migration_complete() ) {
191 + $this->logger->log_debug( 'Indexing process is done. Job will be unscheduled', __FUNCTION__, __CLASS__ );
192 + \wp_clear_scheduled_hook( $hook, array( $hook ) );
193 + return;
194 + }
195 +
196 + $this->order_service->migrate_data();
197 + }
198 +
199 + /**
200 + * Create the Cart Info object for the current session if it doesn't exist.
201 + *
202 + * @return void
203 + */
204 + public function ensure_cart_info_exists() {
205 + $this->cart_service->get_cart_info_from_session();
146 206 }
147 207 }