Hi guys, so I need to know how to add Products programtically without getting this error.
Fatal error: Call to a member function getPosition() on a non-object in \app\code\core\Mage\Bundle\Model\Product\Type.php on line 854
This is my code:
class TCK_Forty_CartController extends Mage_Core_Controller_Front_Action {
public function addAction() {
$prdId = $this->getRequest()->getParam('product');
$cart = Mage::getModel('checkout/cart');
$cart->init();
$_return = array('code' => 0, 'message' => 'Something went wrong...');
if (!empty($prdId)) {
$product = new Mage_Catalog_Model_Product();
$product->load($prdId);
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$typeInstance = $product->getTypeInstance(true);
$optionCollection = $typeInstance->getOptionsCollection($product);
$selectionCollection = $typeInstance->getSelectionsCollection(
$typeInstance->getOptionsIds($product),
$product
);
$this->_options = $optionCollection->appendSelections($selectionCollection, false,
Mage::helper('catalog/product')->getSkipSaleableCheck()
);
$bundle_option = array();
foreach ($this->_options as $key => $value) {
foreach ($value['selections'] as $selKey => $selection) {
$bundle_option[$selection->option_id][] = $selection['selection_id'];
}
}
$params = array(
'product' => $prdId,
'related_product' => '',
'bundle_option' => $bundle_option,
'qty' => '1',
);
$cart->addProduct($product, $params);
$cart->save();
}
}
}
}