Question

how can I show catalog products based on customer custom field ?

I've done di.xml

I've done this but is doesn't filter . This is what I have in ListProduct.php (used in di.xml)

protected function _getProductCollection()
{
    $field = $this->customerSession->getCustomer()->getData("field");

    if ($this->_productCollection === null) {
        $this->_productCollection = $this->initializeProductCollection();
        try {
            $this->_productCollection->addAttributeToSelect("field")->addAttributeToFilter("field", array('eq' => $field));
        } catch (LocalizedException $e) {
            echo $e;
        }
    }

    return $this->_productCollection;
}
Was it helpful?

Solution

If it helps :

$this->_productCollection->addAttributeToSelect("field")->addAttributeToFilter("field", array('like' => "%".$field."%"));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top