File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed
view/frontend/templates/product Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 88use Magento \Catalog \Helper \Data ;
99use Magento \Framework \App \Config \ScopeConfigInterface ;
1010use Magento \Framework \DataObject ;
11+ use Magento \Framework \Serialize \Serializer \Json ;
1112use Magento \Framework \View \Element \Block \ArgumentInterface ;
1213
1314/**
@@ -27,18 +28,26 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
2728 */
2829 private $ scopeConfig ;
2930
31+ /**
32+ * @var Json
33+ */
34+ private $ json ;
35+
3036 /**
3137 * @param Data $catalogData
3238 * @param ScopeConfigInterface $scopeConfig
39+ * @param Json $json
3340 */
3441 public function __construct (
3542 Data $ catalogData ,
36- ScopeConfigInterface $ scopeConfig
43+ ScopeConfigInterface $ scopeConfig ,
44+ Json $ json
3745 ) {
3846 parent ::__construct ();
3947
4048 $ this ->catalogData = $ catalogData ;
4149 $ this ->scopeConfig = $ scopeConfig ;
50+ $ this ->json = $ json ;
4251 }
4352
4453 /**
@@ -78,4 +87,20 @@ public function getProductName()
7887 ? $ this ->catalogData ->getProduct ()->getName ()
7988 : '' ;
8089 }
90+
91+ /**
92+ * Returns breadcrumb json.
93+ *
94+ * @return string
95+ */
96+ public function getJsonConfiguration ()
97+ {
98+ return $ this ->json ->serialize ([
99+ 'breadcrumbs ' => [
100+ 'categoryUrlSuffix ' => $ this ->getCategoryUrlSuffix (),
101+ 'userCategoryPathInUrl ' => (int )$ this ->isCategoryUsedInProductUrl (),
102+ 'product ' => $ this ->getProductName ()
103+ ]
104+ ]);
105+ }
81106}
Original file line number Diff line number Diff line change 77/** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */
88$ viewModel = $ block ->getData ('viewModel ' );
99?>
10- <div class="breadcrumbs" data-mage-init='{
11- "breadcrumbs": {
12- "categoryUrlSuffix": "<?= $ block ->escapeHtml ($ viewModel ->getCategoryUrlSuffix ()); ?> ",
13- "useCategoryPathInUrl": <?= (int )$ viewModel ->isCategoryUsedInProductUrl (); ?> ,
14- "product": "<?= $ block ->escapeHtml ($ block ->escapeJs ($ viewModel ->getProductName ())); ?> "
15- }
16- }'>
17- </div>
10+ <div class="breadcrumbs" data-mage-init='<?= $ viewModel ->getJsonConfiguration () ?> '></div>
You can’t perform that action at this time.
0 commit comments