Thêm thuộc tính tùy chỉnh danh mục với thả xuống


10

Tôi cần thêm vào danh mục thuộc tính tùy chỉnh, chọn với 2 giá trị:

  • 0 - "Không"
  • 1 - "Có"

Tôi đã tạo một mô-đun và sử dụng mã này trong tệp cài đặt:

$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();

Thuộc tính xuất hiện trong bảng quản trị nhưng giá trị gia tăng trong chọn cho "Không" là 3 và cho "Có" là 4. Làm cách nào để tạo giá trị 0 và 1?


@ user4157: Tôi có thể thêm vấn đề này ở đâu,
Gem

Câu trả lời:


11

Thử cái này xem sao:

$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();

Tôi đã thêm eav/entity_attribute_source_booleannhư sourcecho thuộc tính của bạn.


@Maurius cảm ơn vì câu trả lời. Nhưng làm thế nào mô hình nguồn eav/entity_attribute_source_booleansẽ hoạt động cho tùy chọn multiselect?
Slimshadddyyy

2
@Vikram Nếu bạn sử dụng mô hình nguồn đó cho multiselect, bạn sẽ thấy multiselect với 2 tùy chọn. Yes/No.
Marius

@Marius tôi muốn có thuộc tính Có hoặc Không trong đó tôi phải thêm tệp hoặc tạo mô-đun mới cho việc này
Magento 2

2

Hãy thử sử dụng mã dưới đây để tạo thuộc tính top_brand trong danh mục:

   $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

Để thêm thuộc tính có / không tùy chỉnh trong phần danh mục, vui lòng tạo mô-đun và nhập mã sau đây.

 <?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();`

Hãy tham khảo hướng dẫn của tôi là tốt.

http://www.pearlbells.co.uk/how-to-add-custom-attribution-dropdown-to-carget-section-magento/ (có / không) thuộc tính

http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribution-to-magento-carget-section/ (tùy chọn tùy chỉnh)

Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.