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
1 2 3 4 5 6 |
<?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="Magento\CatalogWidget\Block\Product\ProductsList"> <plugin name="custom_widgets_product_list" type="ProductOrder\CatalogProList\Plugin\Block\Product\ProductsOrderList"/> </type> </config> |
Step 2: Create another file like ProductOrder/CatalogProList/Plugin/Block/Product/ProductsOrderList.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php namespace ProductOrder\CatalogProList\Plugin\Block\Product; use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\CatalogWidget\Block\Product\ProductsList; /** * 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.
[crayon-63d3e05d4699f196115921/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.