ड्रॉपडाउन के साथ श्रेणी कस्टम विशेषता जोड़ें


10

मुझे कस्टम एट्रीब्यूट की श्रेणी में जोड़ने की आवश्यकता है, 2 मानों के साथ चयन करें:

  • 0 - "नहीं"
  • 1 - "हाँ"

मैंने एक मॉड्यूल बनाया और स्थापना फ़ाइल में इस कोड का उपयोग किया:

$this->startSetup();
$this->addAttribute('catalog_category', 'top_brand', array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Top Hersteller',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'option' => array(
        'value' => array(

            'optionone'=> array(
                0 =>'No'),
            'optiontwo'=> array(
                0 =>'Yes')
        ),

    ),
    'default' => array(0),
    'class'             => '',
    // 'source'            => '',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => '',
    'required'          => false,//or true
    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
));
$this->endSetup();

व्यवस्थापन पैनल में विशेषता दिखाई देती है लेकिन "नहीं" के लिए चयन में जोड़ा गया मूल्य 3 है और "हां" के लिए 4 है। मान 0 और 1 कैसे बनाएं?


@ user4157: जहां मैं इस संबंध को जोड़ सकता हूं,
मणि

जवाबों:


11

इसे इस्तेमाल करे:

$this->startSetup();
$this->addAttribute('catalog_category', 'top_brand', array(
    'group'                => 'General',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Top Hersteller',
    'input'             => 'select', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => '',
    'source'            => 'eav/entity_attribute_source_boolean',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => '',
    'required'          => false,//or true
    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
));
$this->endSetup();

मैं जोड़ा eav/entity_attribute_source_booleanके रूप में sourceअपनी विशेषता के लिए।


@ मॉरिस उत्तर के लिए धन्यवाद। लेकिन सोर्स मॉडल eav/entity_attribute_source_booleanमल्टीसेलेक्ट ऑप्शन के लिए कैसे काम करेगा?
स्लिम्सडैडीय

2
@ विक्रम यदि आप उस सोर्स मॉडल का उपयोग एक मल्टीसेलेक्ट के लिए करते हैं तो आपको 2 विकल्पों के साथ एक बहुस्तरीय दिखाई देगा। Yes/No
मेरियस

@ मेरे लिए हाँ या कोई विशेषता नहीं है जहाँ मुझे फ़ाइल जोड़ना है या इसके लिए नया मॉड्यूल बनाना है
Magento 2

2

श्रेणी में top_brand विशेषता बनाने के लिए नीचे दिए गए कोड का उपयोग करने का प्रयास करें:

   $this->addAttribute( 'catalog_category', 'top_brand', array(
                'group' => 'General',
                'type' => 'tinyint',
                'backend' => '',
                'frontend' => '',
                'label' => 'Top Hersteller',
                'input' => 'boolean',
                'source' => 'eav/entity_attribute_source_boolean',
                'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '', 
                'unique' => false, 
            ) );

1

श्रेणी अनुभाग में कस्टम हां / नहीं विशेषता जोड़ने के लिए कृपया मॉड्यूल बनाएं और निम्नलिखित कोड दर्ज करें।

 <?php
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'featured_product', array(
    'group'         => 'General Information',
    'input'         => 'select',
    'type'          => 'text',
    'label'         => 'Featured Product',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'source' => 'eav/entity_attribute_source_boolean',
));

$this->endSetup();`

कृपया मेरे ट्यूटोरियल को भी देखें।

http://www.pearlbells.co.uk/how-to-add-custom-attribute-dropdown-to-category-section-magento/ (हाँ / नहीं) विशेषता

http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribute-to-magento-category-section/ (कस्टम विकल्प)

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