Skip to content

Commit 05c7eb3

Browse files
committed
fixed you may like block
1 parent 5919117 commit 05c7eb3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

app/base/blocks/YouMayLikeProducts.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function renderHTML(?BasePage $current_page = null, array $data = []): st
9393
foreach ($this->getCart($current_page)->getItems() as $item) {
9494
$youMayLike = array_unique_by(
9595
array_merge($youMayLike, $this->getProductSuggestions($item)),
96-
fn ($el) => $el['type'] . '::' . $el['id']
96+
fn ($el) => $el['modelClass'] . '::' . $el['id']
9797
);
9898
}
9999

@@ -103,8 +103,9 @@ public function renderHTML(?BasePage $current_page = null, array $data = []): st
103103

104104
$suggestions = [];
105105
foreach ($youMayLike as $elem) {
106-
if (is_subclass_of($elem['modelClass'], ProductInterface::class)) {
107-
$suggestion = $this->containerCall([$elem['modelClass'], 'load'], ['id' => $elem['id']]);
106+
['modelClass' => $modelClass, 'type' => $type, 'id' => $id] = $elem;
107+
if (is_subclass_of($modelClass, ProductInterface::class)) {
108+
$suggestion = $this->containerCall([$modelClass, 'load'], ['id' => $id]);
108109

109110
if (in_array(static::getClassBasename($suggestion).'::'.$suggestion->getId(), $cartIdentifiers)) {
110111
continue;
@@ -170,11 +171,11 @@ protected function getProductSuggestions(CartItem $item, ?BasePage $current_page
170171
$locale = $current_page?->getCurrentLocale() ?? App::getInstance()->getCurrentLocale();
171172
$website_id = App::getInstance()->getSiteData()->getCurrentWebsiteId();
172173

173-
$cacheKey = 'youmaylike.'.$product->getSku().'.'.$locale.'.'.$website_id;
174+
$cacheKey = strtolower('youmaylike.'.static::getClassBasename($product).'.'.$product->getId().'.'.$locale.'.'.$website_id);
174175

175176
if (App::getInstance()->getCache()->has($cacheKey)) {
176177
$result = (array) App::getInstance()->getCache()->get($cacheKey);
177-
return array_map(fn ($el) => $el['data'], $result['docs']);
178+
return array_map(fn ($el) => ['modelClass' => $el['modelClass'], 'type' => $el['type'], 'id' => $el['id']], $result['docs']);
178179
}
179180

180181
/** @var FrontendModel $product */
@@ -183,7 +184,7 @@ protected function getProductSuggestions(CartItem $item, ?BasePage $current_page
183184

184185
App::getInstance()->getCache()->set($cacheKey, $result, 1800);
185186

186-
return array_map(fn ($el) => $el['data'], $result['docs']);
187+
return array_map(fn ($el) => ['modelClass' => $el['modelClass'], 'type' => $el['type'], 'id' => $el['id']], $result['docs']);
187188
}
188189

189190
protected function getSearchManager(string $llmCode = 'googlegemini') : AISearchManager

0 commit comments

Comments
 (0)