Skip to content

Commit 4126ab6

Browse files
committed
Prevent special characters finding their way into layout handle due to SKU being used.
This avoids page cache issue when Varnish tries to retrieve ESI with invalid URL on product page.
1 parent cc577b7 commit 4126ab6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,26 @@ public function initProductLayout(ResultPage $resultPage, $product, $params = nu
116116
$pageConfig->setPageLayout($settings->getPageLayout());
117117
}
118118

119+
$urlSafeSku = rawurlencode($product->getSku());
120+
119121
// Load default page handles and page configurations
120122
if ($params && $params->getBeforeHandles()) {
121123
foreach ($params->getBeforeHandles() as $handle) {
122124
$resultPage->addPageLayoutHandles(
123-
['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()],
125+
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()],
124126
$handle
125127
);
126128
}
127129
}
128130

129131
$resultPage->addPageLayoutHandles(
130-
['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()]
132+
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]
131133
);
132134

133135
if ($params && $params->getAfterHandles()) {
134136
foreach ($params->getAfterHandles() as $handle) {
135137
$resultPage->addPageLayoutHandles(
136-
['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()],
138+
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()],
137139
$handle
138140
);
139141
}

app/code/Magento/Review/Controller/Product/ListAction.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ protected function _initProductLayout($product)
2525
$pageConfig->setPageLayout($product->getPageLayout());
2626
}
2727
$update = $this->_view->getLayout()->getUpdate();
28+
29+
$urlSafeSku = rawurlencode($product->getSku());
2830
$this->_view->addPageLayoutHandles(
29-
['id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()]
31+
['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]
3032
);
3133

3234
$this->_view->loadLayoutUpdates();

0 commit comments

Comments
 (0)