Refactor code and create twig function for cart render