You do not set a custom option in the product model, you pass it through the second argument to $cart->addProduct($product, $params) .
For the project, which is required to be added to the Magento basket for an external application, you need to use the $params array of the following format:
$params = array( 'product' => 1, // This would be $product->getId() 'qty' => 1, 'options' => array( 34 => "value", 35 => "other value", 53 => "some other value" ) );
$params['options'] contains information about custom parameters. Keys are custom parameter identifiers, you can see them if you check the custom settings section of the product screen using Firebug or similar.
$params['product'] may be redundant, I wrote this script a while ago for a much earlier version of Magento.
In addition, I am sure that standard add to cart events will fire when this method is added, so you will need to disable them yourself. Side effects are possible.
Nick
source share