0

So I'm trying to add a bundled product to a quote programmatically in a module. When I add an item to the cart directly from the front-end, it works just fine. However, when I do it programmatically, I get an error message:

Please specify product option(s).

The function invocation I'm doing looks a little like this:

$productID = Mage::getModel('catalog/product')->getIdBySku('PKGTEST');
$product = Mage::getModel('catalog/product')->load($productID);

$result = $quote->addProduct($product, new Varien_Object([
    'product' => $productID,
    'qty' => 1,
]));
if ($result) {
    throw new Exception($result);
}

What is going on here? How do I add this bundled product to my quote?


As an aside, I did notice that some answers to questions about bundled products on this site have bundle_option as a part of the Varien_Object. However, the way I have my bundled product set up - the bundle actually has no user-selectable options - means I can skip that field.

1 Answer 1

0

The problem turned out to be with the way I was retrieving the product.

$product = Mage::getModel('catalog/product')->load($productID);

The problem with this invocation is that although I am loading the product, the product is ignorant of which storefront it is being loaded for. The correct invocation is this:

$product = Mage::getModel('catalog/product')->setStoreId($storeID)->load($productID);

Setting the Storefront ID, among other things, fills out a very important data field called is_salable in the product. Without that field, Magento doesn't think that any of the selections for a bundled product are valid because they aren't salable, thus resulting in the error message as described above.

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.