Skip to content

Commit aae2808

Browse files
authored
ENGCOM-3430: #4154 - There is no ability to add a tab to product page at a desired position #19007
2 parents 088bc10 + cc4e9e2 commit aae2808

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Block\Product\View;
10+
11+
/**
12+
* Product details block.
13+
*
14+
* Holds a group of blocks to show as tabs.
15+
*
16+
* @api
17+
*/
18+
class Details extends \Magento\Framework\View\Element\Template
19+
{
20+
/**
21+
* Get sorted child block names.
22+
*
23+
* @param string $groupName
24+
* @param string $callback
25+
* @throws \Magento\Framework\Exception\LocalizedException
26+
*
27+
* @return array
28+
*/
29+
public function getGroupSortedChildNames(string $groupName, string $callback): array
30+
{
31+
$groupChildNames = $this->getGroupChildNames($groupName, $callback);
32+
$layout = $this->getLayout();
33+
34+
$childNamesSortOrder = [];
35+
36+
foreach ($groupChildNames as $childName) {
37+
$alias = $layout->getElementAlias($childName);
38+
$sortOrder = (int)$this->getChildData($alias, 'sort_order') ?? 0;
39+
40+
$childNamesSortOrder[$sortOrder] = $childName;
41+
}
42+
43+
ksort($childNamesSortOrder, SORT_NUMERIC);
44+
45+
return $childNamesSortOrder;
46+
}
47+
}

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@
136136
</arguments>
137137
</block>
138138
</container>
139-
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.details" template="Magento_Catalog::product/view/details.phtml" after="product.info.media">
139+
<block class="Magento\Catalog\Block\Product\View\Details" name="product.info.details" template="Magento_Catalog::product/view/details.phtml" after="product.info.media">
140140
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.description" as="description" template="Magento_Catalog::product/view/attribute.phtml" group="detailed_info">
141141
<arguments>
142142
<argument name="at_call" xsi:type="string">getDescription</argument>
143143
<argument name="at_code" xsi:type="string">description</argument>
144144
<argument name="css_class" xsi:type="string">description</argument>
145145
<argument name="at_label" xsi:type="string">none</argument>
146146
<argument name="title" translate="true" xsi:type="string">Details</argument>
147+
<argument name="sort_order" xsi:type="string">10</argument>
147148
</arguments>
148149
</block>
149150
<block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" as="additional" template="Magento_Catalog::product/view/attributes.phtml" group="detailed_info">
150151
<arguments>
151152
<argument translate="true" name="title" xsi:type="string">More Information</argument>
153+
<argument name="sort_order" xsi:type="string">20</argument>
152154
</arguments>
153155
</block>
154156
</block>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
// @codingStandardsIgnoreFile
88

9+
/** @var \Magento\Catalog\Block\Product\View\Details $block */
910
?>
10-
<?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):?>
11+
<?php if ($detailedInfoGroup = $block->getGroupSortedChildNames('detailed_info', 'getChildHtml')):?>
1112
<div class="product info detailed">
1213
<?php $layout = $block->getLayout(); ?>
1314
<div class="product data items" data-mage-init='{"tabs":{"openedState":"active"}}'>

app/code/Magento/Review/view/frontend/layout/catalog_product_view.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
</referenceContainer>
2020
<referenceBlock name="product.info.details">
2121
<block class="Magento\Review\Block\Product\Review" name="reviews.tab" as="reviews" template="Magento_Review::review.phtml" group="detailed_info" ifconfig="catalog/review/active">
22+
<arguments>
23+
<argument name="sort_order" xsi:type="string">30</argument>
24+
</arguments>
2225
<block class="Magento\Review\Block\Form" name="product.review.form" as="review_form" ifconfig="catalog/review/active">
2326
<container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>
2427
</block>

0 commit comments

Comments
 (0)