I want to get my wishlist product list on my custom phtml file,
My block:
\app\code\vendor\module\Block\WishlistProducts.php
<?php
namespace Vendor\Module\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 $customerSession
) {
$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\module\view\frontend\wishlistitems.phtml
<?php
echo("hello");
?>
The hello not return on my custom phtml file,
I am using to call:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("vendor_module::wishlistitems.phtml")->toHtml(); ?>
It's not return the values.
getWishlistProductCollection()
in any template file right?