Skip to content

Commit 5d4f74d

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-pr27
2 parents 713f6c4 + d7aafe9 commit 5d4f74d

File tree

8 files changed

+142
-32
lines changed

8 files changed

+142
-32
lines changed

app/code/Magento/Backend/Block/Widget/Tabs.php

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function addTab($tabId, $tab)
117117
if (empty($tabId)) {
118118
throw new \Exception(__('Please correct the tab configuration and try again. Tab Id should be not empty'));
119119
}
120+
120121
if (is_array($tab)) {
121122
$this->_tabs[$tabId] = new \Magento\Framework\DataObject($tab);
122123
} elseif ($tab instanceof \Magento\Framework\DataObject) {
@@ -126,13 +127,15 @@ public function addTab($tabId, $tab)
126127
}
127128
} elseif (is_string($tab)) {
128129
$this->_addTabByName($tab, $tabId);
130+
129131
if (!$this->_tabs[$tabId] instanceof TabInterface) {
130132
unset($this->_tabs[$tabId]);
131133
return $this;
132134
}
133135
} else {
134136
throw new \Exception(__('Please correct the tab configuration and try again.'));
135137
}
138+
136139
if ($this->_tabs[$tabId]->getUrl() === null) {
137140
$this->_tabs[$tabId]->setUrl('#');
138141
}
@@ -143,10 +146,7 @@ public function addTab($tabId, $tab)
143146

144147
$this->_tabs[$tabId]->setId($tabId);
145148
$this->_tabs[$tabId]->setTabId($tabId);
146-
147-
if ($this->_activeTab === null) {
148-
$this->_activeTab = $tabId;
149-
}
149+
150150
if (true === $this->_tabs[$tabId]->getActive()) {
151151
$this->setActiveTab($tabId);
152152
}
@@ -235,33 +235,108 @@ protected function _setActiveTab($tabId)
235235
*/
236236
protected function _beforeToHtml()
237237
{
238+
$this->_tabs = $this->reorderTabs();
239+
238240
if ($activeTab = $this->getRequest()->getParam('active_tab')) {
239241
$this->setActiveTab($activeTab);
240242
} elseif ($activeTabId = $this->_authSession->getActiveTabId()) {
241243
$this->_setActiveTab($activeTabId);
242244
}
243245

244-
$_new = [];
246+
if ($this->_activeTab === null && !empty($this->_tabs)) {
247+
/** @var TabInterface $tab */
248+
$this->_activeTab = (reset($this->_tabs))->getId();
249+
}
250+
251+
$this->assign('tabs', $this->_tabs);
252+
return parent::_beforeToHtml();
253+
}
254+
255+
/**
256+
* Reorder the tabs.
257+
*
258+
* @return array
259+
*/
260+
private function reorderTabs()
261+
{
262+
$orderByIdentity = [];
263+
$orderByPosition = [];
264+
$position = 100;
265+
266+
/**
267+
* Set the initial positions for each tab.
268+
*
269+
* @var string $key
270+
* @var TabInterface $tab
271+
*/
245272
foreach ($this->_tabs as $key => $tab) {
246-
foreach ($this->_tabs as $k => $t) {
247-
if ($t->getAfter() == $key) {
248-
$_new[$key] = $tab;
249-
$_new[$k] = $t;
250-
} else {
251-
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($this->_tabs))) {
252-
$_new[$key] = $tab;
253-
}
254-
}
255-
}
273+
$tab->setPosition($position);
274+
275+
$orderByIdentity[$key] = $tab;
276+
$orderByPosition[$position] = $tab;
277+
278+
$position += 100;
256279
}
257280

258-
$this->_tabs = $_new;
259-
unset($_new);
281+
return $this->applyTabsCorrectOrder($orderByPosition, $orderByIdentity);
282+
}
260283

261-
$this->assign('tabs', $this->_tabs);
262-
return parent::_beforeToHtml();
284+
/**
285+
* @param array $orderByPosition
286+
* @param array $orderByIdentity
287+
*
288+
* @return array
289+
*/
290+
private function applyTabsCorrectOrder(array $orderByPosition, array $orderByIdentity)
291+
{
292+
$positionFactor = 1;
293+
294+
/**
295+
* Rearrange the positions by using the after tag for each tab.
296+
*
297+
* @var integer $position
298+
* @var TabInterface $tab
299+
*/
300+
foreach ($orderByPosition as $position => $tab) {
301+
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($orderByIdentity))) {
302+
$positionFactor = 1;
303+
continue;
304+
}
305+
306+
$grandPosition = $orderByIdentity[$tab->getAfter()]->getPosition();
307+
$newPosition = $grandPosition + $positionFactor;
308+
309+
unset($orderByPosition[$position]);
310+
$orderByPosition[$newPosition] = $tab;
311+
$tab->setPosition($newPosition);
312+
313+
$positionFactor++;
314+
}
315+
316+
return $this->finalTabsSortOrder($orderByPosition);
263317
}
264318

319+
/**
320+
* Apply the last sort order to tabs.
321+
*
322+
* @param array $orderByPosition
323+
*
324+
* @return array
325+
*/
326+
private function finalTabsSortOrder(array $orderByPosition)
327+
{
328+
ksort($orderByPosition);
329+
330+
$ordered = [];
331+
332+
/** @var TabInterface $tab */
333+
foreach ($orderByPosition as $tab) {
334+
$ordered[$tab->getId()] = $tab;
335+
}
336+
337+
return $ordered;
338+
}
339+
265340
/**
266341
* @return string
267342
*/

