Magento – Why can’t Simple Products with options be grouped

custom-optionsmagento-1.8overridesproduct

Synopsis

I have a store where-by I create a Grouped Product and associate a number of Simple Products. When I add custom options to the simple products it is not visible in the Grouped Products' Associated Products Grid neither the Front-End.

However I have implemented a local, custom module to amend this behaviour, but what I would like to know is:

  • What are the reasons for this behaviour in Magento?
  • Is my module a good/bad idea?

Sources

config.xml

<global>
    <blocks>
        <adminhtml>
            <rewrite>
                <catalog_product_edit_tab_super_group>Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group</catalog_product_edit_tab_super_group>
            </rewrite>
        </adminhtml>
    </blocks>
    <models>
        <catalog>
            <rewrite>
                <product_type_grouped>Vendor_Catalog_Model_Product_Type_Grouped</product_type_grouped>
            </rewrite>
        </catalog>
    </models>
</global>

Block/Adminhtml/Catalog/Product/Edit/Tab/Super/Group.php

<?php

class Vendor_Catalog_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group
    extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group
{
    protected function _prepareCollection()
    {
        $allowProductTypes = array();
        $allowProductTypeNodes = Mage::getConfig()
            ->getNode('global/catalog/product/type/grouped/allow_product_types')->children();
        foreach ($allowProductTypeNodes as $type) {
            $allowProductTypes[] = $type->getName();
        }

        $collection = Mage::getModel('catalog/product_link')->useGroupedLinks()
            ->getProductCollection()
            ->setProduct($this->_getProduct())
            ->addAttributeToSelect('*')
            #->addFilterByRequiredOptions() # removed this
            ->addAttributeToFilter('type_id', $allowProductTypes);

        if ($this->getIsReadonly() === true) {
            $collection->addFieldToFilter('entity_id', array('in' => $this->_getSelectedProducts()));
        }
        $this->setCollection($collection);

        $parent = get_parent_class(get_parent_class($this));
        return $parent::_prepareCollection();
    }
}

Vendor/Catalog/Model/Product/Type/Grouped.php

<?php

class Vendor_Catalog_Model_Product_Type_Grouped
    extends Mage_Catalog_Model_Product_Type_Grouped
{
    public function getAssociatedProducts($product = null)
    {
        if (! $this->getProduct($product)->hasData($this->_keyAssociatedProducts)) {
            $associatedProducts = array();

            if (! Mage::app()->getStore()->isAdmin()) {
                $this->setSaleableStatus($product);
            }

            $collection = $this->getAssociatedProductCollection($product)
                ->addAttributeToSelect('*')
                #->addFilterByRequiredOptions() # removed this
                ->setPositionOrder()
                ->addStoreFilter($this->getStoreFilter($product))
                ->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));

            foreach ($collection as $item) {
                $associatedProducts[] = $item;
            }

            $this->getProduct($product)->setData($this->_keyAssociatedProducts, $associatedProducts);
        }
        return $this->getProduct($product)->getData($this->_keyAssociatedProducts);
    }
}

Best Answer

In this article is described how to associate simple products(containing custom options) with group product.

So if you wish to have simple products with custom options listed, be sure you don’t set any of the custom options to be required.

I hope this will solve your problem.