0

I am trying to disable or enable category attribute based on system config or helper value using UI component can I make this directly from here ?

system config path :- marketplacesetting/category_commissions/enable

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="category_commission">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Category Commission</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">15</item>
            </item>
        </argument>
        <field name="category_commission_percentage">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">Category Commission Percentage</item>
                    <!--<item name="disabled" xsi:type="boolean">true</item>-->
                    <!--<item name="disabled" xsi:type="string">${ $.provider }:data.category_commission_percentage.do_we_hide_it</item>-->
                    <item name="config" xsi:type="string">marketplacesetting/category_commissions/enable</item>
                    <item name="scope_info" xsi:type="string">1</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">false</item>
                        <item name="less-than-equals-to" xsi:type="number">99</item>
                        <item name="validate-number" xsi:type="boolean">true</item>
                        <item name="validate-zero-or-greater" xsi:type="boolean">true</item>
                        <item name="validate-not-negative-number" xsi:type="boolean">true</item>
                    </item>

                </item>
            </argument>
        </field>
    </fieldset>
</form>
2
  • I think you can not do that from XML, but you can do by custom component or CLASS.
    – kunj
    Commented Oct 17, 2018 at 12:26
  • can you please provide any example ..? <item name="disabled" class="Omnyfy\Mcm\Ui\Component\Listing\Column\DisableCategoryPercentage" xsi:type="boolean"></item> public function foreach ($dataSource['data']['items'] as & $data) { if ($this->_helper->isTransactionFeeEnable() && $this->_helper->isEnable()){ return $data['category_commission_percentage']['disabled'] = false; } else { return $data['category_commission_percentage']['disabled'] = true; } } }
    – sakshi
    Commented Oct 23, 2018 at 10:32

1 Answer 1

0

I made it by using js with phtml for category add and edit.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Modulename\Block\Adminhtml\Category;

class Edit extends \Magento\Framework\View\Element\Template
{

}

layout:-Vendor\Modulename\view\adminhtml\layout\catalog_category_add.xml

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <uiComponent name="category_form"/>
            <block class="Vendor\Modulename\Block\Adminhtml\Category\Edit" after="-" name="category_percentage" template="catalog/category/edit.phtml" />
        </referenceContainer>
    </body>
</page>

template:-Vendor\Modulename\view\adminhtml\templates\catalog\category\edit.phtml

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('marketplacesetting/category_commissions/enable');
?>
<script type="text/javascript">
    require(['jquery'], function ($) {
        jQuery(document).ready(function () {
            var conf = <?php echo $conf; ?>;
            if (conf != 1) {
                setTimeout(function () {
                    jQuery("input[name='category_commission_percentage']").prop('disabled', true);
                }, 15000);
            }
        });

    });
</script>

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.