Adding custom column into product grid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT
And here is the code which creates the "postion_simple".
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);
magento-1.9 product configurable-product event-observer grid
bumped to the homepage by Community♦ 9 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT
And here is the code which creates the "postion_simple".
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);
magento-1.9 product configurable-product event-observer grid
bumped to the homepage by Community♦ 9 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44
add a comment |
I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT
And here is the code which creates the "postion_simple".
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);
magento-1.9 product configurable-product event-observer grid
I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT
And here is the code which creates the "postion_simple".
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);
magento-1.9 product configurable-product event-observer grid
magento-1.9 product configurable-product event-observer grid
edited May 4 '16 at 7:13
Siarhey Uchukhlebau
10.2k93058
10.2k93058
asked Dec 6 '15 at 19:23
Capri82Capri82
486
486
bumped to the homepage by Community♦ 9 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 9 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44
add a comment |
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44
add a comment |
1 Answer
1
active
oldest
votes
- change
'index' => 'position_simple'to'index' => 'entity_id'in your Observer.php (function addPositionColumn) - you need to get value of your
position_simpleattribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.
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%2f92789%2fadding-custom-column-into-product-grid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- change
'index' => 'position_simple'to'index' => 'entity_id'in your Observer.php (function addPositionColumn) - you need to get value of your
position_simpleattribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.
add a comment |
- change
'index' => 'position_simple'to'index' => 'entity_id'in your Observer.php (function addPositionColumn) - you need to get value of your
position_simpleattribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.
add a comment |
- change
'index' => 'position_simple'to'index' => 'entity_id'in your Observer.php (function addPositionColumn) - you need to get value of your
position_simpleattribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.
- change
'index' => 'position_simple'to'index' => 'entity_id'in your Observer.php (function addPositionColumn) - you need to get value of your
position_simpleattribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.
answered Apr 20 '16 at 7:40
tesar.hktesar.hk
306
306
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.
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%2f92789%2fadding-custom-column-into-product-grid%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
have you checked that your observer is working ? check by printing query in your observer.echo $collection->getSelect();
– Minesh Patel
Dec 7 '15 at 5:17
@MineshPatel, Yes, the observer is working. I was already sure about it but still checked it by printing the query.
– Capri82
Dec 7 '15 at 12:44