File tree 2 files changed +27
-9
lines changed
view/frontend/templates/product 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 8
8
use Magento \Catalog \Helper \Data ;
9
9
use Magento \Framework \App \Config \ScopeConfigInterface ;
10
10
use Magento \Framework \DataObject ;
11
+ use Magento \Framework \Serialize \Serializer \Json ;
11
12
use Magento \Framework \View \Element \Block \ArgumentInterface ;
12
13
13
14
/**
@@ -27,18 +28,26 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
27
28
*/
28
29
private $ scopeConfig ;
29
30
31
+ /**
32
+ * @var Json
33
+ */
34
+ private $ json ;
35
+
30
36
/**
31
37
* @param Data $catalogData
32
38
* @param ScopeConfigInterface $scopeConfig
39
+ * @param Json $json
33
40
*/
34
41
public function __construct (
35
42
Data $ catalogData ,
36
- ScopeConfigInterface $ scopeConfig
43
+ ScopeConfigInterface $ scopeConfig ,
44
+ Json $ json
37
45
) {
38
46
parent ::__construct ();
39
47
40
48
$ this ->catalogData = $ catalogData ;
41
49
$ this ->scopeConfig = $ scopeConfig ;
50
+ $ this ->json = $ json ;
42
51
}
43
52
44
53
/**
@@ -78,4 +87,20 @@ public function getProductName()
78
87
? $ this ->catalogData ->getProduct ()->getName ()
79
88
: '' ;
80
89
}
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
+ }
81
106
}
Original file line number Diff line number Diff line change 7
7
/** @var \Magento\Catalog\ViewModel\Product\Breadcrumbs $viewModel */
8
8
$ viewModel = $ block ->getData ('viewModel ' );
9
9
?>
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