Magento2.1 श्रेणी कस्टम विशेषता ड्रॉपडाउन


10

प्रजनन करने कि प्रक्रिया

1. मॉड्यूल UpgradData.php स्क्रिप्ट में शामिल हैं:

$categorySetup->addAttribute(Category::ENTITY, 'roflcopter', [
                    'type' => 'int',
                    'label' => 'CMS Block',
                    'input' => 'select',
                    'source' => 'Magento\Catalog\Model\Category\Attribute\Source\Page',
                    'required' => false,
                    'sort_order' => 20,
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'Display Settings',
            ]);

2. view / adminhtml / ui_component / category_form.xml

<?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="Navigation">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Navigation</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
        <field name="roflcopter">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">60</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Roflcopter</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

अपेक्षित परिणाम

  1. श्रेणी के रूप में ड्रॉपडाउन का चयन करना चाहिए विकल्प के रूप में CMS ब्लॉक के साथ Roflcopter का चयन करें

वास्तविक परिणाम

  1. खाली ड्रॉपडाउन

जवाबों:


14

चुनिंदा विकल्प बनाने के लिए विकल्प टैग जोड़ें। आपके मामले में यह होना चाहिए


<field name="roflcopter">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Magento\Catalog\Model\Category\Attribute\Source\Page</item>
        <item name="config" xsi:type="array">
            <item name="sortOrder" xsi:type="number">70</item>
            <item name="dataType" xsi:type="string">string</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="label" xsi:type="string" translate="true">Roflcopter</item>
        </item>
    </argument>
</field>


शायद आप जानते हैं कि क्या मैं इस टैब और / या इसकी विशेषताओं को कुछ स्थितियों के आधार पर दिखा / छिपा सकता हूं, उदाहरण के लिए श्रेणी की गहराई?
फ्रैंकफर्ट जकाटोव्स

धन्यवाद! मैं इतने लंबे समय से इसे खोज रहा था। डॉक्स इस विषय पर इतने स्पष्ट नहीं हैं। तुम यह कैसे जानते हो?
कॉम्पेक्टकोड

डेटाबेस @Sohel Rana
चिराग परमार

2

मैंने अपने मामले में किया है। मेरे पास कस्टम विकल्प पूर्व हैं। एल 1, एल 2 और एल 3। मुझे उन्हें कस्टम विशेषता पर मूल्यों के रूप में प्राप्त करने की आवश्यकता है। इसलिए मैंने मॉड्यूल में एक स्रोत फ़ाइल बनाई थी - विक्रेता \ मॉड्यूल \ मॉडल \ कॉन्फ़िगर \ स्रोत \ विकल्प। एफपीपी

इस फ़ाइल में विकल्प बनाने के लिए छोटा कोड होता है, यहाँ आप कोड का पालन कर सकते हैं

 <?php
    /**
     * Copyright © 2013-2017 Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    namespace Vendor\module\Model\Config\Source;
    /**
     * Catalog category landing page attribute source
     *
     * @author      Magento Core Team <core@magentocommerce.com>
     */
    class Options extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
    {
        /**
         * {@inheritdoc}
         * @codeCoverageIgnore
         */
        public function getAllOptions()
        {
            if (!$this->_options) {
                $this->_options = [
                    ['value' => 'l1', 'label' => __('L1')],
                    ['value' => 'l2', 'label' => __('L2')],
                    ['value' => 'l3', 'label' => __('L3')],
                ];
            }
            return $this->_options;
        }
          /**
         * Get options in "key-value" format
         *
         * @return array
         */
        public function toArray()
        {
            return [
                'l1' => __('L1'),
                'l2' => __('L2'),
                'L3' => __('L3'),
                ];
        }

    }

उसके बाद अपने installdata.php में आपको स्रोत के रूप में कॉल करना होगा

$eavSetup->addAttribute(
            Category::ENTITY,
            'category_level_rendering',
            [
                'type' => 'varchar',
                'backend' => '',
                'frontend' => '',
                'label' => 'Category Level rendering',
                'input' => 'select',
                'required' => false,
                'sort_order' => 100,
                'source' => '',
                'visible'  => true,
                'source' => 'vendor\module\Model\Config\Source\Options',
                'default'  => '0',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'General Information',
                'used_in_product_listing' => true,
             ]
        );

फिर लाइन को xml फ़ाइल में भी जोड़ें

<field name="category_level_rendering">
                <argument name="data" xsi:type="array">
/*Here is the code added to get the options on dropdown*/
<item name="options" xsi:type="object">Vendor\module\Model\Config\Source\Options</item>
                    <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">select</item>
                        <item name="label" xsi:type="string" translate="true">Category Level Rendering</item>
                    </item>
                </argument>
            </field>

इसे सहेजें, कैश फ्लश करें और जांच करें।

उम्मीद है कि यह आपकी मदद करता है।

कृपया मुझे जवाब दें अगर यह आपके लिए काम करता है।


मुझे इस प्रकार की त्रुटि मिली: तत्व 'फ़ील्ड': यह तत्व अपेक्षित नहीं है। अपेक्षित एक है (सेटिंग्स, कॉलम, क्रियाएं, कॉलम, सेलेक्शन कॉलम)। पंक्ति: 681
प्रतीक मेहता

आपने डेटा को कैसे बचाया,
मुजाहिद

डेटाबेस @Jdprasad V
चिराग परमार

यह मेरे लिए काम किया है, कृपया फिर से जाँच करें, यदि आपने स्कीमा पृष्ठ पर कोई परिवर्तन किया है।
जादप्रसाद वि।

1
इसके लिए +1। इससे मेरा काम बनता है। ] सरणी में गायब है। मैं इसे संपादित करता हूं।
चिराग परमार
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.