Automatically add an insurrance for a product What would be the best way to automatically add a product when another product is added to the cart?

For example, if I where to add a TV to the cart, I would like to automatically add a HDMI cable as well.
You could write a custom Craft plugin (generate the boilerplate for it at https://pluginfactory.io) - and in that listen to the onPopulateLineItem event.

https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem

Then, check the purchasableId of the item being added to the cart - if it is the TV, then add the cable to the cart at the same time.  Something like this (untested):

craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function($event){

    $purchasable= $event-&gt;params['purchasable'];
    $cart =  craft()-&gt;commerce_cart-&gt;getCart();

    if($purchasable-&gt;getPurchasableId() == 123){
        craft()-&gt;commerce_cart-&gt;addToCart($cart, 456);
    }
}


(See addToCart() in plugins/commerce/services/Commerce_CartService.php for the full function definition).

But the bigger question is should you do this....

Be aware that customers don't generally like this sort of behaviour in cart systems, and you should make sure that if you do do this, you at least take care to remove the accessories when they remove the main item from the cart.

Note that it soon gets complex, because can you be sure the accessory was added this way etc?

My advice is to instead use MultiAdd (https://github.com/engram-design/MultiAdd) to build a form that gives them the option of adding the accessories at the same time as the main product.  Like we do here for example:
https://imagescience.com.au/products/monitors/eizo-coloredge-cs2730