MatheusJardimB
MatheusJardimB

Reputation: 3677

Magento - Bundle product inside bundle products (Almost working)

I'm trying to add bundle products inside another bundle product. It's quite simple to achieve my status. Edit the file /app/code/Mage/Bundle/etc/config.xml like this:

                ...
                <allowed_selection_types>
                    <simple/>
                    <bundle/> <!-- Add this at line 104-->
                    <virtual/>
                </allowed_selection_types>
                ...

By doing so, you'll be able to successfully create a bundle product with another bundled products inside of it!

My problem is that I can't add this product to an order, via AdminPanel or SOAP (didn't tried trough frontend, but probably doesn't work too).

When I click "Add Selected Product(s) to Order" in the Admin Panel I get the following error:

[19-Jun-2013 15:52:48 UTC] PHP Fatal error:  Call to a member function getPosition() on a non-object in app\code\core\Mage\Bundle\Model\Product\Type.php on line 865

The crash occurs at shakeSelections($a, $b): the code $a->getOption() doesn't returns a object. It's not null and it's also not an object (I'm a PHP noobie, so it doesn't make sense to me).

==Update==

Now I'm able to add this new kind of products into the cart! I've edited the file app\code\core\Mage\Bundle\Model\Product\Type.php, so now I have the following code:

...
/*
 * Create extra attributes that will be converted to product options in order item
* for selection (not for all bundle)
*/
$price = $product->getPriceModel()->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
$attributes = array(
        'price'         => Mage::app()->getStore()->convertPrice($price),
        'qty'           => $qty,
        'option_label'  => is_null($selection->getOption()) ? '' : $selection->getOption()->getTitle(),
        'option_id'     => is_null($selection->getOption()) ? 0 : $selection->getOption()->getId()
);

$type = $selection->getTypeInstance(true);
if (get_class($type) != 'Mage_Bundle_Model_Product_Type'){
    $_result = $selection->getTypeInstance(true)->prepareForCart($buyRequest, $selection);
}
...

and also the function below:

public function shakeSelections($a, $b)
{
    $ta = $a->getOption();
    $tb = $b->getOption();

    $aPosition = array(
            is_null($ta) ? 0 : $ta->getPosition(),
            $a->getOptionId(),
            $a->getPosition(),
            $a->getSelectionId()
    );
    $bPosition = array(
            is_null($tb) ? 0 : $tb->getPosition(),
            $b->getOptionId(),
            $b->getPosition(),
            $b->getSelectionId()
    );
    if ($aPosition == $bPosition) {
        return 0;
    } else {
        return $aPosition < $bPosition ? -1 : 1;
    }
}

I'm investigating to discover possible side effects I've introduced. At this moment I see that there will exist problems with the stock management of this bundle of bundled products.

Please post your updates if your go any further. Thanks a lot!

== Second EDIT ==

I've started this repo at github, so that you can follow my progress and maybe help me somehow.

https://github.com/matheusjadimb/MagentoBundleOfBundled

Upvotes: 3

Views: 1949

Answers (1)

MatheusJardimB
MatheusJardimB

Reputation: 3677

Just don't do it!

I had a lot of hard times trying to get this working properly. I learned that you should create your own product types instead of editing existing ones.

Upvotes: 2

Related Questions