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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / OrderWithdrawal / OrderWithdrawalController.php
woocommerce / src / Internal / OrderWithdrawal Last commit date
OrderWithdrawalController.php 2 weeks ago OrderWithdrawalFeatureHighlightNotification.php 2 weeks ago OrderWithdrawalFormProcessor.php 2 weeks ago OrderWithdrawalFormState.php 2 weeks ago OrderWithdrawalFormView.php 2 weeks ago
OrderWithdrawalController.php
252 lines
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Automattic\WooCommerce\Internal\OrderWithdrawal;
5
6 use Automattic\WooCommerce\Internal\Features\FeaturesController;
7 use Automattic\WooCommerce\Internal\RegisterHooksInterface;
8 use Automattic\WooCommerce\Utilities\FeaturesUtil;
9
10 /**
11 * Registers the order withdrawal endpoint and related feature-gated UI.
12 *
13 * @internal Just for internal use.
14 */
15 final class OrderWithdrawalController implements RegisterHooksInterface {
16
17 private const FEATURE_ID = 'order_withdrawal';
18 private const ENDPOINT_KEY = 'order-withdrawal';
19 private const ENDPOINT_SLUG = 'withdraw-order';
20 private const ENDPOINT_OPTION = 'woocommerce_myaccount_order_withdrawal_endpoint';
21
22 /**
23 * Form processor.
24 *
25 * @var OrderWithdrawalFormProcessor
26 */
27 private OrderWithdrawalFormProcessor $form_processor;
28
29 /**
30 * Form view.
31 *
32 * @var OrderWithdrawalFormView
33 */
34 private OrderWithdrawalFormView $form_view;
35
36 /**
37 * Feature highlight notification.
38 *
39 * @var OrderWithdrawalFeatureHighlightNotification
40 */
41 private OrderWithdrawalFeatureHighlightNotification $feature_highlight_notification;
42
43 /**
44 * Initialize dependencies.
45 *
46 * @param OrderWithdrawalFormProcessor $form_processor Form processor.
47 * @param OrderWithdrawalFormView $form_view Form view.
48 * @param OrderWithdrawalFeatureHighlightNotification $feature_highlight_notification Feature highlight notification.
49 * @internal
50 *
51 * @since 11.1.0
52 */
53 final public function init( OrderWithdrawalFormProcessor $form_processor, OrderWithdrawalFormView $form_view, OrderWithdrawalFeatureHighlightNotification $feature_highlight_notification ): void { // phpcs:ignore Generic.CodeAnalysis.UnnecessaryFinalModifier.Found -- Required by WooCommerce injection method rules.
54 $this->form_processor = $form_processor;
55 $this->form_view = $form_view;
56 $this->feature_highlight_notification = $feature_highlight_notification;
57 }
58
59 /**
60 * Register hooks.
61 *
62 * @since 11.1.0
63 */
64 public function register(): void {
65 add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'maybe_flush_rewrite_rules' ), 10, 1 );
66 add_filter( 'woocommerce_get_query_vars', array( $this, 'add_query_var' ), 10, 1 );
67 add_filter( 'woocommerce_endpoint_' . self::ENDPOINT_KEY . '_title', array( $this, 'get_endpoint_title' ), 10, 1 );
68 add_filter( 'woocommerce_settings_pages', array( $this, 'add_endpoint_setting' ), 10, 1 );
69 add_action( 'woocommerce_account_' . self::ENDPOINT_KEY . '_endpoint', array( $this, 'render_view' ) );
70 add_action( 'woocommerce_before_delete_order', array( $this->form_processor, 'delete_order_withdrawal_inbox_note_for_order' ), 10, 1 );
71 add_action( 'before_delete_post', array( $this->form_processor, 'delete_order_withdrawal_inbox_note_for_order' ), 10, 1 );
72 add_action( 'woocommerce_privacy_remove_order_personal_data', array( $this->form_processor, 'delete_order_withdrawal_inbox_note_for_order' ), 10, 1 );
73 add_action( 'init', array( $this, 'maybe_register_feature_highlight_notification' ), 10, 0 );
74 }
75
76 /**
77 * Whether order withdrawal is enabled.
78 *
79 * @since 11.1.0
80 */
81 public function is_enabled(): bool {
82 return FeaturesUtil::feature_is_enabled( self::FEATURE_ID );
83 }
84
85 /**
86 * Whether the current My Account request is for the public order withdrawal endpoint.
87 *
88 * @since 11.1.0
89 */
90 public function is_endpoint_request(): bool {
91 global $wp;
92
93 return $this->is_enabled()
94 && isset( $wp->query_vars[ self::ENDPOINT_KEY ] )
95 && self::ENDPOINT_KEY === WC()->query->get_current_endpoint();
96 }
97
98 /**
99 * Queue a rewrite rules flush when the feature is toggled.
100 *
101 * @param string $feature_id Feature being toggled.
102 *
103 * @since 11.1.0
104 */
105 public function maybe_flush_rewrite_rules( string $feature_id ): void {
106 if ( self::FEATURE_ID === $feature_id ) {
107 update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
108 }
109 }
110
111 /**
112 * Register the order withdrawal feature highlight notification if the feature is not enabled.
113 *
114 * @since 11.1.0
115 */
116 public function maybe_register_feature_highlight_notification(): void {
117 if ( ! $this->is_enabled() ) {
118 $this->feature_highlight_notification->register();
119 }
120 }
121
122 /**
123 * Register the order withdrawal query var.
124 *
125 * @param array $query_vars Existing query vars keyed by endpoint key.
126 * @return array
127 *
128 * @since 11.1.0
129 */
130 public function add_query_var( $query_vars ): array {
131 if ( ! is_array( $query_vars ) ) {
132 return array();
133 }
134
135 if ( $this->is_enabled() ) {
136 $query_vars[ self::ENDPOINT_KEY ] = (string) get_option( self::ENDPOINT_OPTION, self::ENDPOINT_SLUG );
137 }
138
139 return $query_vars;
140 }
141
142 /**
143 * Order withdrawal endpoint page title.
144 *
145 * @param string $title Default title.
146 * @return string
147 *
148 * @since 11.1.0
149 */
150 public function get_endpoint_title( $title ): string {
151 return __( 'Withdraw from contract', 'woocommerce' );
152 }
153
154 /**
155 * Add the endpoint setting when the feature is enabled.
156 *
157 * @param array $settings Page settings.
158 * @return array
159 *
160 * @since 11.1.0
161 */
162 public function add_endpoint_setting( $settings ): array {
163 if ( ! is_array( $settings ) ) {
164 return array();
165 }
166
167 if ( ! $this->is_enabled() ) {
168 return $settings;
169 }
170
171 $endpoint_setting = array(
172 'title' => __( 'Order withdrawal', 'woocommerce' ),
173 'desc' => __( 'Endpoint for the order withdrawal page.', 'woocommerce' ),
174 'id' => self::ENDPOINT_OPTION,
175 'type' => 'text',
176 'default' => self::ENDPOINT_SLUG,
177 'desc_tip' => true,
178 );
179
180 $new_settings = array();
181 $added = false;
182
183 foreach ( $settings as $setting ) {
184 if ( is_array( $setting ) && self::ENDPOINT_OPTION === ( $setting['id'] ?? '' ) ) {
185 return $settings;
186 }
187
188 if (
189 ! $added &&
190 is_array( $setting ) &&
191 'sectionend' === ( $setting['type'] ?? '' ) &&
192 'account_endpoint_options' === ( $setting['id'] ?? '' )
193 ) {
194 $new_settings[] = $endpoint_setting;
195 $added = true;
196 }
197
198 $new_settings[] = $setting;
199 }
200
201 if ( ! $added ) {
202 $new_settings[] = $endpoint_setting;
203 }
204
205 return $new_settings;
206 }
207
208 /**
209 * Render the order withdrawal view.
210 *
211 * @since 11.1.0
212 */
213 public function render_view(): void {
214 if ( ! $this->is_enabled() ) {
215 return;
216 }
217
218 wc_get_template( 'myaccount/form-order-withdrawal.php', $this->get_template_args() );
219 }
220
221 /**
222 * Get template arguments for the order withdrawal form.
223 *
224 * @return array<string,mixed>
225 */
226 private function get_template_args(): array {
227 return $this->form_view->get_template_args(
228 $this->form_processor->process_current_request(),
229 $this->get_form_action_url(),
230 $this->get_shop_url()
231 );
232 }
233
234 /**
235 * Get a safe shop URL for the confirmation link.
236 */
237 private function get_shop_url(): string {
238 $shop_url = wc_get_page_permalink( 'shop' );
239
240 return $shop_url ? $shop_url : home_url( '/' );
241 }
242
243 /**
244 * Get the form action URL.
245 */
246 private function get_form_action_url(): string {
247 $account_url = wc_get_page_permalink( 'myaccount' );
248
249 return wc_get_endpoint_url( self::ENDPOINT_KEY, '', $account_url ? $account_url : home_url( '/' ) );
250 }
251 }
252