Alex Hadley
Alex Hadley

Reputation: 2125

magento add bundle item directly to cart from upsell - predefined options

I'm trying to add a bundled item to the cart from the upsell area with the options preselected - so it will take you directly to the cart and not the item page, and am using the following url:

Mage::$this->helper('checkout/cart')->getAddUrl($_link)

concatenated with, for example:

?bundle_option[14][]=16&bundle_option[15][]=17&bundle_option[16][]=19&

This url then adds the item to the cart, but with the warning:

Some of the products below do not have all the required options. Please edit them and configure all the required options.

And will not let me continue to the checkout. It also contains the usual add to cart success message.

If I add the item from it's own page (with all default options) it works fine.

I have it set up as per Add bundle product to cart without having to specify the options, with required radio buttons and defaults selected.

Also, adding options_bundle_qty[... options to the url doesn't help.

Update: I have exactly the same setup on a 1.4 and a 1.6 install, it is working in 1.4, but not 1.6

Upvotes: 3

Views: 2562

Answers (1)

B00MER
B00MER

Reputation: 5491

You may want to try and create a single test.php file with something like:

$params = array(
    'product' => 164,
    'related_product' => null,
    'bundle_option' => array(
        21 => 58,
        20 => 55,
        11 => 28,
        12 => array(
            0 => 31,
        ),
        13 => array(
            0 => 32,
            1 => 35,
        ),
    ),
    'options' => array(
        3 => 'olaaaaaaaa',
    ),
    'qty' => 2,
);

$cart = Mage::getSingleton('checkout/cart');

$product = new Mage_Catalog_Model_Product();
$product->load(164);

$cart->addProduct($product, $params);
$cart->save();

Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

$message = $this->__('Custom message: %s was successfully added to your shopping cart.', $product->getName());
Mage::getSingleton('checkout/session')->addSuccess($message);

To test and debug adding product bundles, so its easier to pinpoint any issues. Obviously you'll want to edit the product ID's and options to relate to the data your needing.

Hope this helps.

Upvotes: 4

Related Questions