How to rename the product detail tab title, and display as the last tab? This is what i added, but didn't make any effect. the file is at the following location:
/app/design/frontend/Infortis/ultimo/Amasty_Faq/layout/catalog_product_view.xml
I added:
<action method="setTitle">
<argument name="title" xsi:type="string">Q>A</argument>
</action>
and
<move element="amasty_faq_product_tab" destination="product.info.details" after="-" />
to the original xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="Amasty_Faq::js/section/product-url.js"/>
</head>
<body>
<referenceBlock name="product.info.details">
<block class="Amasty\Faq\Block\Catalog\Product\Tab" name="amasty_faq_product_tab" ifconfig="amastyfaq/product_page/show_tab" as="amfaq_product" template="Amasty_Faq::product/questions_tab.phtml" group="detailed_info">
<action method="setTitle">
<argument name="title" xsi:type="string">Q>A</argument>
</action>
<block class="Amasty\Faq\Block\Lists\QuestionsList" name="amasty_faq_questions" template="Amasty_Faq::lists/questions.phtml" after="-">
<block class="Amasty\Faq\Block\Rating\Rating" ifconfig="amastyfaq/rating/enabled" name="amasty_faq_rating" template="Amasty_Faq::rating/rating.phtml">
<block class="Magento\Framework\View\Element\Template" name="amasty_faq_rating_item" template="Amasty_Faq::rating/rating_item.phtml"/>
</block>
<block class="Amasty\Faq\Block\Lists\Pager" name="amasty_faq_pager"/>
</block>
<block class="Amasty\Faq\Block\Forms\AskQuestion" ifconfig="amastyfaq/product_page/show_link" name="amasty_faq_ask_question_form" template="Amasty_Faq::forms/askquestion.phtml"/>
</block>
</referenceBlock>
<move element="amasty_faq_product_tab" destination="product.info.details" after="-" />
</body>
</page>
update: I found out the tab title is set in this file. how do i override this block .php?
/vendor/amasty/module-faq-product-questions/Block/Catalog/Product/Tab.php
I tried to extends the Tab.php by creating a module, but didnt' work
/app/code/Kw/Renametab/Block/Catalog/Product/Tab.php
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2019 Amasty (https://www.amasty.com)
* @package Amasty_Faq
*/
namespace Kw\Renametab\Block\Catalog\Product;
use Magento\Framework\View\Element\Template;
class Tab extends \Amasty\Faq\Block\Catalog\Product\Tab
{
/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$count = $this->getChildBlock('amasty_faq_questions')->getCollection()->count();
$this->setTitle(__('Q&A') . (($count) ? ' (' . $count .')' : ''));
return parent::_toHtml();
}
}
Amasty_Faq::product/questions_tab.phtml
looks like this
<?php
/**
* @var \Amasty\Faq\Block\Catalog\Product\Tab $block
*/
?>
<div class="amfaq-product-tab">
<div class="block-title">
<!--<strong><?//= $block->escapeHtml(__('Question')); ?></strong>-->
</div>
<?php
echo $block->getChildHtml('amasty_faq_questions');
if ($block->showAskQuestionForm()) {
echo $block->getChildHtml('amasty_faq_ask_question_form');
}
?>
</div>
The
/vendor/amasty/module-faq-product-questions/Block/Catalog/Product/Tab.php
looks like this, i'm not sure how to override the function, so i edit the original file for the mean time
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2019 Amasty (https://www.amasty.com)
* @package Amasty_Faq
*/
namespace Amasty\Faq\Block\Catalog\Product;
use Amasty\Faq\Model\ConfigProvider;
use Magento\Framework\View\Element\Template;
class Tab extends \Amasty\Faq\Block\AbstractBlock implements \Magento\Framework\DataObject\IdentityInterface
{
/**
* @var ConfigProvider
*/
private $configProvider;
/**
* Tab constructor.
*
* @param Template\Context $context
* @param ConfigProvider $configProvider
* @param array $data
*/
public function __construct(
Template\Context $context,
ConfigProvider $configProvider,
array $data = []
) {
parent::__construct($context, $data);
$this->configProvider = $configProvider;
}
/**
* @return int
*/
public function getShortAnswerBehavior()
{
return (int)$this->configProvider->getProductPageShortAnswerBehavior();
}
/**
* @return bool
*/
public function showAskQuestionForm()
{
return $this->configProvider->isShowAskQuestionOnProductPage();
}
/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$count = $this->getChildBlock('amasty_faq_questions')->getCollection()->count();
$this->setTitle(__('Product Questions') . (($count) ? ' (' . $count .')' : ''));
return parent::_toHtml();
}
/**
* Return identifiers for produced content
*
* @return array
*/
public function getIdentities()
{
return [\Amasty\Faq\Model\ResourceModel\Question\Collection::CACHE_TAG];
}
}
/app/design/frontend/Infortis/ultimo/Magento_Catalog/templates/product/view/details.phtml
look like this
<?php
// @codingStandardsIgnoreFile
?>
<?php
$theme = $this->helper('Infortis\Base\Helper\Data');
$innerContainerClasses = '';
$jsScriptInit = '';
$mode = $theme->getCfg('product_page/tabs');
$openedTab = $theme->getCfg('product_page/opened_tab');
$jsOpenedTab = '';
if ($openedTab !== null)
{
$jsOpenedTab = ', "active": ' . $openedTab;
}
else
{
$jsOpenedTab = ', "active": null';
}
switch ($mode)
{
case 1:
$innerContainerClasses = 'product data items ' . $theme->getCfg('product_page/tabs_style') . ' show-tabs';
$jsScriptInit = '{"tabs": {"openedState": "active", "collapsible": true' . $jsOpenedTab . '}}';
break;
case 2:
$innerContainerClasses = 'product data items ' . $theme->getCfg('product_page/tabs_style');
$jsScriptInit = '{"tabs": {"openedState": "active", "collapsible": true' . $jsOpenedTab . '}}';
break;
default:
$innerContainerClasses = 'product data items style1 stacked-tabs';
$jsScriptInit = '{"tabs": {"openedState": "active", "collapsible": true}}';
break;
}
?>
<?php if ($detailedInfoGroup = $block->getGroupChildNames('detailed_info', 'getChildHtml')):?>
<?php//START CODE FOR LAST TAB
foreach ($detailedInfoGroup as $key => $name){
if($name == 'amasty_faq_product_tab'){
unset($detailedInfoGroup[$key]);
array_push($detailedInfoGroup, $name);
}
}// END CODE FOR LAST TAB
?>
<div class="product info detailed collateral-container">
<?php $layout = $block->getLayout(); ?>
<div class="<?php echo $innerContainerClasses; ?>" <?php if ($jsScriptInit): ?>data-mage-init='<?php echo $jsScriptInit; ?>'<?php endif; ?>>
<?php foreach ($detailedInfoGroup as $name):?>
<?php
$html = $layout->renderElement($name);
if (!trim($html)) {
continue;
}
$alias = $layout->getElementAlias($name);
$label = $block->getChildData($alias, 'title');
?>
<div class="data item title"
aria-labeledby="tab-label-<?php /* @escapeNotVerified */ echo $alias; ?>-title"
data-role="collapsible" id="tab-label-<?php /* @escapeNotVerified */ echo $alias; ?>">
<a class="data switch"
tabindex="-1"
data-toggle="switch"
href="#<?php /* @escapeNotVerified */ echo $alias; ?>"
id="tab-label-<?php /* @escapeNotVerified */ echo $alias; ?>-title">
<strong><?php /* @escapeNotVerified */ echo $label; ?></strong>
</a>
</div>
<div class="data item content" id="<?php /* @escapeNotVerified */ echo $alias; ?>" data-role="content">
<?php /* @escapeNotVerified */ echo $html; ?>
</div>
<?php endforeach;?>
</div>
</div>
<?php endif; ?>
Amasty_Faq::product/questions_tab.phtml?
and '/public_html/vendor/amasty/module-faq-product-questions/Block/Catalog/Product/Tab.php'