File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
app/code/Meta/Conversion/Model/Tracker Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -112,17 +112,28 @@ private function getCartCategories(CartInterface $quote): string
112
112
}
113
113
114
114
$ items = $ quote ->getAllVisibleItems ();
115
+ $ categoryIds = [];
115
116
foreach ($ items as $ item ) {
116
117
$ product = $ item ->getProduct ();
117
- $ categoryIds = $ product ->getCategoryIds ();
118
- $ categories = $ this ->categoryCollection ->create ()
119
- ->addAttributeToSelect ('* ' )
120
- ->addAttributeToFilter ('entity_id ' , $ categoryIds );
121
- $ categoryNames = [];
122
- foreach ($ categories as $ category ) {
123
- $ categoryNames [] = $ category ->getName ();
118
+ if ($ product ->getCategoryIds ()) {
119
+ $ categoryIds [] = $ product ->getCategoryIds ();
124
120
}
125
121
}
122
+
123
+ /** Handle products without categories assigned */
124
+ if (empty ($ categoryIds )) {
125
+ return '' ;
126
+ }
127
+ $ categoryIds = array_merge (...$ categoryIds );
128
+
129
+ $ categoryNames = [];
130
+ $ categories = $ this ->categoryCollection ->create ()
131
+ ->addAttributeToSelect ('* ' )
132
+ ->addAttributeToFilter ('entity_id ' , ['in ' => $ categoryIds ]);
133
+ foreach ($ categories as $ category ) {
134
+ $ categoryNames [] = $ category ->getName ();
135
+ }
136
+
126
137
return implode (', ' , $ categoryNames ); /** @phpstan-ignore-line */
127
138
}
128
139
You can’t perform that action at this time.
0 commit comments