I programmatically updated my indexes (Thanks Marius):
require_once('app/Mage.php');
Mage::app('default');
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*');
foreach ($categories as $category) {
$process = Mage::getModel('index/process')->load(5); $process->reindexAll();
$process = Mage::getModel('index/process')->load(6); $process->reindexAll();
$cat = Mage::getModel("catalog/category")->load($category->getId());
var_dump($cat->getData('mymodule_myattribute')); // Gives result
var_dump($cat->getMymoduleMyattribute()); // Gives result
var_dump($cat->getName()); // My Cool Category Name
}
Well first it seems that there is an obvious error with $installer->startSetup();
missing near the start, then you may also need to define the backend used for the attribute in order to save it:
'backend' => 'eav/entity_attribute_backend_array',
Otherwise instead of:
$installer = new Mage_Sales_Model_Mysql4_Setup;
i would try to use:
$installer = new Mage_Eav_Model_Entity_Setup('default_setup');
My two cents hoping it helps you if still needed. :)
the modified code:
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Eav_Model_Entity_Setup('default_setup');
$installer->startSetup();
$attribute = array(
'type' => 'text',
'label'=> 'Room Type',
'input' => 'multiselect',
'backend' => 'eav/entity_attribute_backend_array',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information",
'option' => array (
'value' => array(
'kitchen' => array('Kitchen'),
'bedroom' => array('Bedroom'),
'bathroom' => array('Bathroom'),
'loft' => array('Loft'),
'basement' => array('Basement'),
'lounge' => array('Lounge')
)
)
);
$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'room_type', $attribute);
$installer->endSetup();
Best Answer
This is quite a big answer.
In Magento 2.1.0 you need to apply a patch to create a additional file upload attribute for category.
As they are using hardcoded values for image attribute on many places. for more details have a look at link1 and link2
Steps to apply a patch.
1) Edit composer.json file located at root directory as follows.
As mentioned on link2 above newly added code is in extra and require.
2) Create a patches folder on root directory.
3) Create file Patch-Magento_Catalog-M2.1.0-image-attribute-backend-model-hardcoded-attribute-code-removal.patch under patches folder with following contains.
4) Create file Patch-Magento_Ui-M2.1.0-allow-backend-to-know-the-origin-input-of-the-upload-request.patch under patches folder with following contains.
5) Run following Commands
6) Now its time to create your module for new file upload option.
Create a file
Create a file
Create a file
Create a file
Hope this helps you.