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
17 changes: 11 additions & 6 deletions Block/Catalog/Product/ViewedProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Klaviyo\Reclaim\Helper\Data;
use Magento\Catalog\Helper\Image;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
Expand All @@ -13,7 +13,7 @@ class ViewedProduct extends Template
{
protected $_helper;
protected $_registry;
protected $_categoryFactory;
protected $_categoryCollectionFactory;
protected $imageUrl = null;
protected $categories = [];
protected $price = 0;
Expand All @@ -36,14 +36,14 @@ public function __construct(
Context $context,
Data $helper,
Registry $registry,
CategoryFactory $categoryFactory,
CollectionFactory $categoryCollectionFactory,
Image $imageHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->_helper = $helper;
$this->_registry = $registry;
$this->_categoryFactory = $categoryFactory;
$this->_categoryCollectionFactory = $categoryCollectionFactory;
$this->imageHelper = $imageHelper;
}

Expand Down Expand Up @@ -90,8 +90,13 @@ public function getProduct()
public function getProductCategories()
{
if (empty($this->categories)) {
foreach ($this->getProduct()->getCategoryIds() as $category_id) {
$category = $category = $this->_categoryFactory->create()->load($category_id);
$categoryIds = $this->getProduct()->getCategoryIds();

$collection = $this->_categoryCollectionFactory->create();
$collection->addAttributeToSelect('name');
$collection->addAttributeToFilter('entity_id', $categoryIds);

foreach ($collection->getItems() as $category) {
$this->categories[] = $category->getName();
}
}
Expand Down