1

I have a lot of configurable product in my backend listing, I'd like to know how can I hide all my virtual product ? (I want to show only configurable products on my backend).

Can I do this from the backoffice or should I hide them programmaticaly ? And how ?

  • Did you try filter listing? – Sohel Rana Apr 25 '19 at 14:31
  • I don't want to simply add a filter, because I don't want the user to have control on this (he won't be able to see them through backend listing). – Morgan Tartreau Apr 25 '19 at 16:23
0

Suppose you have SR_MagentoCommunity module. Now added folowing file in your module that will avoid showing virtual type product in admin grid.

app/code/SR/MagentoCommunity/etc/adminhtml/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="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
        <plugin name="sr_product_list" type="SR\MagentoCommunity\Plugin\Catalog\Ui\DataProvider\Product\ProductDataProvider" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Catalog/Ui/DataProvider/Product/ProductDataProvider.php

<?php
namespace SR\MagentoCommunity\Plugin\Catalog\Ui\DataProvider\Product;

class ProductDataProvider
{
    /**
     * @param \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject
     * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
     * @return mixed
     */
    public function afterGetCollection(
        \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject,
        $collection
    ) {
        $collection->addFieldToFilter('type_id', ['nin' => 'virtual']);
        return $collection;
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.