I have created a block for getting wishlist items, after that i need this list to my custom phtml file,
my block :
app\code\vendor\path\Block\WishlistProducts.php
<?php
namespace Vendor\Path\Block;
use Magento\Framework\View\Element\Template\Context;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Wishlist\Model\ResourceModel\Item\CollectionFactory as WishlistCollectionFactory;
use Magento\Customer\Model\Session;
class WishlistProducts extends \Magento\Framework\View\Element\Template
{
protected $_wishlistCollectionFactory;
protected $_customerSession;
protected $_productCollectionFactory;
public function __construct(Context $context,
CollectionFactory $productCollectionFactory,
WishlistCollectionFactory $wishlistCollectionFactory,
Session $customerSessio
) {
$this->_productCollectionFactory = $productCollectionFactory;
$this->_wishlistCollectionFactory = $wishlistCollectionFactory;
$this->_customerSession = $customerSessio;
}
public function getWishlistProductCollection()
{
$collection = [];
if ($this->_customerSession->isLoggedIn()) {
$wishlist = $this->_wishlistCollectionFactory->create()
->addCustomerIdFilter($this->_customerSession->getCustomer()->getId());
$productIds = null;
foreach ($wishlist as $product) {
$productIds[] = $product->getProductId();
}
$collection = $this->_productCollectionFactory->create()->addIdFilter($productIds);
$collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter($this->getStoreId());
}
return $collection;
}
}
?>
app\code\vendor\path\view\frontend\wishlistitems.phtml
for testing:
<?Php
echo("hello");
?>
How to get this on my custom phtml DropdownDialog widget
app\design\frontend\Zero\my_theme\Magento_Theme\templates\location_link.phtml
<div class="wishlist minicart-wrapper" data-block="dropdown">
<a href="#" class="action" data-trigger="trigger">
<img class="wishlist-img" src='<?php echo $this->getViewFileUrl('images/Group_5288.png'); ?>' alt="Logo">
</a>
</div>
<div class="block block-minicart"
data-mage-init='{
"dropdownDialog": {
"appendTo": "[data-block=dropdown]",
"triggerTarget":"[data-trigger=trigger]",
"timeout": 2000,
"closeOnMouseLeave": false,
"closeOnEscape": true,
"autoOpen": false,
"triggerClass": "active",
"parentClass": "active",
"buttons": []
}
}'>
<div id="minicart-content-wrapper">
<?php
include($block->getTemplateFile('vendor_path::wishlistitems.phtml'))
?>
</div>
</div>
page error, if i add
<p>hi</p> // when i click my icon hi message working
What is the proper way to call my block into phtml file?
or
FYI - How to get this https://i.stack.imgur.com/S07Za.png into my custom phtml file DropdownDialog widget