$product = Mage::getModel('catalog/product')->load($productId); $buyRequest = new Varien_Object; $buyRequest->setData('qty', $qty); $buyRequest->setData('options', $options); $product->setBuyRequest($buyRequest); $product->save();
$cart = Mage::getSingleton('checkout/cart'); $product = Mage::getModel('catalog/product')->load($productId); $params = array( 'product' => $productId, 'qty' => $qty, 'options' => $options ); $buyRequest = new Varien_Object; $buyRequest->setData($params); $cart->addProduct($product, $buyRequest); $cart->save();In this example, we are adding a product to the shopping cart. We are creating a new Varien_Object to store the buy request information and setting the product ID, quantity, and options in the $params array. We are then adding the product and the buy request to the cart using the addProduct method, and then saving the cart to store the changes in the database. Package/Library: The Varien_Object class is part of the Magento core framework, which is a PHP ecommerce platform.