We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

If you want to show product listing in a given order by its category in the Catalog Product List Widget? Then follow the below steps.

Step 1: Create a file like ProductOrder/CatalogProList/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCatalogWidgetBlockProductProductsList">
        <plugin name="custom_widgets_product_list" type="ProductOrderCatalogProListPluginBlockProductProductsOrderList"/>
    </type>
</config>

Step 2: Create another file like ProductOrder/CatalogProList/Plugin/Block/Product/ProductsOrderList.php

<?php    
	namespace ProductOrderCatalogProListPluginBlockProduct;

	use MagentoCatalogModelResourceModelProductCollection;
	use MagentoCatalogWidgetBlockProductProductsList;

	/**
	 * Class ProductsOrderList
	 */
	class ProductsOrderList
	{

	    /**
	     * @param ProductsList $subject
	     * @param Collection $result
	     * @return Collection
	     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
	     */
	    public function afterCreateCollection(ProductsList $subject, Collection $result)
	    {
	        $result->getSelect()->order('cat_index_position asc');

	        return $result;
	    }
	}

That’s it…

Now, you can check your widget’s products. It will be displayed as per the given order.

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote

      Let’s initiate a discussion!!