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 10
10
use Magento \Catalog \Helper \Data ;
11
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
12
use Magento \Framework \DataObject ;
13
+ use Magento \Framework \Serialize \Serializer \Json ;
13
14
use Magento \Framework \View \Element \Block \ArgumentInterface ;
14
15
15
16
/**
@@ -29,18 +30,26 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
29
30
*/
30
31
private $ scopeConfig ;
31
32
33
+ /**
34
+ * @var Json
35
+ */
36
+ private $ json ;
37
+
32
38
/**
33
39
* @param Data $catalogData
34
40
* @param ScopeConfigInterface $scopeConfig
41
+ * @param Json $json
35
42
*/
36
43
public function __construct (
37
44
Data $ catalogData ,
38
- ScopeConfigInterface $ scopeConfig
45
+ ScopeConfigInterface $ scopeConfig ,
46
+ Json $ json
39
47
) {
40
48
parent ::__construct ();
41
49
42
50
$ this ->catalogData = $ catalogData ;
43
51
$ this ->scopeConfig = $ scopeConfig ;
52
+ $ this ->json = $ json ;
44
53
}
45
54
46
55
/**
@@ -80,4 +89,20 @@ public function getProductName(): string
80
89
? $ this ->catalogData ->getProduct ()->getName ()
81
90
: '' ;
82
91
}
92
+
93
+ /**
94
+ * Returns breadcrumb json.
95
+ *
96
+ * @return string
97
+ */
98
+ public function getJsonConfiguration ()
99
+ {
100
+ return $ this ->json ->serialize ([
101
+ 'breadcrumbs ' => [
102
+ 'categoryUrlSuffix ' => $ this ->getCategoryUrlSuffix (),
103
+ 'userCategoryPathInUrl ' => (int )$ this ->isCategoryUsedInProductUrl (),
104
+ 'product ' => $ this ->getProductName ()
105
+ ]
106
+ ]);
107
+ }
83
108
}
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