Skip to content

Commit 78a1163

Browse files
Indrani sonawaneIndrani sonawane
authored andcommitted
Merge remote-tracking branch '37876/metatitle-fix' into comm_247beta3
2 parents e124de8 + aa293cb commit 78a1163

File tree

2 files changed

+23
-1
lines changed
  • app/code/Magento/Catalog/Helper/Product
  • dev/tests/integration/testsuite/Magento/Catalog/Helper/Product

2 files changed

+23
-1
lines changed

app/code/Magento/Catalog/Helper/Product/View.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ private function preparePageMetadata(ResultPage $resultPage, $product)
118118
$pageConfig = $resultPage->getConfig();
119119

120120
$metaTitle = $product->getMetaTitle();
121-
$pageConfig->setMetaTitle($metaTitle);
121+
$productMetaTitle = $metaTitle ? $this->addConfigValues($metaTitle) : null;
122+
$pageConfig->setMetaTitle($productMetaTitle);
122123
$pageConfig->getTitle()->set($metaTitle ?: $product->getName());
123124

124125
$keyword = $product->getMetaKeyword();
@@ -294,4 +295,22 @@ public function prepareAndRender(ResultPage $resultPage, $productId, $controller
294295
$this->preparePageMetadata($resultPage, $product);
295296
return $this;
296297
}
298+
299+
/**
300+
* Add Prefix and Suffix as per the configuration.
301+
*
302+
* @param string $title
303+
* @return string
304+
*/
305+
private function addConfigValues($title)
306+
{
307+
$preparedTitle = $this->scopeConfig->getValue(
308+
'design/head/title_prefix',
309+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
310+
) . ' ' . $title . ' ' . $this->scopeConfig->getValue(
311+
'design/head/title_suffix',
312+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
313+
);
314+
return trim($preparedTitle);
315+
}
297316
}

dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/ViewTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function testInitProductLayout()
101101
/**
102102
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
103103
* @magentoAppIsolation enabled
104+
* @magentoConfigFixture default_store design/head/title_prefix prefix
105+
* @magentoConfigFixture default_store design/head/title_suffix suffix
104106
* @magentoAppArea frontend
105107
*/
106108
public function testPrepareAndRender()
@@ -112,6 +114,7 @@ public function testPrepareAndRender()
112114
/** @var \Magento\TestFramework\Response $response */
113115
$response = $this->objectManager->get(\Magento\TestFramework\Response::class);
114116
$this->page->renderResult($response);
117+
$this->assertStringContainsString('prefix meta title suffix', $response->getBody());
115118
$this->assertNotEmpty($response->getBody());
116119
$this->assertEquals(
117120
10,

0 commit comments

Comments
 (0)