1

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:

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

// @codingStandardsIgnoreFile

?>
<?php
/** @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">
        <?php 

        //NEW
        $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; ?>
                </div>
            </li>
        <?php endforeach; ?>
    </ol>
    <?php else: ?>
        <div class="message info empty">
            <span><?= $block->escapeHtml(__('This Wish List has no Items')) ?></span>
        </div>
    <?php endif; ?>
</div>

<?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.