Magento 2 Find value comma separated string column

Today we discuss Magento 2 find value comma separated string column. Sometime you need to search in comma separated values in database. So for that we use the Finset to search in comma separated values. Let’s take the example of product collection. Let’s spose the field name test_sku have the comma separated values. So here is example.

protected $_productCollectionFactory;
public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory
    ) {
        $this->_productCollectionFactory = $productFactory;
    }
    public function getProductCollection()
    {
       $sku=’test’;    
      return   $this->_productCollectionFactory->create()->addFieldToFilter('test_sku', array('finset' => $sku));
     
     }

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply