I have extended the controller Catalog/ProductController.php
and I can't get related products to save when clicking the Save button.
Saving data on the attributes tab works as normal, but it's just the related products tab that isn't saving. (I'm only using 2 tabs.)
After clicking the save button, it redirects normally as if it worked and it says The product has been saved.
-
I have added a debug statement to the controller that I extend:
public function saveAction()
{
print_r($_POST);exit;
...
}
which gave me this output:
Array
(
[links] => Array
(
[related] =>
)
)
So it looks like there aren't any related products being sent to the server-side.
-
Here are my files.
app/code/local/NS1/MyModule/ManageComponentsController.php
<?php
require_once 'Catalog/ProductController.php';
class NS1_MyModule_ManageComponentsController extends Mage_Adminhtml_Catalog_ProductController
{
}
app/design/adminhtml/default/default/layout/MyModule.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<adminhtml_managecomponents_grid>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/catalog_product_ComponentsGridForAttachComponents" name="admin.product.grid"/>
</block>
</adminhtml_managecomponents_grid>
<adminhtml_managecomponents_new>
<update handle="editor"/>
<reference name="content">
<block type="MyModule/adminhtml_catalog_product_edit" name="product_edit"></block>
</reference>
<reference name="left">
<block type="adminhtml/catalog_product_edit_tabs" name="product_tabs"></block>
</reference>
<reference name="js">
<block type="adminhtml/catalog_product_edit_js" template="catalog/product/js.phtml" name="catalog_product_js"></block>
<block type="core/template" template="catalog/wysiwyg/js.phtml"/>
</reference>
</adminhtml_managecomponents_new>
<adminhtml_managecomponents_edit>
<update handle="editor"/>
<reference name="content">
<block type="MyModule/adminhtml_catalog_product_edit" name="product_edit"></block>
</reference>
<reference name="left">
<block type="adminhtml/store_switcher" name="store_switcher" before="-"></block>
<block type="adminhtml/catalog_product_edit_tabs" name="product_tabs"></block>
</reference>
<reference name="js">
<block type="adminhtml/catalog_product_edit_js" template="catalog/product/js.phtml" name="catalog_product_js"></block>
<block type="core/template" name="catalog.wysiwyg.js" template="catalog/wysiwyg/js.phtml"/>
</reference>
</adminhtml_managecomponents_edit>
<adminhtml_managecomponents_related>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/catalog_product_edit_tab_related" name="catalog.product.edit.tab.related"/>
<block type="adminhtml/widget_grid_serializer" name="related_grid_serializer">
<reference name="related_grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>catalog.product.edit.tab.related</grid_block_name>
<data_callback>getSelectedRelatedProducts</data_callback>
<hidden_input_name>links[related]</hidden_input_name>
<reload_param_name>products_related</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
</adminhtml_managecomponents_related>
<adminhtml_managecomponents_relatedgrid>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/catalog_product_edit_tab_related" name="catalog.product.edit.tab.related"/>
</block>
</adminhtml_managecomponents_relatedgrid>
...
</layout>
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php
class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Related extends Mage_Adminhtml_Block_Widget_Grid
{
...
protected function _prepareCollection()
{
$collection = Mage::getModel('catalog/product_link')->useRelatedLinks()
->getProductCollection()
->setProduct($this->_getProduct())
->addAttributeToSelect('*')
->addAttributeToFilter('attribute_set_id', 9); // <------ added this line
if ($this->isReadonly()) {
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = array(0);
}
$collection->addFieldToFilter('entity_id', array('in' => $productIds));
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
...
// Some columns have been commented out.
protected function _prepareColumns()
{
if (!$this->isReadonly()) {
$this->addColumn('in_products', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'align' => 'center',
'index' => 'entity_id'
));
}
$this->addColumn('entity_id', array(
'header' => Mage::helper('catalog')->__('ID'),
'sortable' => true,
'width' => 60,
'index' => 'entity_id'
));
$this->addColumn('name', array(
'header' => Mage::helper('catalog')->__('Component Name'),
'index' => 'name'
));
/*
$this->addColumn('type', array(
'header' => Mage::helper('catalog')->__('Type'),
'width' => 100,
'index' => 'type_id',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
));
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->addColumn('set_name', array(
'header' => Mage::helper('catalog')->__('Attrib. Set Name'),
'width' => 130,
'index' => 'attribute_set_id',
'type' => 'options',
'options' => $sets,
));
*/
$this->addColumn('status', array(
'header' => Mage::helper('catalog')->__('Status'),
'width' => 90,
'index' => 'status',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
));
$this->addColumn('visibility', array(
'header' => Mage::helper('catalog')->__('Visibility'),
'width' => 90,
'index' => 'visibility',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(),
));
$this->addColumn('sku', array(
'header' => Mage::helper('catalog')->__('SKU'),
'width' => 80,
'index' => 'sku'
));
/*
$this->addColumn('price', array(
'header' => Mage::helper('catalog')->__('Price'),
'type' => 'currency',
'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
'index' => 'price'
));
$this->addColumn('position', array(
'header' => Mage::helper('catalog')->__('Position'),
'name' => 'position',
'type' => 'number',
'validate_class' => 'validate-number',
'index' => 'position',
'width' => 60,
'editable' => !$this->_getProduct()->getRelatedReadonly(),
'edit_only' => !$this->_getProduct()->getId()
));
*/
return parent::_prepareColumns();
}
...
}