Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Problem Adding a new field to Grouped Product Associated Products list
 
nathus
Sr. Member
 
Total Posts:  93
Joined:  2008-12-13
Twin Cities, MN
 

For a store I am building, we are using grouped products to show all of the parts that go into a specific item, and using a breakdown image that labels all of the parts. We want to have a column on the grouped product list that shows the part label.

We can’t use an attributed assigned to the simple products since a part might be used in different breakdowns and have different part labels on each diagram.

I need to add a new field to the grouped products associated product links so that I can set the label. I have worked out something that works, sort of.

I modified the catalog_product_link_attribute table adding a new item with the following information.

link_type_id 3
product_link_attribute_code 
breakdown_part_no
data_type 
varchar

I modified the Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php adding the following to the _prepareColumns method

$this->addColumn('breakdown_part_no', array(
    
'header'    => Mage::helper('catalog')->__('Part No'),
    
'name'      => 'breakdown_part_no',
    
'type'      => 'varchar',
    
'index'     => 'breakdown_part_no',
    
'width'     => '60px',
    
'editable'  => true,
));

This adds the column to the grid, and I can save the data and it works fine.

The problem that I am having is that if I edit the product and save it, it deletes all of the data from the new column. However, if I go to the Associated Products tab and click inside one of the text boxes for an item (which makes the interface show the disk icon on the Associated Product tab label), that specific item will save its data for the new column.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nathus
Sr. Member
 
Total Posts:  93
Joined:  2008-12-13
Twin Cities, MN
 

So, after 8 hours of trying to figure out why it wasn’t working right, I get an idea 30 seconds after posting my question and was able to fix it.

The problem was that the data for the new column wasn’t being added to the serialized object unless the item was modified.

In the Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php I modified the getProductJSON method to include the field. This seems like it should be something that would be done automically.

public function getProductsJSON()
{
    $result 
= array();
    if (
$this->getProducts()) {
        $isEntityId 
$this->getIsEntityId();
        foreach (
$this->getProducts() as $product{
            $id 
$isEntityId $product->getEntityId() : $product->getId();
            
$result[$id] $product->toArray(array('qty''position''breakdown_part_no'));
        
}
    }
    
return $result Zend_Json_Encoder::encode($result) : '{}';
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
sucitivel
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2009-07-21
Chicago, IL
 

I want to reach through the internet and shake your hand man… i knew this was the problem but i couldn’t for the life of me find where i was serializing the data.

You are my hero of the day, thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top