0

I need to get the id of each product which composes the bundle product. There is this foreach ($optionsArray as $_option) in public function getJsonConfig() from \app\code\core\Mage\Bundle\Block\Catalog\Product\View\Type\Bundle.php I need for each product which is in the bundle I want to get a custom attribute. I tried some solution but I am not able to get what I need

4

you get all bundle product ids by using below code

$childrenIdArray = Mage::getResourceSingleton('bundle/selection')
            ->getChildrenIds($parentId, $required=true);
| improve this answer | |
1

Look at method of class Mage_Bundle_Helper_Catalog_Product_Configuration

/**
 * Get bundled selections (slections-products collection)
 *
 * Returns array of options objects.
 * Each option object will contain array of selections objects
 *
 * @return array
 */
public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
    $options = array();
    $product = $item->getProduct();

    /**
     * @var Mage_Bundle_Model_Product_Type
     */
    $typeInstance = $product->getTypeInstance(true);

    // get bundle options
    $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
    $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
    if ($bundleOptionsIds) {
        /**
        * @var Mage_Bundle_Model_Mysql4_Option_Collection
        */
        $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);

        // get and add bundle selections collection
        $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');

        $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());

        if (!empty($bundleSelectionIds)) {
            $selectionsCollection = $typeInstance->getSelectionsByIds(
                unserialize($selectionsQuoteItemOption->getValue()),
                $product
            );

            $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
            foreach ($bundleOptions as $bundleOption) {
                if ($bundleOption->getSelections()) {
                    $option = array(
                        'label' => $bundleOption->getTitle(),
                        'value' => array()
                    );

                    $bundleSelections = $bundleOption->getSelections();

                    foreach ($bundleSelections as $bundleSelection) {
                        $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
                        if ($qty) {
                            $option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
                                . ' ' . Mage::helper('core')->currency(
                                    $this->getSelectionFinalPrice($item, $bundleSelection)
                                );
                        }
                    }

                    if ($option['value']) {
                        $options[] = $option;
                    }
                }
            }
        }
    }

    return $options;
}
| improve this answer | |
0

Thank you for your answers. I had to dig deeper in app\code\local\OSF\Bundle\Block\Catalog\Product\View\Type\Bundle.php I added in function getJsonConfig() my extra data which I needed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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