create custom category attributes dynamically in admin
I want to create custom category attributes dynamically in admin. I mean, how can I create custom category attributes in my Model class? Please suggest me proper solution to resolve this issue.
magento-1.7 attributes category
|
show 5 more comments
I want to create custom category attributes dynamically in admin. I mean, how can I create custom category attributes in my Model class? Please suggest me proper solution to resolve this issue.
magento-1.7 attributes category
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25
|
show 5 more comments
I want to create custom category attributes dynamically in admin. I mean, how can I create custom category attributes in my Model class? Please suggest me proper solution to resolve this issue.
magento-1.7 attributes category
I want to create custom category attributes dynamically in admin. I mean, how can I create custom category attributes in my Model class? Please suggest me proper solution to resolve this issue.
magento-1.7 attributes category
magento-1.7 attributes category
edited yesterday
Teja Bhagavan Kollepara
2,93841847
2,93841847
asked Sep 26 '13 at 10:16
Lalit Kaushik
38921127
38921127
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25
|
show 5 more comments
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25
|
show 5 more comments
2 Answers
2
active
oldest
votes
create a module Yournamespace_CategoryAttribute.
in app/etc/Yournamespace_CategoryAttribute.xml
<config>
<modules>
<Yournamespace_CategoryAttribute>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_CategoryAttribute>
</modules>
</config>
===========================================
now if you want to use form, in the same module:
in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_CategoryAttribute>
<version>0.1.1</version>
</Yournamespace_CategoryAttribute>
</modules>
<global>
<models>
<categoryattribute>
<classYournamespace_CategoryAttribute_Model</class>
</categoryattribute>
<!-- removed eav_entity_setup rewrite -->
</models>
<blocks>
<categoryattribute>
<class>Yournamespace_CategoryAttribute_Block</class>
</categoryattribute>
</blocks>
</global>
<frontend>
<routers>
<categoryattribute>
<use>standard</use>
<args>
<module>Yournamespace_CategoryAttribute</module>
<frontName>categoryattribute</frontName>
</args>
</categoryattribute>
</routers>
<layout>
<updates>
<yournamespace_categoryattribute>
<file>yournamespace_categoryattribute.xml</file>
</yournamespace_categoryattribute>
</updates>
</layout>
</frontend>
</config>
in YourNamespace/CategoryAttribute/Model/Setup.php
<?php
class Yournamespace_CategoryAttribute_Model_Setup{
public function setAdminAttribute($params){
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('catalog_category', $params['attr_code'], array(
'group' => $params['section'],
'input' => $params['input_type'],
'type' => $params['db_type'],
'label' => $params['attr_label'],
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->endSetup();
}
}
in your controllers/IndexController.php
<?php
class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
public function createAction(){
$formParams = $this->getRequest()->getParams();
Mage::getModel('categoryattribute/setup')->setAdminAttribute($formParams);
}
}
in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php
<?php
class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template
{
}
in
app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<categoryattribute_index_index>
<reference name="content">
<block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />
</reference>
</categoryattribute_index_index>
</layout>
in
app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml
put your form and the form-action should be $baseurl/categoryattribute/
Note:
This can be organised from Admin panel, by adding a admin grid and post these from admin form.
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
|
show 1 more comment
Run this script in your magento root folder to create Attribute
<?php
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('core_setup');
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
$installer->addAttribute('catalog_category', 'shipping_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Short description',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => '0',
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'unique' => false,
'wysiwyg_enabled' => true,
'apply_to' => '',
'is_configurable' => true
));
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);
}
$installer->endSetup();
?>
For Remove Category Attribute
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'shipping_content');
$installer->endSetup();
?>
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f8537%2fcreate-custom-category-attributes-dynamically-in-admin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
create a module Yournamespace_CategoryAttribute.
in app/etc/Yournamespace_CategoryAttribute.xml
<config>
<modules>
<Yournamespace_CategoryAttribute>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_CategoryAttribute>
</modules>
</config>
===========================================
now if you want to use form, in the same module:
in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_CategoryAttribute>
<version>0.1.1</version>
</Yournamespace_CategoryAttribute>
</modules>
<global>
<models>
<categoryattribute>
<classYournamespace_CategoryAttribute_Model</class>
</categoryattribute>
<!-- removed eav_entity_setup rewrite -->
</models>
<blocks>
<categoryattribute>
<class>Yournamespace_CategoryAttribute_Block</class>
</categoryattribute>
</blocks>
</global>
<frontend>
<routers>
<categoryattribute>
<use>standard</use>
<args>
<module>Yournamespace_CategoryAttribute</module>
<frontName>categoryattribute</frontName>
</args>
</categoryattribute>
</routers>
<layout>
<updates>
<yournamespace_categoryattribute>
<file>yournamespace_categoryattribute.xml</file>
</yournamespace_categoryattribute>
</updates>
</layout>
</frontend>
</config>
in YourNamespace/CategoryAttribute/Model/Setup.php
<?php
class Yournamespace_CategoryAttribute_Model_Setup{
public function setAdminAttribute($params){
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('catalog_category', $params['attr_code'], array(
'group' => $params['section'],
'input' => $params['input_type'],
'type' => $params['db_type'],
'label' => $params['attr_label'],
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->endSetup();
}
}
in your controllers/IndexController.php
<?php
class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
public function createAction(){
$formParams = $this->getRequest()->getParams();
Mage::getModel('categoryattribute/setup')->setAdminAttribute($formParams);
}
}
in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php
<?php
class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template
{
}
in
app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<categoryattribute_index_index>
<reference name="content">
<block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />
</reference>
</categoryattribute_index_index>
</layout>
in
app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml
put your form and the form-action should be $baseurl/categoryattribute/
Note:
This can be organised from Admin panel, by adding a admin grid and post these from admin form.
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
|
show 1 more comment
create a module Yournamespace_CategoryAttribute.
in app/etc/Yournamespace_CategoryAttribute.xml
<config>
<modules>
<Yournamespace_CategoryAttribute>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_CategoryAttribute>
</modules>
</config>
===========================================
now if you want to use form, in the same module:
in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_CategoryAttribute>
<version>0.1.1</version>
</Yournamespace_CategoryAttribute>
</modules>
<global>
<models>
<categoryattribute>
<classYournamespace_CategoryAttribute_Model</class>
</categoryattribute>
<!-- removed eav_entity_setup rewrite -->
</models>
<blocks>
<categoryattribute>
<class>Yournamespace_CategoryAttribute_Block</class>
</categoryattribute>
</blocks>
</global>
<frontend>
<routers>
<categoryattribute>
<use>standard</use>
<args>
<module>Yournamespace_CategoryAttribute</module>
<frontName>categoryattribute</frontName>
</args>
</categoryattribute>
</routers>
<layout>
<updates>
<yournamespace_categoryattribute>
<file>yournamespace_categoryattribute.xml</file>
</yournamespace_categoryattribute>
</updates>
</layout>
</frontend>
</config>
in YourNamespace/CategoryAttribute/Model/Setup.php
<?php
class Yournamespace_CategoryAttribute_Model_Setup{
public function setAdminAttribute($params){
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('catalog_category', $params['attr_code'], array(
'group' => $params['section'],
'input' => $params['input_type'],
'type' => $params['db_type'],
'label' => $params['attr_label'],
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->endSetup();
}
}
in your controllers/IndexController.php
<?php
class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
public function createAction(){
$formParams = $this->getRequest()->getParams();
Mage::getModel('categoryattribute/setup')->setAdminAttribute($formParams);
}
}
in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php
<?php
class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template
{
}
in
app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<categoryattribute_index_index>
<reference name="content">
<block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />
</reference>
</categoryattribute_index_index>
</layout>
in
app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml
put your form and the form-action should be $baseurl/categoryattribute/
Note:
This can be organised from Admin panel, by adding a admin grid and post these from admin form.
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
|
show 1 more comment
create a module Yournamespace_CategoryAttribute.
in app/etc/Yournamespace_CategoryAttribute.xml
<config>
<modules>
<Yournamespace_CategoryAttribute>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_CategoryAttribute>
</modules>
</config>
===========================================
now if you want to use form, in the same module:
in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_CategoryAttribute>
<version>0.1.1</version>
</Yournamespace_CategoryAttribute>
</modules>
<global>
<models>
<categoryattribute>
<classYournamespace_CategoryAttribute_Model</class>
</categoryattribute>
<!-- removed eav_entity_setup rewrite -->
</models>
<blocks>
<categoryattribute>
<class>Yournamespace_CategoryAttribute_Block</class>
</categoryattribute>
</blocks>
</global>
<frontend>
<routers>
<categoryattribute>
<use>standard</use>
<args>
<module>Yournamespace_CategoryAttribute</module>
<frontName>categoryattribute</frontName>
</args>
</categoryattribute>
</routers>
<layout>
<updates>
<yournamespace_categoryattribute>
<file>yournamespace_categoryattribute.xml</file>
</yournamespace_categoryattribute>
</updates>
</layout>
</frontend>
</config>
in YourNamespace/CategoryAttribute/Model/Setup.php
<?php
class Yournamespace_CategoryAttribute_Model_Setup{
public function setAdminAttribute($params){
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('catalog_category', $params['attr_code'], array(
'group' => $params['section'],
'input' => $params['input_type'],
'type' => $params['db_type'],
'label' => $params['attr_label'],
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->endSetup();
}
}
in your controllers/IndexController.php
<?php
class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
public function createAction(){
$formParams = $this->getRequest()->getParams();
Mage::getModel('categoryattribute/setup')->setAdminAttribute($formParams);
}
}
in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php
<?php
class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template
{
}
in
app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<categoryattribute_index_index>
<reference name="content">
<block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />
</reference>
</categoryattribute_index_index>
</layout>
in
app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml
put your form and the form-action should be $baseurl/categoryattribute/
Note:
This can be organised from Admin panel, by adding a admin grid and post these from admin form.
create a module Yournamespace_CategoryAttribute.
in app/etc/Yournamespace_CategoryAttribute.xml
<config>
<modules>
<Yournamespace_CategoryAttribute>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_CategoryAttribute>
</modules>
</config>
===========================================
now if you want to use form, in the same module:
in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_CategoryAttribute>
<version>0.1.1</version>
</Yournamespace_CategoryAttribute>
</modules>
<global>
<models>
<categoryattribute>
<classYournamespace_CategoryAttribute_Model</class>
</categoryattribute>
<!-- removed eav_entity_setup rewrite -->
</models>
<blocks>
<categoryattribute>
<class>Yournamespace_CategoryAttribute_Block</class>
</categoryattribute>
</blocks>
</global>
<frontend>
<routers>
<categoryattribute>
<use>standard</use>
<args>
<module>Yournamespace_CategoryAttribute</module>
<frontName>categoryattribute</frontName>
</args>
</categoryattribute>
</routers>
<layout>
<updates>
<yournamespace_categoryattribute>
<file>yournamespace_categoryattribute.xml</file>
</yournamespace_categoryattribute>
</updates>
</layout>
</frontend>
</config>
in YourNamespace/CategoryAttribute/Model/Setup.php
<?php
class Yournamespace_CategoryAttribute_Model_Setup{
public function setAdminAttribute($params){
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
$setup->addAttribute('catalog_category', $params['attr_code'], array(
'group' => $params['section'],
'input' => $params['input_type'],
'type' => $params['db_type'],
'label' => $params['attr_label'],
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->endSetup();
}
}
in your controllers/IndexController.php
<?php
class Yournamespace_CategoryAttribute_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
public function createAction(){
$formParams = $this->getRequest()->getParams();
Mage::getModel('categoryattribute/setup')->setAdminAttribute($formParams);
}
}
in Yournamspace/CategoryAttribute/Block/CategoryAttribute.php
<?php
class Yournamespace_CategoryAttribute_Block_CategoryAttribute extends Mage_Core_Block_Template
{
}
in
app/design/frontend/your_theme/default/layout/yournamespace_categoryattribute.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<categoryattribute_index_index>
<reference name="content">
<block type="categoryattribute/categoryattribute" name="categoryattribute" template="categoryattribute/categoryattribute.phtml" />
</reference>
</categoryattribute_index_index>
</layout>
in
app/design/frontend/your_theme/default/template/categoryattribute/categoryattribute.phtml
put your form and the form-action should be $baseurl/categoryattribute/
Note:
This can be organised from Admin panel, by adding a admin grid and post these from admin form.
edited Sep 27 '13 at 11:15
answered Sep 26 '13 at 11:24
Shathish
1,99922455
1,99922455
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
|
show 1 more comment
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I am getting this error in Setup.php Model file: "Fatal error: Call to a member function startSetup() on a non-object"
– Lalit Kaushik
Sep 26 '13 at 13:15
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
I've made changes to config.xml as suggested.
– Shathish
Sep 27 '13 at 4:09
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
Can you please suggest me how can I resolve this error "Fatal error: Call to a member function select() on a non-object"? I am getting this error in Setup.php Model file.
– Lalit Kaushik
Sep 27 '13 at 5:23
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
can you post the full errror?
– Shathish
Sep 27 '13 at 8:18
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
"Fatal error: Call to a member function select() on a non-object in appcodecoreMageCoreModelResourceSetup.php on line 734 "
– Lalit Kaushik
Sep 27 '13 at 8:43
|
show 1 more comment
Run this script in your magento root folder to create Attribute
<?php
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('core_setup');
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
$installer->addAttribute('catalog_category', 'shipping_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Short description',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => '0',
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'unique' => false,
'wysiwyg_enabled' => true,
'apply_to' => '',
'is_configurable' => true
));
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);
}
$installer->endSetup();
?>
For Remove Category Attribute
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'shipping_content');
$installer->endSetup();
?>
add a comment |
Run this script in your magento root folder to create Attribute
<?php
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('core_setup');
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
$installer->addAttribute('catalog_category', 'shipping_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Short description',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => '0',
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'unique' => false,
'wysiwyg_enabled' => true,
'apply_to' => '',
'is_configurable' => true
));
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);
}
$installer->endSetup();
?>
For Remove Category Attribute
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'shipping_content');
$installer->endSetup();
?>
add a comment |
Run this script in your magento root folder to create Attribute
<?php
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('core_setup');
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
$installer->addAttribute('catalog_category', 'shipping_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Short description',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => '0',
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'unique' => false,
'wysiwyg_enabled' => true,
'apply_to' => '',
'is_configurable' => true
));
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);
}
$installer->endSetup();
?>
For Remove Category Attribute
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'shipping_content');
$installer->endSetup();
?>
Run this script in your magento root folder to create Attribute
<?php
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('core_setup');
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
if (!$installer->getAttributeId($entityTypeId, 'shipping_content')) {
$installer->addAttribute('catalog_category', 'shipping_content', array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Short description',
'input' => 'textarea',
'class' => '',
'source' => '',
'global' => '0',
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'unique' => false,
'wysiwyg_enabled' => true,
'apply_to' => '',
'is_configurable' => true
));
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($entityTypeId, 'shipping_content', 'is_html_allowed_on_front', 1);
}
$installer->endSetup();
?>
For Remove Category Attribute
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$installer->startSetup();
$installer->removeAttribute('catalog_category', 'shipping_content');
$installer->endSetup();
?>
answered Dec 1 '16 at 11:32
Ketan Borada
91631
91631
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f8537%2fcreate-custom-category-attributes-dynamically-in-admin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
are you specific you want to do that with Model? if yes why? if no it's so simple to do this.
– Shathish
Sep 26 '13 at 10:53
Thanks for your response. As I specified I want to create custom attributes dynamically. so I think Model or Controller class is the best way to create attributes (sorry I forgot to mention controller class in my question). If it's possible through other simple way, please suggest.
– Lalit Kaushik
Sep 26 '13 at 10:53
what do you mean by the word "dynamically"? do you want to create it from a form or what?
– Shathish
Sep 26 '13 at 11:05
Yes, exactly I want to create attributes through form.
– Lalit Kaushik
Sep 26 '13 at 11:08
now I've posted answer which will create it programatically. I'll post the answer using form later :)
– Shathish
Sep 26 '13 at 11:25