Skip to content

Commit ce9b748

Browse files
authored
Merge pull request #4237 from magento-tsg/2.3.2-develop-pr52
[TSG] Fixes for 2.3.2 (pr52) (2.3.2-develop)
2 parents 18efe2d + 5c6db27 commit ce9b748

File tree

8 files changed

+187
-19
lines changed

8 files changed

+187
-19
lines changed

app/code/Magento/AuthorizenetAcceptjs/view/adminhtml/templates/payment/script.phtml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
/** @var Magento\AuthorizenetAcceptjs\Block\Payment $block */
88
?>
9-
<script type="text/x-magento-init">
10-
{
11-
"#payment_form_<?= $block->escapeJs($block->escapeHtml($block->getMethodCode())) ?>": {
12-
"Magento_AuthorizenetAcceptjs/js/payment-form": {
13-
"config": <?= /* @noEscape */ $block->getPaymentConfig() ?>
14-
}
15-
}
16-
}
17-
</script>
9+
<script>
10+
//<![CDATA[
11+
require(
12+
['Magento_AuthorizenetAcceptjs/js/payment-form'],
13+
function(Authorizenet) {
14+
var config = <?= /* @noEscape */ $block->getPaymentConfig() ?>,
15+
form = "#payment_form_<?= $block->escapeJs($block->escapeHtml($block->getMethodCode())) ?>";
16+
17+
new Authorizenet(config, form);
18+
});
19+
//]]>
20+
</script>

