File tree Expand file tree Collapse file tree 5 files changed +81
-77
lines changed Expand file tree Collapse file tree 5 files changed +81
-77
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright 2025 Adobe.
4+ * All Rights Reserved.
5+ */
6+
7+ declare (strict_types=1 );
8+ namespace Magento \Captcha \Block ;
9+
10+ use Magento \Checkout \Block \Checkout \LayoutProcessorInterface ;
11+ use Magento \Captcha \Helper \Data as HelperCaptcha ;
12+
13+ class CaptchaLayoutProcessor implements LayoutProcessorInterface
14+ {
15+ /**
16+ * @param HelperCaptcha $helper
17+ */
18+ public function __construct (
19+ private readonly HelperCaptcha $ helper
20+ ) {
21+ }
22+
23+ /**
24+ * Remove captcha from checkout page if it is disabled
25+ *
26+ * @param array $jsLayout
27+ * @return array
28+ */
29+ public function process ($ jsLayout ): array
30+ {
31+ if (!$ this ->helper ->getConfig ('enable ' )) {
32+ if (isset ($ jsLayout ['components ' ]['checkout ' ]['children ' ]['authentication ' ]['children ' ]['captcha ' ])) {
33+ unset($ jsLayout ['components ' ]['checkout ' ]['children ' ]['authentication ' ]['children ' ]['captcha ' ]);
34+ }
35+ if (isset ($ jsLayout ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]['shipping-step ' ]['children ' ]['shippingAddress ' ]['children ' ]['customer-email ' ]['children ' ]['additional-login-form-fields ' ]['children ' ]['captcha ' ])) {
36+ unset($ jsLayout ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]['shipping-step ' ]['children ' ]['shippingAddress ' ]['children ' ]['customer-email ' ]['children ' ]['additional-login-form-fields ' ]['children ' ]['captcha ' ]);
37+ }
38+ if (isset ($ jsLayout ['components ' ]['authenticationPopup ' ]['children ' ]['captcha ' ])) {
39+ unset($ jsLayout ['components ' ]['authenticationPopup ' ]['children ' ]['captcha ' ]);
40+ }
41+ }
42+ return $ jsLayout ;
43+ }
44+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3737 <type name =" Magento\Sales\Api\OrderManagementInterface" >
3838 <plugin name =" reset_payment_attempts_after_order_is_placed_plugin" type =" Magento\Captcha\Plugin\ResetPaymentAttemptsAfterOrderIsPlacedPlugin" />
3939 </type >
40- <type name =" Magento\Customer\Block\Account\AuthenticationPopup" >
41- <plugin name =" check_captcha_on_storefront" type =" Magento\Captcha\Plugin\CheckCaptchaOnStorefront" sortOrder =" 10" />
40+
41+ <type name =" Magento\Checkout\Block\Onepage" >
42+ <arguments >
43+ <argument name =" layoutProcessors" xsi : type =" array" >
44+ <item name =" captcha_processor" xsi : type =" object" >Magento\Captcha\Block\CaptchaLayoutProcessor</item >
45+ </argument >
46+ </arguments >
4247 </type >
4348</config >
Original file line number Diff line number Diff line change 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved .
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe .
4+ * All Rights Reserved .
55 */
66namespace Magento \Customer \Block \Account ;
77
88use Magento \Customer \Model \Form ;
99use Magento \Store \Model \ScopeInterface ;
10+ use Magento \Customer \Model \Context ;
1011
1112/**
1213 * @api
@@ -48,6 +49,16 @@ public function __construct(
4849 */
4950 public function getJsLayout ()
5051 {
52+ // Check if captcha is not enabled and user is not logged in
53+ if (!$ this ->_scopeConfig ->getValue (
54+ Form::XML_PATH_CUSTOMER_CAPTCHA_ENABLED ,
55+ ScopeInterface::SCOPE_STORE
56+ ) && !$ this ->isLoggedIn ()) {
57+ if (isset ($ this ->jsLayout ['components ' ]['authenticationPopup ' ]['children ' ]['captcha ' ])) {
58+ unset($ this ->jsLayout ['components ' ]['authenticationPopup ' ]['children ' ]['captcha ' ]);
59+ }
60+ }
61+
5162 return $ this ->serializer ->serialize ($ this ->jsLayout );
5263 }
5364
@@ -122,4 +133,14 @@ public function getCustomerForgotPasswordUrl()
122133 {
123134 return $ this ->getUrl ('customer/account/forgotpassword ' );
124135 }
136+
137+ /**
138+ * Is logged in
139+ *
140+ * @return bool
141+ */
142+ private function isLoggedIn (): ?bool
143+ {
144+ return $ this ->httpContext ->getValue (Context::CONTEXT_AUTH );
145+ }
125146}
Original file line number Diff line number Diff line change 11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved .
4- * See COPYING.txt for license details .
3+ * Copyright 2011 Adobe .
4+ * All Rights Reserved .
55 */
66
77namespace Magento \Customer \Model ;
@@ -16,6 +16,11 @@ class Form extends \Magento\Eav\Model\Form
1616 */
1717 public const XML_PATH_ENABLE_AUTOCOMPLETE = 'customer/password/autocomplete_on_storefront ' ;
1818
19+ /**
20+ * XML configuration paths for "Enable CAPTCHA on Storefront" property
21+ */
22+ public const XML_PATH_CUSTOMER_CAPTCHA_ENABLED = 'customer/captcha/enable ' ;
23+
1924 /**
2025 * Current module pathname
2126 *
You can’t perform that action at this time.
0 commit comments