diff --git a/ViewModel/Product/Breadcrumbs.php b/ViewModel/Product/Breadcrumbs.php index 2f2048b2a30..213f2fc34f6 100644 --- a/ViewModel/Product/Breadcrumbs.php +++ b/ViewModel/Product/Breadcrumbs.php @@ -8,6 +8,7 @@ namespace Magento\Catalog\ViewModel\Product; use Magento\Catalog\Helper\Data; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\View\Element\Block\ArgumentInterface; /** @@ -27,18 +28,26 @@ class Breadcrumbs extends DataObject implements ArgumentInterface */ private $scopeConfig; + /** + * @var Json + */ + private $json; + /** * @param Data $catalogData * @param ScopeConfigInterface $scopeConfig + * @param Json $json */ public function __construct( Data $catalogData, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + Json $json ) { parent::__construct(); $this->catalogData = $catalogData; $this->scopeConfig = $scopeConfig; + $this->json = $json; } /** @@ -78,4 +87,20 @@ class Breadcrumbs extends DataObject implements ArgumentInterface ? $this->catalogData->getProduct()->getName() : ''; } + + /** + * Returns breadcrumb json. + * + * @return string + */ + public function getJsonConfiguration() + { + return $this->json->serialize([ + 'breadcrumbs' => [ + 'categoryUrlSuffix' => $this->getCategoryUrlSuffix(), + 'userCategoryPathInUrl' => (int)$this->isCategoryUsedInProductUrl(), + 'product' => $this->getProductName() + ] + ]); + } } diff --git a/view/frontend/templates/product/breadcrumbs.phtml b/view/frontend/templates/product/breadcrumbs.phtml index a5d193afd2a..c54ce534085 100644 --- a/view/frontend/templates/product/breadcrumbs.phtml +++ b/view/frontend/templates/product/breadcrumbs.phtml @@ -7,11 +7,4 @@ /** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */ $viewModel = $block->getData('viewModel'); ?> - +