As my default wishlist collection which is coming from block is not working due to the applied theme in my magento2 site.

So, I applied the collection on my list.phtml file. And the problem is I need to apply pagination for this.

How to apply pagination for the wishlist listing page.

Here is my code:

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// @codingStandardsIgnoreFile

/** @var \Magento\Wishlist\Block\Customer\Wishlist\Items $block */
$columns = $block->getColumns();

<div class="products-grid wishlist wishlist_Alter">
    <?php if (count($block->getItems())): ?>
    <ol class="product-items">

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->get('Magento\Customer\Model\Session');  
        $customerData = $customerSession->getCustomer()->getId();
        $wishlist_collection = $objectManager->create('Magento\Wishlist\Model\Wishlist')->loadByCustomerId($customerData, true)->getItemCollection()->setOrder('added_at','DESC');

        //OLD DONT REMOVE 
        //$wishlist_collection = $block->getItems();

        foreach ($wishlist_collection as $item): ?>
            <?php //print_r($item->getAddedAt());?>
            <li data-row="product-item" class="product-item" id="item_<?= $block->escapeHtmlAttr($item->getId()) ?>">
                <div class="product-item-info" data-container="product-grid">
                    <?php foreach ($columns as $column): ?>
                        <?= $column->setItem($item)->toHtml();?>
                    <?php endforeach; ?>
        <?php endforeach; ?>
    <?php else: ?>
        <div class="message info empty">
            <span><?= $block->escapeHtml(__('This Wish List has no Items')) ?></span>
    <?php endif; ?>

<?php foreach ($columns as $column): ?>
    <?= $column->getAdditionalHtml() ?>
<?php endforeach; ?>

Any help would be appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.