Skip to content

Commit f0fe55b

Browse files
authored
Merge pull request #9 from magento-tsg-csl3/MC-40393
MC-40393: ReCaptcha prevents checkout with In Store Pickup option
2 parents 544b066 + bb5f32d commit f0fe55b

File tree

9 files changed

+197
-0
lines changed

9 files changed

+197
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaStorePickup\Block\LayoutProcessor\Checkout;
9+
10+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
11+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
12+
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
13+
14+
/**
15+
* Provides reCaptcha component configuration.
16+
*/
17+
class Onepage implements LayoutProcessorInterface
18+
{
19+
/**
20+
* @var UiConfigResolverInterface
21+
*/
22+
private $captchaUiConfigResolver;
23+
24+
/**
25+
* @var IsCaptchaEnabledInterface
26+
*/
27+
private $isCaptchaEnabled;
28+
29+
/**
30+
* @param UiConfigResolverInterface $captchaUiConfigResolver
31+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
32+
*/
33+
public function __construct(
34+
UiConfigResolverInterface $captchaUiConfigResolver,
35+
IsCaptchaEnabledInterface $isCaptchaEnabled
36+
) {
37+
$this->captchaUiConfigResolver = $captchaUiConfigResolver;
38+
$this->isCaptchaEnabled = $isCaptchaEnabled;
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function process($jsLayout)
45+
{
46+
$key = 'customer_login';
47+
if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) {
48+
$jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children']
49+
['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children']
50+
['recaptcha']['settings'] = $this->captchaUiConfigResolver->get($key);
51+
} else {
52+
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children']
53+
['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children']
54+
['recaptcha']['settings'])) {
55+
unset($jsLayout['components']['checkout']['children']['steps']['children']['store-pickup']['children']
56+
['store-selector']['children']['customer-email']['children']['additional-login-form-fields']['children']
57+
['recaptcha']['settings']);
58+
}
59+
}
60+
61+
return $jsLayout;
62+
}
63+
}

ReCaptchaStorePickup/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please refer to: https://github.com/magento/security-package

ReCaptchaStorePickup/composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "magento/module-re-captcha-store-pickup",
3+
"description": "Google reCaptcha integration for Magento2 Inventory Store Pickup shipping form",
4+
"require": {
5+
"php": "~7.3.0||~7.4.0",
6+
"magento/framework": "*",
7+
"magento/module-checkout": "*",
8+
"magento/module-re-captcha-ui": "*"
9+
},
10+
"suggest": {
11+
"magento/module-inventory-in-store-pickup-frontend": "*"
12+
},
13+
"type": "magento2-module",
14+
"license": "OSL-3.0",
15+
"autoload": {
16+
"files": [
17+
"registration.php"
18+
],
19+
"psr-4": {
20+
"Magento\\ReCaptchaStorePickup\\": ""
21+
}
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\Checkout\Block\Onepage">
11+
<arguments>
12+
<argument name="layoutProcessors" xsi:type="array">
13+
<item name="store_pickup_recaptcha" xsi:type="object">\Magento\ReCaptchaStorePickup\Block\LayoutProcessor\Checkout\Onepage</item>
14+
</argument>
15+
</arguments>
16+
</type>
17+
</config>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10+
<module name="Magento_ReCaptchaStorePickup"/>
11+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
\Magento\Framework\Component\ComponentRegistrar::register(
9+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
10+
'Magento_ReCaptchaStorePickup',
11+
__DIR__
12+
);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
10+
<body>
11+
<referenceBlock name="checkout.root">
12+
<arguments>
13+
<argument name="jsLayout" xsi:type="array">
14+
<item name="components" xsi:type="array">
15+
<item name="checkout" xsi:type="array">
16+
<item name="children" xsi:type="array">
17+
<item name="steps" xsi:type="array">
18+
<item name="children" xsi:type="array">
19+
<item name="store-pickup" xsi:type="array">
20+
<item name="children" xsi:type="array">
21+
<item name="store-selector" xsi:type="array">
22+
<item name="children" xsi:type="array">
23+
<item name="customer-email" xsi:type="array">
24+
<item name="children" xsi:type="array">
25+
<item name="additional-login-form-fields" xsi:type="array">
26+
<item name="children" xsi:type="array">
27+
<item name="recaptcha" xsi:type="array">
28+
<item name="component" xsi:type="string">Magento_ReCaptchaStorePickup/js/reCaptchaStorePickup</item>
29+
<item name="displayArea" xsi:type="string">additional-login-form-fields</item>
30+
<item name="configSource" xsi:type="string">checkoutConfig</item>
31+
<item name="reCaptchaId" xsi:type="string">store-pickup-recaptcha-checkout-inline-login</item>
32+
</item>
33+
</item>
34+
</item>
35+
</item>
36+
</item>
37+
</item>
38+
</item>
39+
</item>
40+
</item>
41+
</item>
42+
</item>
43+
</item>
44+
</item>
45+
</item>
46+
</argument>
47+
</arguments>
48+
</referenceBlock>
49+
</body>
50+
</page>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define(['Magento_ReCaptchaFrontendUi/js/reCaptcha'], function (reCaptcha) {
7+
'use strict';
8+
9+
return reCaptcha.extend({
10+
11+
/**
12+
* @inheritdoc
13+
*/
14+
renderReCaptcha: function () {
15+
this.captchaInitialized = false;
16+
this._super();
17+
}
18+
});
19+
});

_metapackage/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"magento/module-re-captcha-paypal": "*",
1414
"magento/module-re-captcha-review": "*",
1515
"magento/module-re-captcha-send-friend": "*",
16+
"magento/module-re-captcha-store-pickup": "*",
1617
"magento/module-re-captcha-ui": "*",
1718
"magento/module-re-captcha-user": "*",
1819
"magento/module-re-captcha-validation": "*",

0 commit comments

Comments
 (0)