helper = $helper;
$this->productUrl = $productUrl;
$this->outputHelper = $outputHelper;
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
}
/**
* @inheritdoc
*/
public function getSectionData()
{
$count = $this->helper->getItemCount();
return [
'count' => $count,
'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
'listUrl' => $this->helper->getListUrl(),
'items' => $count ? $this->getItems() : [],
'websiteId' => $this->storeManager->getWebsite()->getId()
];
}
/**
* Get the list of compared product items
*
* @return array
* @throws LocalizedException
*/
protected function getItems()
{
$items = [];
$productsScope = $this->scopeConfig->getValue(
'catalog/recently_products/scope',
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
);
/** @var \Magento\Catalog\Model\Product $item */
foreach ($this->helper->getItemCollection() as $item) {
$items[] = [
'id' => $item->getId(),
'product_url' => $this->productUrl->getUrl($item),
'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'),
'remove_url' => $this->helper->getPostDataRemove($item),
'productScope' => $productsScope
];
}
return $items;
}
}