app/code/Magento/AuthorizenetAcceptjs/view/adminhtml/web/js/payment-form.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ define([
88
], function (AuthorizenetAcceptjs, $) {
99
'use strict';
1010

11-
return function (data, element) {
12-
var $form = $(element),
13-
config = data.config;
11+
return function (config, element) {
12+
var $form = $(element);
1413

1514
config.active = $form.length > 0 && !$form.is(':hidden');
1615
new AuthorizenetAcceptjs(config);

app/code/Magento/Config/Controller/Adminhtml/System/AbstractConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function _isAllowed()
7777
{
7878
$sectionId = $this->_request->getParam('section');
7979
return parent::_isAllowed()
80-
&& $this->_configStructure->getElement($sectionId)->isAllowed();
80+
|| $this->_configStructure->getElement($sectionId)->isAllowed();
8181
}
8282

8383
/**

app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,68 @@ public function __construct(
5656
$this->string = $string;
5757
}
5858

59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function _isAllowed()
63+
{
64+
return parent::_isAllowed() && $this->isSectionAllowed();
65+
}
66+
67+
/**
68+
* Checks if user has access to section.
69+
*
70+
* @return bool
71+
*/
72+
private function isSectionAllowed(): bool
73+
{
74+
$sectionId = $this->_request->getParam('section');
75+
$isAllowed = $this->_configStructure->getElement($sectionId)->isAllowed();
76+
if (!$isAllowed) {
77+
$groups = $this->getRequest()->getPost('groups');
78+
$fieldPath = $this->getFirstFieldPath($groups, $sectionId);
79+
80+
$fieldPaths = $this->_configStructure->getFieldPaths();
81+
$fieldPath = $fieldPaths[$fieldPath][0] ?? $sectionId;
82+
$explodedConfigPath = explode('/', $fieldPath);
83+
$configSectionId = $explodedConfigPath[0] ?? $sectionId;
84+
85+
$isAllowed = $this->_configStructure->getElement($configSectionId)->isAllowed();
86+
}
87+
88+
return $isAllowed;
89+
}
90+
91+
/**
92+
* Return field path as string.
93+
*
94+
* @param array $elements
95+
* @param string $fieldPath
96+
* @return string
97+
*/
98+
private function getFirstFieldPath(array $elements, string $fieldPath): string
99+
{
100+
$groupData = [];
101+
foreach ($elements as $elementName => $element) {
102+
if (!empty($element)) {
103+
$fieldPath .= '/' . $elementName;
104+
105+
if (!empty($element['fields'])) {
106+
$groupData = $element['fields'];
107+
} elseif (!empty($element['groups'])) {
108+
$groupData = $element['groups'];
109+
}
110+
111+
if (!empty($groupData)) {
112+
$fieldPath = $this->getFirstFieldPath($groupData, $fieldPath);
113+
}
114+
break;
115+
}
116+
}
117+
118+
return $fieldPath;
119+
}
120+
59121
/**
60122
* Get groups for save
61123
*

app/code/Magento/Ups/view/adminhtml/templates/system/shipping/carrier_config.phtml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ require(["prototype"], function(){
6767
upsXml.prototype = {
6868
initialize: function()
6969
{
70+
this.carriersUpsActiveId = 'carriers_ups_active';
7071
this.carriersUpsTypeId = 'carriers_ups_type';
7172
if (!$(this.carriersUpsTypeId)) {
7273
return;
@@ -94,6 +95,7 @@ require(["prototype"], function(){
9495

9596
this.setFormValues();
9697
Event.observe($(this.carriersUpsTypeId), 'change', this.setFormValues.bind(this));
98+
Event.observe($(this.carriersUpsActiveId), 'change', this.setFormValues.bind(this));
9799
},
98100
updateAllowedMethods: function(originShipmentTitle)
99101
{
@@ -148,7 +150,8 @@ require(["prototype"], function(){
148150
$(this.checkingUpsXmlId[a]).removeClassName('required-entry');
149151
}
150152
for (a = 0; a < this.checkingUpsId.length; a++) {
151-
$(this.checkingUpsXmlId[a]).addClassName('required-entry');
153+
$(this.checkingUpsId[a]).addClassName('required-entry');
154+
this.changeFieldsDisabledState(this.checkingUpsId, a);
152155
}
153156
Event.stopObserving($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
154157
showRowArrayElements(this.onlyUpsElements);
@@ -157,9 +160,10 @@ require(["prototype"], function(){
157160
} else {
158161
for (a = 0; a < this.checkingUpsXmlId.length; a++) {
159162
$(this.checkingUpsXmlId[a]).addClassName('required-entry');
163+
this.changeFieldsDisabledState(this.checkingUpsXmlId, a);
160164
}
161165
for (a = 0; a < this.checkingUpsId.length; a++) {
162-
$(this.checkingUpsXmlId[a]).removeClassName('required-entry');
166+
$(this.checkingUpsId[a]).removeClassName('required-entry');
163167
}
164168
Event.observe($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
165169
showRowArrayElements(this.onlyUpsXmlElements);
@@ -171,6 +175,16 @@ require(["prototype"], function(){
171175
{
172176
this.originShipmentTitle = key ? key : $F('carriers_ups_origin_shipment');
173177
this.updateAllowedMethods(this.originShipmentTitle);
178+
},
179+
changeFieldsDisabledState: function (fields, key) {
180+
$(fields[key]).disabled = $F(this.carriersUpsActiveId) !== '1'
181+
|| $(fields[key] + '_inherit') !== null
182+
&& $F(fields[key] + '_inherit') === '1';
183+
184+
if ($(fields[key]).next() !== undefined) {
185+
$(fields[key]).removeClassName('mage-error').next().remove();
186+
$(fields[key]).removeAttribute('style');
187+
}
174188
}
175189
};
176190
xml = new upsXml();

dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertCancelSuccessMessageInShoppingCart.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Checkout\Test\Page\CheckoutCart;
1010
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Mtf\Client\BrowserInterface;
1112

1213
/**
1314
* Assert that success message about canceled order is present and correct.
@@ -23,10 +24,18 @@ class AssertCancelSuccessMessageInShoppingCart extends AbstractConstraint
2324
* Assert that success message about canceled order is present and correct.
2425
*
2526
* @param CheckoutCart $checkoutCart
27+
* @param BrowserInterface $browser
2628
* @return void
2729
*/
28-
public function processAssert(CheckoutCart $checkoutCart)
30+
public function processAssert(CheckoutCart $checkoutCart, BrowserInterface $browser)
2931
{
32+
$path = $checkoutCart::MCA;
33+
$browser->waitUntil(
34+
function () use ($browser, $path) {
35+
return $_ENV['app_frontend_url'] . $path . '/' === $browser->getUrl() . 'index/' ? true : null;
36+
}
37+
);
38+
3039
$actualMessage = $checkoutCart->getMessagesBlock()->getSuccessMessage();
3140
\PHPUnit\Framework\Assert::assertEquals(
3241
self::SUCCESS_MESSAGE,

dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/OnePageCheckoutDeclinedTest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<data name="payment/method" xsi:type="string">payflowpro</data>
1919
<data name="creditCard/dataset" xsi:type="string">visa_default</data>
2020
<data name="configData" xsi:type="string">payflowpro, payflowpro_avs_street_does_not_match</data>
21-
<data name="expectedErrorMessage" xsi:type="string">A server error stopped your order from being placed. Please try to place your order again.</data>
21+
<data name="expectedErrorMessage" xsi:type="string">Transaction has been declined</data>
2222
<constraint name="Magento\Checkout\Test\Constraint\AssertCheckoutErrorMessage" />
2323
</variation>
2424
<variation name="OnePageCheckoutDeclinedTestWithAVSZIP" summary="Place order via Payflow Pro with AVS ZIP verification fail" ticketId="MAGETWO-37483">
@@ -30,7 +30,7 @@
3030
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
3131
<data name="payment/method" xsi:type="string">payflowpro</data>
3232
<data name="creditCard/dataset" xsi:type="string">visa_default</data>
33-
<data name="expectedErrorMessage" xsi:type="string">A server error stopped your order from being placed. Please try to place your order again.</data>
33+
<data name="expectedErrorMessage" xsi:type="string">Transaction has been declined</data>
3434
<data name="configData" xsi:type="string">payflowpro, payflowpro_use_avs_zip</data>
3535
<data name="tag" xsi:type="string">test_type:3rd_party_test, severity:S1</data>
3636
<constraint name="Magento\Checkout\Test\Constraint\AssertCheckoutErrorMessage" />
@@ -46,7 +46,7 @@
4646
<data name="payment/method" xsi:type="string">payflowpro</data>
4747
<data name="creditCard/dataset" xsi:type="string">visa_cvv_mismatch</data>
4848
<data name="configData" xsi:type="string">payflowpro, payflowpro_avs_security_code_does_not_match</data>
49-
<data name="expectedErrorMessage" xsi:type="string">A server error stopped your order from being placed. Please try to place your order again.</data>
49+
<data name="expectedErrorMessage" xsi:type="string">Transaction has been declined</data>
5050
<constraint name="Magento\Checkout\Test\Constraint\AssertCheckoutErrorMessage" />
5151
</variation>
5252
</testCase>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Paypal\Controller\Adminhtml\System;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* @magentoAppArea adminhtml
16+
*/
17+
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
18+
{
19+
/**
20+
* @magentoAppIsolation enabled
21+
* @magentoDbIsolation enabled
22+
*
23+
* @dataProvider saveMerchantCountryDataProvider
24+
*
25+
* @param string $section
26+
* @param array $groups
27+
* @return void
28+
*/
29+
public function testSaveMerchantCountry(string $section, array $groups): void
30+
{
31+
/** @var ScopeConfigInterface $scopeConfig */
32+
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
33+
34+
$request = $this->getRequest();
35+
$request->setPostValue($groups)
36+
->setParam('section', $section)
37+
->setMethod(HttpRequest::METHOD_POST);
38+
39+
$this->dispatch('backend/admin/system_config/save');
40+
41+
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
42+
43+
$this->assertEquals(
44+
'GB',
45+
$scopeConfig->getValue('paypal/general/merchant_country')
46+
);
47+
}
48+
49+
/**
50+
* @return array
51+
*/
52+
public function saveMerchantCountryDataProvider(): array
53+
{
54+
return [
55+
[
56+
'section' => 'paypal',
57+
'groups' => [
58+
'groups' => [
59+
'general' => [
60+
'fields' => [
61+
'merchant_country' => ['value' => 'GB'],
62+
],
63+
],
64+
],
65+
],
66+
],
67+
[
68+
'section' => 'payment',
69+
'groups' => [
70+
'groups' => [
71+
'account' => [
72+
'fields' => [
73+
'merchant_country' => ['value' => 'GB'],
74+
],
75+
],
76+
],
77+
],
78+
],
79+
];
80+
}
81+
}

0 commit comments

Comments
 (0)