89 \
Magento\Framework\Stdlib\StringUtils $string =
null 91 $this->_catalogSession = $catalogSession;
92 $this->_catalogDesign = $catalogDesign;
93 $this->_catalogProduct = $catalogProduct;
94 $this->_coreRegistry = $coreRegistry;
99 ->get(\
Magento\Framework\Stdlib\StringUtils::class);
100 parent::__construct($context);
110 private function preparePageMetadata(ResultPage $resultPage,
$product)
112 $pageLayout = $resultPage->getLayout();
113 $pageConfig = $resultPage->getConfig();
115 $metaTitle =
$product->getMetaTitle();
116 $pageConfig->setMetaTitle($metaTitle);
117 $pageConfig->getTitle()->set($metaTitle ?:
$product->getName());
119 $keyword =
$product->getMetaKeyword();
120 $currentCategory = $this->_coreRegistry->registry(
'current_category');
122 $pageConfig->setKeywords($keyword);
123 }
elseif ($currentCategory) {
124 $pageConfig->setKeywords(
$product->getName());
131 $pageConfig->setDescription($this->string->substr(strip_tags(
$product->getDescription()), 0, 255));
134 if ($this->_catalogProduct->canUseCanonicalTag()) {
135 $pageConfig->addRemotePageAsset(
138 [
'attributes' => [
'rel' =>
'canonical']]
142 $pageMainTitle = $pageLayout->getBlock(
'page.main.title');
143 if ($pageMainTitle) {
144 $pageMainTitle->setPageTitle(
$product->getName());
163 $pageConfig = $resultPage->getConfig();
166 $this->_catalogDesign->applyCustomDesign(
$settings->getCustomDesign());
171 $pageConfig->setPageLayout(
$settings->getPageLayout());
174 $urlSafeSku = rawurlencode(
$product->getSku());
179 $resultPage->addPageLayoutHandles([
'type' =>
$product->getTypeId()],
$handle,
false);
180 $resultPage->addPageLayoutHandles([
'id' =>
$product->getId(),
'sku' => $urlSafeSku],
$handle);
184 $resultPage->addPageLayoutHandles([
'type' =>
$product->getTypeId()],
null,
false);
185 $resultPage->addPageLayoutHandles([
'id' =>
$product->getId(),
'sku' => $urlSafeSku]);
189 $resultPage->addPageLayoutHandles([
'type' =>
$product->getTypeId()],
$handle,
false);
190 $resultPage->addPageLayoutHandles([
'id' =>
$product->getId(),
'sku' => $urlSafeSku],
$handle);
195 $update = $resultPage->getLayout()->getUpdate();
196 $layoutUpdates =
$settings->getLayoutUpdates();
197 if ($layoutUpdates) {
198 if (is_array($layoutUpdates)) {
199 foreach ($layoutUpdates as $layoutUpdate) {
200 $update->addUpdate($layoutUpdate);
205 $currentCategory = $this->_coreRegistry->registry(
'current_category');
206 $controllerClass = $this->_request->getFullActionName();
207 if ($controllerClass !=
'catalog-product-view') {
208 $pageConfig->addBodyClass(
'catalog-product-view');
210 $pageConfig->addBodyClass(
'product-' .
$product->getUrlKey());
212 $pageConfig->addBodyClass(
'categorypath-' . $this->categoryUrlPathGenerator->getUrlPath($currentCategory))
213 ->addBodyClass(
'category-' . $currentCategory->getUrlKey());
243 $defaultActionHandle = $resultPage->getDefaultLayoutHandle();
244 $handles = $resultPage->getLayout()->getUpdate()->getHandles();
245 if (in_array($defaultActionHandle, $handles)) {
246 $resultPage->getLayout()->getUpdate()->removeHandle($resultPage->getDefaultLayoutHandle());
250 throw new \Magento\Framework\Exception\LocalizedException(
251 __(
'Bad controller interface for showing product')
257 $params = new \Magento\Framework\DataObject();
263 throw new \Magento\Framework\Exception\NoSuchEntityException(
__(
'Product is not loaded'));
271 if (
$params->hasConfigureMode()) {
275 $this->_eventManager->dispatch(
'catalog_controller_product_view', [
'product' =>
$product]);
277 $this->_catalogSession->setLastViewedProductId(
$product->getId());
279 if (in_array($defaultActionHandle, $handles)) {
280 $resultPage->addDefaultHandle();
284 $this->preparePageMetadata($resultPage,
$product);
elseif(isset( $params[ 'redirect_parent']))
$categoryUrlPathGenerator
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest
initProductLayout(ResultPage $resultPage, $product, $params=null)
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Session $catalogSession, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, array $messageGroups=[], \Magento\Framework\Stdlib\StringUtils $string=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
prepareAndRender(ResultPage $resultPage, $productId, $controller, $params=null)