Integrating Catalog Collection Pager into Magento Wishlist
Wishlists are an essential feature for e-commerce platforms, allowing customers to save products they’re interested in for future reference or purchase. In Magento, the default wishlist functionality does not include built-in pagination for large lists of saved items.
Understanding the Limitations
The standard Magento wishlist uses a simple array to store items, which doesn’t natively support pagination. When you have hundreds or thousands of products in your customer’s wishlists, navigating through them becomes cumbersome and slows down the user experience.
Setting Up the Environment for Pagination
Before we begin, ensure you have a Magento installation with catalog and wishlist functionality enabled. If you haven’t already, install the Magento_Catalog and Magento_Wishlist modules in your project:
composer require magento/module-catalog
composer require magento/module-wishlist
Then run the following commands to enable the necessary modules:
bin/magento module:enable Magento_Catalog
bin/magento module:enable Magento_Wishlist
bin/magento setup:upgrade
Implementing Pagination in Wishlist
To integrate the catalog’s pager toolbar into your wishlist, you’ll need to modify the wishlist controller and template files.
Step 1: Override the Wishlist Controller
Create a custom module with the following structure:
app/code/Vendor/WishlistPager/etc
|-- di.xml
In di.xml, override the Magento\Wishlist\Controller\Index class:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Wishlist\Controller\Index">
<arguments>
<argument name="actionFactory" xsi:type="object">Vendor\WishlistPager\Controller\ActionFactory</argument>
</arguments>
</type>
</config>
Step 2: Create the Custom Controller
Create a new file app/code/Vendor/WishlistPager/Controller/Index.php:
namespace Vendor\WishlistPager\Controller;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\Controller\ResultFactory;
class Index implements ActionInterface
{
// Implement your custom logic here to fetch wishlist items using the catalog collection pager
public function execute()
{
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
// Add your pager implementation logic
return $result;
}
}
Step 3: Modify the Wishlist Template File
Override the wishlist/view/items.phtml file in your custom theme:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View etc/page_configuration.xsd">
<update handle="customer_account_common"/>
<referenceContainer name="content">
<block class="Magento\Wishlist\Block\Customer\Items" template="Vendor_WishlistPager::items.phtml"/>
</referenceContainer>
</page>
In app/code/Vendor/WishlistPager/view/frontend/templates/items.phtml, replace the existing wishlist items loop with your custom pager implementation using Magento’s catalog collection.
Conclusion
Integrating the catalog collection pager into the Magento wishlist enhances user experience by allowing customers to easily navigate through large lists of saved products. This customization requires a solid understanding of Magento’s extension architecture and controller actions.
Remember to consult the official Magento development documentation for more detailed information on overriding controllers and templates in your custom modules.
By following these steps, you can provide your customers with an optimized wishlist experience that improves their interaction with your store’s product catalog.