"Notice undefined index" for an existing element in $form array
Your function is called for all forms in your Drupal. $cartId = $form['product_id']['#value']; is called outside if, so it's also executed on all forms. And most of them does not have $form['product_id'] defined at all. Move that part inside if block.