简体   繁体   中英

Magento - Create an Attribute and Applied it to specified product type

I have created an attribute for my extension from this tutorials -

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module

It's the best one I have found on the google.

Acutally I also created a custom type for product, type name is "custom_product", label is "custom product". After I added the attribute, I found it applied to every product type, so how can I just applied it to "custom product" type? So when it only displayed in new "custom product" page?

Thanks.

Use this:

$this->addAttribute('catalog_product', 'custom_product', array(
    'type'                       => 'int',
    'label'                      => 'Custom Product',
    'input'                      => 'select',
    'required'                   => false,
    'user_defined'               => true,
    'searchable'                 => true,
    'filterable'                 => true,
    'comparable'                 => true,
    'visible_in_advanced_search' => true,
    //this is the line that adds it to a type of product
    'apply_to'                   => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE.','.Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, 
    'group'                      => 'General',
));

Check the class Mage_Catalog_Model_Product_Type for all available types and pick yours. You can add as many types as you want separated by comma.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM