Skip to content

Commit 52adb75

Browse files
committed
Merge branch 'MAGETWO-55676' into MPI-PR
2 parents 114f480 + 4c7f8ec commit 52adb75

File tree

49 files changed

+2939
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2939
-406
lines changed

app/code/Magento/Braintree/etc/adminhtml/system.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
99
<system>
1010
<section id="payment">
11-
<group id="braintree_section" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
12-
<label>Braintree</label>
13-
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store. No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
14-
<attribute type="expanded">1</attribute>
15-
<fieldset_css>complex braintree-section</fieldset_css>
16-
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group</frontend_model>
17-
<group id="braintree" translate="label" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
18-
<label><![CDATA[&nbsp;]]></label>
11+
<group id="braintree_section" sortOrder="6" showInDefault="0" showInWebsite="0" showInStore="0">
12+
<group id="braintree" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
13+
<label>Braintree</label>
14+
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
15+
<fieldset_css>complex braintree-section</fieldset_css>
1916
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
2017
<attribute type="activity_path">payment/braintree/active</attribute>
21-
<more_url>https://articles.braintreepayments.com/guides/magento/configuration</more_url>
18+
<attribute type="displayIn">recommended_solutions</attribute>
2219
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
2320
<label>Enable this Solution</label>
2421
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
@@ -43,8 +40,11 @@
4340
<group id="braintree_required"/>
4441
</requires>
4542
</field>
43+
<group id="configuration_details" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="4">
44+
<comment>http://docs.magento.com/m2/ce/user_guide/payment/braintree.html</comment>
45+
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint</frontend_model>
46+
</group>
4647
<group id="braintree_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="5">
47-
<comment><![CDATA[<a href="https://www.braintreegateway.com/login" target="_blank">Click here to login to your existing Braintree account</a>. Or to setup a new account and accept payments on your website, <a href="https://apply.braintreegateway.com/signup/us" target="_blank">click here to signup for a Braintree account</a>.<br><br>Powered by <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Braintree v.zero with Hosted Fields</a> latest technology. Hosted Fields are small, transparent iframes that replace the sensitive credit card inputs in your checkout flow - helping you meet the latest data security requirements while ensuring your customization doesn't suffer. <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Find out more</a>.]]></comment>
4848
<label>Basic Braintree Settings</label>
4949
<attribute type="expanded">1</attribute>
5050
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>

app/code/Magento/Braintree/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,5 @@ Debug,Debug
164164
"europe_bank_accout","Europe bank account"
165165
"credit_card","Credit card"
166166
"apple_pay_card","Apple pay card"
167-
"android_pay_card","Android pay card"
167+
"android_pay_card","Android pay card"
168+
"Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase.","Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase."

app/code/Magento/Braintree/view/adminhtml/web/styles.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
.braintree-section .entry-edit-head > .config-heading .heading strong {padding-left:150px;background:url(images/braintree_logo.png) no-repeat 0 0 / 145px auto;line-height:36px;}
7-
.braintree-section .entry-edit-head > .config-heading:before {background: url("images/braintree_allinone.png") no-repeat 0 0 / 100% auto;content: "";display: inline;float: right;height: 35px;width: 280px;}
6+
.braintree-section .heading {display: inline-block; background: url("images/braintree_logo.png") no-repeat 0 50% / 18rem auto; padding-left: 20rem;}
7+
.braintree-section .button-container {display: inline-block; float: right;}
8+
.braintree-section .config-alt {background: url("images/braintree_allinone.png") no-repeat scroll 0 0 / 100% auto; height: 28px; margin: 0.5rem 0 0; width: 230px;}

app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Hint.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,42 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
namespace Magento\Paypal\Block\Adminhtml\System\Config\Fieldset;
107

8+
use Magento\Backend\Block\Template;
9+
use Magento\Framework\Data\Form\Element\AbstractElement;
10+
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
11+
1112
/**
12-
* Renderer for PayPal banner in System Configuration
13-
* @author Magento Core Team <core@magentocommerce.com>
13+
* Class Hint adds "Configuration Details" link to payment configuration.
14+
* `<comment>` node must be defined in `<group>` node and contain some link.
1415
*/
15-
class Hint extends \Magento\Backend\Block\Template implements \Magento\Framework\Data\Form\Element\Renderer\RendererInterface
16+
class Hint extends Template implements RendererInterface
1617
{
1718
/**
1819
* @var string
20+
* @deprecated
1921
*/
2022
protected $_template = 'Magento_Paypal::system/config/fieldset/hint.phtml';
2123

2224
/**
23-
* Render fieldset html
24-
*
25-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
25+
* @param AbstractElement $element
2626
* @return string
2727
*/
28-
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
28+
public function render(AbstractElement $element)
2929
{
30-
$elementOriginalData = $element->getOriginalData();
31-
if (isset($elementOriginalData['help_link'])) {
32-
$this->setHelpLink($elementOriginalData['help_link']);
30+
$html = '';
31+
32+
if ($element->getComment()) {
33+
$html .= sprintf('<tr id="row_%s">', $element->getHtmlId());
34+
$html .= '<td colspan="1"><p class="note"><span>';
35+
$html .= sprintf(
36+
'<a href="%s" target="_blank">Configuration Details</a>',
37+
$element->getComment()
38+
);
39+
$html .= '</span></p></td></tr>';
3340
}
34-
return $this->toHtml();
41+
42+
return $html;
3543
}
3644
}

app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Payment.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ protected function _getHeaderTitleHtml($element)
8787
if ($element->getComment()) {
8888
$html .= '<span class="heading-intro">' . $element->getComment() . '</span>';
8989
}
90+
$html .= '<div class="config-alt"></div>';
9091
$html .= '</div>';
9192

9293
$disabledAttributeString = $this->_isPaymentEnabled($element) ? '' : ' disabled="disabled"';
@@ -149,4 +150,33 @@ protected function _isCollapseState($element)
149150
{
150151
return false;
151152
}
153+
154+
/**
155+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
156+
* @return string
157+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
158+
*/
159+
protected function _getExtraJs($element)
160+
{
161+
$script = "require(['jquery', 'prototype'], function(jQuery){
162+
window.paypalToggleSolution = function (id, url) {
163+
var doScroll = false;
164+
Fieldset.toggleCollapse(id, url);
165+
if ($(this).hasClassName(\"open\")) {
166+
$$(\".with-button button.button\").each(function(anotherButton) {
167+
if (anotherButton != this && $(anotherButton).hasClassName(\"open\")) {
168+
$(anotherButton).click();
169+
doScroll = true;
170+
}
171+
}.bind(this));
172+
}
173+
if (doScroll) {
174+
var pos = Element.cumulativeOffset($(this));
175+
window.scrollTo(pos[0], pos[1] - 45);
176+
}
177+
}
178+
});";
179+
180+
return $this->_jsHelper->getScript($script);
181+
}
152182
}

app/code/Magento/Paypal/Model/Config/StructurePlugin.php

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Paypal\Model\Config;
77

8+
use Magento\Config\Model\Config\ScopeDefiner;
9+
use Magento\Config\Model\Config\Structure;
10+
use Magento\Config\Model\Config\Structure\Element\Section;
11+
use Magento\Config\Model\Config\Structure\ElementInterface;
12+
use Magento\Paypal\Helper\Backend as BackendHelper;
13+
814
class StructurePlugin
915
{
1016
/**
@@ -13,12 +19,12 @@ class StructurePlugin
1319
const REQUEST_PARAM_COUNTRY = 'paypal_country';
1420

1521
/**
16-
* @var \Magento\Paypal\Helper\Backend
22+
* @var BackendHelper
1723
*/
1824
protected $_helper;
1925

2026
/**
21-
* @var \Magento\Config\Model\Config\ScopeDefiner
27+
* @var ScopeDefiner
2228
*/
2329
protected $_scopeDefiner;
2430

@@ -40,12 +46,12 @@ class StructurePlugin
4046
];
4147

4248
/**
43-
* @param \Magento\Config\Model\Config\ScopeDefiner $scopeDefiner
44-
* @param \Magento\Paypal\Helper\Backend $helper
49+
* @param ScopeDefiner $scopeDefiner
50+
* @param BackendHelper $helper
4551
*/
4652
public function __construct(
47-
\Magento\Config\Model\Config\ScopeDefiner $scopeDefiner,
48-
\Magento\Paypal\Helper\Backend $helper
53+
ScopeDefiner $scopeDefiner,
54+
BackendHelper $helper
4955
) {
5056
$this->_scopeDefiner = $scopeDefiner;
5157
$this->_helper = $helper;
@@ -69,14 +75,14 @@ public static function getPaypalConfigCountries($addOther = false)
6975
/**
7076
* Substitute payment section with PayPal configs
7177
*
72-
* @param \Magento\Config\Model\Config\Structure $subject
78+
* @param Structure $subject
7379
* @param \Closure $proceed
7480
* @param array $pathParts
75-
* @return \Magento\Config\Model\Config\Structure\ElementInterface
81+
* @return ElementInterface
7682
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7783
*/
7884
public function aroundGetElementByPathParts(
79-
\Magento\Config\Model\Config\Structure $subject,
85+
Structure $subject,
8086
\Closure $proceed,
8187
array $pathParts
8288
) {
@@ -89,10 +95,11 @@ public function aroundGetElementByPathParts(
8995
$pathParts[0] = 'payment_other';
9096
}
9197
}
92-
/** @var \Magento\Config\Model\Config\Structure\ElementInterface $result */
98+
/** @var ElementInterface $result */
9399
$result = $proceed($pathParts);
94100
if ($isSectionChanged && isset($result)) {
95-
if ($result instanceof \Magento\Config\Model\Config\Structure\Element\Section) {
101+
if ($result instanceof Section) {
102+
$this->restructurePayments($result);
96103
$result->setData(array_merge(
97104
$result->getData(),
98105
['showInDefault' => true, 'showInWebsite' => true, 'showInStore' => true]
@@ -101,4 +108,63 @@ public function aroundGetElementByPathParts(
101108
}
102109
return $result;
103110
}
111+
112+
/**
113+
* Changes payment config structure.
114+
* Groups which have `displayIn` element, transfer to appropriate group.
115+
* Groups without `displayIn` transfer to other payment methods group.
116+
*
117+
* @param Section $result
118+
* @return void
119+
*/
120+
private function restructurePayments(Section $result)
121+
{
122+
$sectionMap = [
123+
'account' => [],
124+
'recommended_solutions' => [],
125+
'other_paypal_payment_solutions' => [],
126+
'other_payment_methods' => []
127+
];
128+
129+
$configuration = $result->getData();
130+
131+
foreach ($configuration['children'] as $section => $data) {
132+
if (array_key_exists($section, $sectionMap)) {
133+
$sectionMap[$section] = $data;
134+
} elseif ($displayIn = $this->getDisplayInSection($section, $data)) {
135+
$sectionMap[$displayIn['parent']]['children'][$displayIn['section']] = $displayIn['data'];
136+
} else {
137+
$sectionMap['other_payment_methods']['children'][$section] = $data;
138+
}
139+
}
140+
141+
$configuration['children'] = $sectionMap;
142+
$result->setData($configuration, $this->_scopeDefiner->getScope());
143+
}
144+
145+
/**
146+
* Recursive search of `displayIn` element in node children
147+
*
148+
* @param string $section
149+
* @param array $data
150+
* @return array|null
151+
*/
152+
private function getDisplayInSection($section, $data)
153+
{
154+
if (is_array($data) && array_key_exists('displayIn', $data)) {
155+
return [
156+
'parent' => $data['displayIn'],
157+
'section' => $section,
158+
'data' => $data
159+
];
160+
}
161+
162+
if (array_key_exists('children', $data)) {
163+
foreach ($data['children'] as $childSection => $childData) {
164+
return $this->getDisplayInSection($childSection, $childData);
165+
}
166+
}
167+
168+
return null;
169+
}
104170
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Test\Unit\Block\Adminhtml\System\Config\Fieldset;
7+
8+
use Magento\Framework\Data\Form\Element\AbstractElement;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
12+
13+
/**
14+
* Class HintTest
15+
*/
16+
class HintTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var Hint
20+
*/
21+
private $block;
22+
23+
/**
24+
* @var AbstractElement|MockObject
25+
*/
26+
private $element;
27+
28+
protected function setUp()
29+
{
30+
$om = new ObjectManager($this);
31+
32+
$this->element = $this->getMockBuilder(AbstractElement::class)
33+
->setMethods(['getComment', 'getHtmlId'])
34+
->disableOriginalConstructor()
35+
->getMockForAbstractClass();
36+
37+
$this->block = $om->getObject(Hint::class);
38+
}
39+
40+
/**
41+
* @covers \Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint::render
42+
*/
43+
public function testRender()
44+
{
45+
$expected = '<tr id="row_payment"><td colspan="1"><p class="note"><span>';
46+
$expected .= '<a href="http://test.com" target="_blank">Configuration Details</a>';
47+
$expected .= '</span></p></td></tr>';
48+
49+
$this->element->expects(static::exactly(2))
50+
->method('getComment')
51+
->willReturn('http://test.com');
52+
53+
$this->element->expects(static::once())
54+
->method('getHtmlId')
55+
->willReturn('payment');
56+
57+
static::assertSame($expected, $this->block->render($this->element));
58+
}
59+
60+
/**
61+
* @covers \Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint::render
62+
*/
63+
public function testRenderEmptyComment()
64+
{
65+
$this->element->expects(static::once())
66+
->method('getComment')
67+
->willReturn('');
68+
69+
$this->element->expects(static::never())
70+
->method('getHtmlId');
71+
72+
static::assertSame('', $this->block->render($this->element));
73+
}
74+
}

0 commit comments

Comments
 (0)