0

I'm working in a module that will add products to cart via chatbot, and I'm having some issues when the product has custom options. Since do not know the possible options required to the product, I'm trying to "force" add a product with custom option (or not) to the cart, but everytime I'm getting a message asking to specify some product custom option:

2017-02-26T17:24:28+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Please specify product link(s).' in /home/werules/testbots.tk/store/app/Mage.php:595
Stack trace:
#0 /home/werules/store/app/code/core/Mage/Checkout/Model/Cart.php(287): Mage::throwException('Please specify ...')
#1 /home/werules/store/app/code/community/Werules/Chatbot/Model/Chatdata.php(243): Mage_Checkout_Model_Cart->addProduct(Object(Mage_Catalog_Model_Product), Array)

Here is my code so far:

$product = Mage::getModel('catalog/product')->load($prodId);
$product->setSkipCheckRequiredOption(true);
$cart->addProduct($product, array());
$cart->save();
$checkout->setCartWasUpdated(true);

I'm using setSkipCheckRequiredOption but it dosen't seems to be working.

How can I accomplish that? Either ignoring any requirements or setting them to any default value would work for me.

Best

1
  • What version of magento you use ?
    – PЯINCƎ
    Feb 27, 2017 at 0:51

1 Answer 1

0

You can try this way :

$session = Mage::getSingleton('customer/session'); 
// Get cart instance
$cart = Mage::getSingleton('checkout/cart'); 
$cart->init();
$productid=1;
$qty=1;
// Add a product without custom options
$productInstance = Mage::getModel('catalog/product')->load($productid);
$param = array(
  'product' => $productInstance->getId(),
  'qty' => $qty
 );
 $request = new Varien_Object();
 $request->setData($param);
 $cart->addProduct($productInstance, $request);

 // update session
 $session->setCartWasUpdated(true);

// save the cart
$cart->save();

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.