6

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);
    }
}

1 Answer 1

2

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.

4
  • Then i'm confused because addFilterByRequiredOptions() adds the following query into the collection for associated products ((e.required != '1') OR (e.required IS NULL)) which compensates for both required and not required, thus the article above is not accurate? Also if you look at the last comments in that article (from 2014) this suggest it's a solution to a version prior to 1.8.
    – Ash
    Commented Jan 24, 2014 at 17:50
  • Did you try? I just tried it on magento version 1.8.0.0 and it works. Commented Jan 24, 2014 at 19:20
  • Then it must have been a recent change in 1.8.1.0, and yes when I set custom options on a simple product and they were not required they were omitted from the grouped products associated products (as I have stated above). In my question you can see the example code is a direct copy of the core code with one line commented out.
    – Ash
    Commented Jan 25, 2014 at 20:03
  • If you have developer mode turned on you will run into warnings when doing this. Bug? Feature? I'm not sure anyone knows. Either way, it's asking for trouble.
    – pspahn
    Commented Oct 30, 2014 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.