app/code/Magento/Catalog/ViewModel/Product/Breadcrumbs.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
use Magento\Catalog\Helper\Data;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\DataObject;
14+
use Magento\Framework\Serialize\Serializer\Json;
1315
use Magento\Framework\View\Element\Block\ArgumentInterface;
16+
use Magento\Framework\Escaper;
1417

1518
/**
1619
* Product breadcrumbs view model.
@@ -29,18 +32,34 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
2932
*/
3033
private $scopeConfig;
3134

35+
/**
36+
* @var Json
37+
*/
38+
private $json;
39+
40+
/**
41+
* @var Escaper
42+
*/
43+
private $escaper;
44+
3245
/**
3346
* @param Data $catalogData
3447
* @param ScopeConfigInterface $scopeConfig
48+
* @param Json|null $json
49+
* @param Escaper|null $escaper
3550
*/
3651
public function __construct(
3752
Data $catalogData,
38-
ScopeConfigInterface $scopeConfig
53+
ScopeConfigInterface $scopeConfig,
54+
Json $json = null,
55+
Escaper $escaper = null
3956
) {
4057
parent::__construct();
4158

4259
$this->catalogData = $catalogData;
4360
$this->scopeConfig = $scopeConfig;
61+
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
62+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
4463
}
4564

4665
/**
@@ -80,4 +99,22 @@ public function getProductName(): string
8099
? $this->catalogData->getProduct()->getName()
81100
: '';
82101
}
102+
103+
/**
104+
* Returns breadcrumb json.
105+
*
106+
* @return string
107+
*/
108+
public function getJsonConfiguration()
109+
{
110+
return $this->json->serialize(
111+
[
112+
'breadcrumbs' => [
113+
'categoryUrlSuffix' => $this->escaper->escapeHtml($this->getCategoryUrlSuffix()),
114+
'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(),
115+
'product' => $this->escaper->escapeHtml($this->escaper->escapeJs($this->getProductName()))
116+
]
117+
]
118+
);
119+
}
83120
}

app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,4 @@
77
/** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */
88
$viewModel = $block->getData('viewModel');
99
?>
10-
<div class="breadcrumbs" data-mage-init='{
11-
"breadcrumbs": {
12-
"categoryUrlSuffix": "<?= $block->escapeHtml($viewModel->getCategoryUrlSuffix()); ?>",
13-
"useCategoryPathInUrl": <?= (int)$viewModel->isCategoryUsedInProductUrl(); ?>,
14-
"product": "<?= $block->escapeHtml($block->escapeJs($viewModel->getProductName())); ?>"
15-
}
16-
}'>
17-
</div>
10+
<div class="breadcrumbs" data-mage-init='<?= /* @escapeNotVerified */ $viewModel->getJsonConfiguration() ?>'></div>

app/code/Magento/Checkout/view/frontend/web/template/billing-address/form.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<!-- ko template: getTemplate() --><!-- /ko -->
1010
<!--/ko-->
1111
<form data-bind="attr: {'data-hasrequired': $t('* Required Fields')}">
12-
<fieldset id="billing-new-address-form" class="fieldset address">
12+
<fieldset data-bind="attr: { id:'billing-new-address-form-'+index, value:index}"
13+
class="billing-new-address-form fieldset address">
1314
<!-- ko foreach: getRegion('additional-fieldsets') -->
1415
<!-- ko template: getTemplate() --><!-- /ko -->
1516
<!--/ko-->

app/code/Magento/Sales/Block/Order/History.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class History extends \Magento\Framework\View\Element\Template
1919
/**
2020
* @var string
2121
*/
22-
protected $_template = 'order/history.phtml';
22+
protected $_template = 'Magento_Sales::order/history.phtml';
2323

2424
/**
2525
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Wishlist\Model;
79

810
use Magento\Catalog\Api\ProductRepositoryInterface;
@@ -215,7 +217,7 @@ public function loadByCustomerId($customerId, $create = false)
215217
public function getName()
216218
{
217219
$name = $this->_getData('name');
218-
if (!strlen($name)) {
220+
if ($name === null || !strlen($name)) {
219221
return $this->_wishlistData->getDefaultWishlistName();
220222
}
221223
return $name;
@@ -637,6 +639,7 @@ public function updateItem($itemId, $buyRequest, $params = null)
637639
$item = null;
638640
if ($itemId instanceof Item) {
639641
$item = $itemId;
642+
$itemId = $item->getId();
640643
} else {
641644
$item = $this->getItem((int)$itemId);
642645
}

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Checkout/Section/CheckoutPaymentSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<element name="isPaymentSection" type="text" selector="//*[@class='opc-progress-bar']/li[contains(@class, '_active') and span[contains(.,'Review &amp; Payments')]]"/>
1313
<element name="availablePaymentSolutions" type="text" selector="#checkout-payment-method-load>div>div>div:nth-child(2)>div.payment-method-title.field.choice"/>
1414
<element name="notAvailablePaymentSolutions" type="text" selector="#checkout-payment-method-load>div>div>div.payment-method._active>div.payment-method-title.field.choice"/>
15-
<element name="billingNewAddressForm" type="text" selector="#billing-new-address-form"/>
15+
<element name="billingNewAddressForm" type="text" selector=".billing-new-address-form"/>
1616
<element name="placeOrderDisabled" type="button" selector="#checkout-payment-method-load button.disabled"/>
1717
<element name="update" type="button" selector=".payment-method-billing-address .action.action-update"/>
1818
<element name="guestFirstName" type="input" selector=".billing-address-form input[name*='firstname']"/>

dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,4 @@ IntegrationConfig.php
201201
setup/performance-toolkit/aggregate-report
202202
Magento/MessageQueue/Setup
203203
Magento/Elasticsearch/Elasticsearch5
204+
Test/_files

0 commit comments

Comments
 (0)