:::: MENU ::::
Posts tagged with: comma seperated values

Magento 2 Find value in comma separated string column

Today we discuss Magento 2 find value in 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));
     
     }
Author: Qaisar Satti
Category: Magento 2
Last Modified: January 12, 2018