Wouldn't ``if (basket_id and [...])`` be enough?