I want to get my wishlist product list on my custom phtml file,
My block:
appcodevendormoduleBlockWishlistProducts.php
<?php
namespace VendorModuleBlock;
use MagentoFrameworkViewElementTemplateContext;
use MagentoCatalogModelResourceModelProductCollectionFactory;
use MagentoWishlistModelResourceModelItemCollectionFactory as WishlistCollectionFactory;
use MagentoCustomerModelSession;
class WishlistProducts extends MagentoFrameworkViewElementTemplate
{
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;
}
}
?>
appcodevendormoduleviewfrontendwishlistitems.phtml
<?php
echo("hello");
?>
The hello not return on my custom phtml file,
I am using to call:
<?php echo $this->getLayout()->createBlock("MagentoFrameworkViewElementTemplate")->setTemplate("vendor_module::wishlistitems.phtml")->toHtml(); ?>
It’s not return the values.