0

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;
}
0

If it helps :

$this->_productCollection->addAttributeToSelect("field")->addAttributeToFilter("field", array('like' => "%".$field."%"));

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.