0

There are three options (1. products only, 2. Static block only, 3. Static block and products) in display mode, i want add two more options so can any one help me to add more options.

enter image description here

thanks in advanced.

1 Answer 1

1

Create a plugin following way:

Vendor/Module/etc/adminhtml/di.xml

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Category\Attribute\Source\Mode">
        <plugin name="WebkulCart" type="Md\Nspc\Plugin\Model\Category\Attribute\Source\Mode" sortOrder="1"/>
    </type>
</config>

Vendor/Module/Plugin/Model/Category/Attribute/Source/Mode.php

namespace Vendor\Module\Plugin\Model\Category\Attribute\Source;

class Mode
{
    public function afterGetAllOptions(
        \Magento\Catalog\Model\Category\Attribute\Source\Mode $subject,
        $result
    ) {
        $result[] = ['value' => 'CUSTOM_MODE', 'label' => 'Custom Mode'];
        return $result;
    }
}

Clear cache.

5
  • thnks for reply, all command are not working when i put your code in di.cml file, so i have change it to "<preference for="Magento\Catalog\Model\Category\Attribute\Source\Mode" type="md\nspc\Plugin\Model\Category\Attribute\Source\Mode" />" after this commands are working but at admin panel it gives 500 internal server error Commented Jul 14, 2017 at 12:18
  • Why you use preference, Use plugin and "md\nspc" should be uppercase first.
    – Sohel Rana
    Commented Jul 14, 2017 at 12:32
  • It's tested code. I use 'SR\StackExchange' instead of 'Vendor\Module'
    – Sohel Rana
    Commented Jul 14, 2017 at 12:34
  • This one is working for me: <type name="Magento\Catalog\Model\Category\Attribute\Source\Mode"> <plugin name="WebkulCart" type="Md\Nspc\Plugin\Model\Category\Attribute\Source\Mode" sortOrder="1" /> </type> Commented Jul 14, 2017 at 12:55
  • Thats nice format.
    – Sohel Rana
    Commented Jul 14, 2017 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.