The simplest way to think of these prepositions is to think that 'y' refers to 'à' and 'en' refers to 'de'. Therefore if you want to say 'Je vais à Paris' you would then say 'J'y vais'.
If you want to use 'en' with the sentence 'Je mange du gâteau', this becomes 'J'en mange'.
Therefore, 'y' refers to a place or a verb followed by 'à' and 'en' refers to a quantity or a verb followed by 'de'. In terms of sequence of prepositions, 'y' comes before 'en'.