Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddToWishlist.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Wishlist\Block;
8 
16 {
22  private $productTypes;
23 
28  public function __construct(
29  \Magento\Framework\View\Element\Template\Context $context,
30  array $data = []
31  ) {
32  parent::__construct(
33  $context,
34  $data
35  );
36  }
37 
44  public function getWishlistOptions()
45  {
46  return ['productType' => $this->getProductTypes()];
47  }
48 
55  private function getProductTypes()
56  {
57  if ($this->productTypes === null) {
58  $this->productTypes = [];
59  $block = $this->getLayout()->getBlock('category.products.list');
60  if ($block) {
61  $productCollection = $block->getLoadedProductCollection();
62  $productTypes = [];
64  foreach ($productCollection as $product) {
65  $productTypes[] = $this->escapeHtml($product->getTypeId());
66  }
67  $this->productTypes = array_unique($productTypes);
68  }
69  }
70  return $this->productTypes;
71  }
72 
77  protected function _toHtml()
78  {
79  if (!$this->getProductTypes()) {
80  return '';
81  }
82  return parent::_toHtml();
83  }
84 }
$block
Definition: block.php:8
__construct(\Magento\Framework\View\Element\Template\Context $context, array $data=[])