2

I have followed a few tutorials on the net and ran a few searches on SO. What I want to do is create a custom select box on the admin category section. So users can select an option yes or no.

I followed a tutorial and so far came with this, but nothing appears once I delete my var/cache folder. This is my setup.

/app/code/local/Adept_Catlanding/sql/adept_catlanding_setup/mysql4-install-0.3.0.php
/app/code/local/Adept_Catlanding/etc/config.xml
/app/etc/modules/Adept_Catlanding.xml

These are the code files:

Adept_Catlanding.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Adept_Catlanding>
            <active>true</active>
            <codePool>local</codePool>
        </Adept_Catlanding>
    </modules>
</config>

mysql4-install-0.3.0.php

<?php

$installer = $this;
$installer->startSetup();

/**
 * This is an entity associated with catalog_category
 * @var  integer
 */
$entityTypeId     = $installer->getEntityTypeId('catalog_category');

/**
 * Use the default attribute set for catalog_category -- this refers to the table `eav_attribute_set`
 * In my case, it's 3, but this function should automatically get that for you.
 * @var integer
 */
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);

/**
 * This determines what group (tab) that the field will be placed. "General Information" 
 * is the default tab, and I'm okay with this, but see `eav_attribute_group` for other
 * groups
 * @var integer
 */
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

/**
 * Let's set up our attribute, customize the type as needed (e.g. int, varchar, decimal)
 * Note where I've used `internal_title` and change to your variable.
 */
$installer->addAttribute('catalog_category', 'internal_title',  array(
    'type'     => 'varchar', /* Type - see eav_entity_* for the different types */
    'label'    => 'Enable Brand link?', /* Your label */
    'input'    => 'select', /* This refers to the type of form field should display*/
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => TRUE,
    'required'          => FALSE,
    'user_defined'      => FALSE,
    'default'           => ''
));

/**
 * Now, add the attribute to the proper attribute group - again, replace the variable title
 * with yours.
 */
$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'brandislinked',
    '2' /* Refers to the sort order of fields - see `eav_entity_attribute` for reference on the location of other fields.  I want this right below the active field, so 2 works for me.*/
);

$installer->endSetup();

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Adept_Catlanding>
            <!-- Make sure that the version number matches the filename on your install script! -->
            <version>0.3.0</version>
        </Adept_Catlanding>
    </modules>
    <global>
        <resources>
            <adept_catlanding_setup>
                <setup>
                    <module>Adept_Catlanding</module>
                    <!-- This next line is absolutely critical so that we call the appropriate setup class --> 
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </setup>
            </adept_catlanding_setup>
            <adept_catlanding_setup_write>
              <connection>
                <use>core_write</use>
              </connection>
            </adept_catlanding_setup_write>
            <adept_catlanding_setup_read>
              <connection>
                <use>core_read</use>
              </connection>
            </adept_catlanding_setup_read>
        </resources>
    </global>
</config>

I am using Magento 1.9 CE for the development environment and EE for the live environment.

2 Answers 2

3

try like this in installer script,

<?php 
$installer = $this;
$installer->startSetup();
//First Remove the custom attribute this after install again
$nameAttribute  = array(
    'type' => 'varchar',
    'label'=> 'Enable Brand link',
    'input' => 'select',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'default' => '',
    'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'internal_title', $nameAttribute); 
$installer->endSetup();
1
  • It still is not appearing. Commented Jun 8, 2015 at 10:35
1

Please add the attribute and add the option as model.

<?php
 $this->startSetup();
 $this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'custom_dropdown',     array(
'group'         => 'General Information',
'input'         => 'select',
'type'          => 'text',
'label'         => 'Custom Dropdown',
'backend'       => '',
'visible'       => true,
'required'      => false,
'visible_on_front' => true,
'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'source' => 'customfeaturedattribute/source_custom',
));
 $this->endSetup();

Inside the model file enter

<?php

class Addpeople_CustomFeaturedAttribute_Model_Source_Custom extends  Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
public function getAllOptions()
{
    $options = array(
        1 => 'One',
        2 => 'Two',
        3 => 'Three'
    );

    return $options;
}
}

Please refer my tutorial for the file structure and step by step explanation http://www.pearlbells.co.uk/how-to-add-custom-dropdown-attribute-to-magento-category-section/

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.