Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CompareProducts.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $helper;
16 
20  protected $productUrl;
21 
25  private $outputHelper;
26 
32  public function __construct(
33  \Magento\Catalog\Helper\Product\Compare $helper,
34  \Magento\Catalog\Model\Product\Url $productUrl,
35  \Magento\Catalog\Helper\Output $outputHelper
36  ) {
37  $this->helper = $helper;
38  $this->productUrl = $productUrl;
39  $this->outputHelper = $outputHelper;
40  }
41 
45  public function getSectionData()
46  {
47  $count = $this->helper->getItemCount();
48  return [
49  'count' => $count,
50  'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
51  'listUrl' => $this->helper->getListUrl(),
52  'items' => $count ? $this->getItems() : [],
53  ];
54  }
55 
59  protected function getItems()
60  {
61  $items = [];
63  foreach ($this->helper->getItemCollection() as $item) {
64  $items[] = [
65  'id' => $item->getId(),
66  'product_url' => $this->productUrl->getUrl($item),
67  'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'),
68  'remove_url' => $this->helper->getPostDataRemove($item),
69  ];
70  }
71  return $items;
72  }
73 }
$count
Definition: recent.phtml:13
__()
Definition: __.php:13
__construct(\Magento\Catalog\Helper\Product\Compare $helper, \Magento\Catalog\Model\Product\Url $productUrl, \Magento\Catalog\Helper\Output $outputHelper)
$items