Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions app/code/Meta/Conversion/Block/Pixel/ViewContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,20 @@ public function getContentCategory()
return null;
}

$categoryIds = $product->getCategoryIds();
if (count($categoryIds)) {
$categoryNames = [];
$categoryModel = $this->fbeHelper->getObject(\Magento\Catalog\Model\Category::class);
foreach ($categoryIds as $category_id) {
// @todo do not load category model in loop - this can be a performance killer, use category collection
$category = $categoryModel->load($category_id);
$categoryNames[] = $category->getName();
}
return $this->escapeQuotes(implode(',', $categoryNames));
} else {
$categoryCollection = $product->getCategoryCollection()
->addAttributeToSelect('name');

if (!$categoryCollection->count()) {
return null;
}

$categoryNames = [];

foreach ($categoryCollection as $category) {
$categoryNames[] = $category->getName();
}

return $this->escapeQuotes(implode(',', $categoryNames));
}

/**
Expand Down