Skip to content

How to override grid.php block or cart.php block to remove some items from shopping cart

I want to filter the products (excluding products with some attributes) when the shopping cart is loaded. What is the best way to achieve this. I have looked into overriding getItems function of Magento/checkout/block/cart/grid.php, but cannot load product repository in this file. Or using an observer is good?? Please suggest.