2

I just need to apply a check on the default Sort By options. Not on all. only one. That when the user is not login, he cannot sort products by price. Anyone having any idea how to do it.

Thanks

0

It's not clear what Magento version you are using. In future please tag your question accordingly.

The following answer is for M2:

I would write a plugin module that does an afterGetAttributeUsedForSortByArray() method to change the output of Magento\Catalog\Model\Config::getAttributeUsedForSortByArray() and remove the options depending on user type (eg: if the user is a Guest user).

here is the full method to change:

    /**
     * Retrieve Attributes Used for Sort by as array
     * key = code, value = name
     *
     * @return array
     */
    public function getAttributeUsedForSortByArray()
    {
        $options = ['position' => __('Position')];
        foreach ($this->getAttributesUsedForSortBy() as $attribute) {
            /* @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
            $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
        }

        return $options;
    }

found in vendor/magento/module-catalog/Model/Config.php

I hope that helps.

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.