Ordered Cartesian Product Say I have three sets:

A = [banana, apple, grape]

B = [1, 2, 3, 4]

C = [Alice, Bob, Carol]


I need to design an algorithm that gives me the Cartesian Product A x B x C, but with any number of sets and any number of elements in each set. Another requirement is that the order of the elements in the Product is such:

A x B x C = [(banana, 1, Alice),
             (apple, 1, Alice),
             (banana, 2, Alice),
             (banana, 1, Bob),
              ...]


I could only come up with a recursive algorithm that ends up giving me:

A x B x C = [(banana, 1, Alice), 
             (banana, 1, Bob), 
             (banana, 1, Carol),
             (banana, 2, Alice),
              ...]


Obviously, A x B x C needs to have every possible combination of the elements of the sets. Also, I need an algorithm that covers the general case of any number of sets, not only three.
Is there any well-known algorithm that provides the Cartesian Product in this order that I need?

Any help or tips is much appreciated.
You want to enumerate first by sum, then by lexicographic order of some sort (it's impossible to tell which type exactly from your example). Replacing actual elements with indices, here is the order you're interested in for $A \times B$:
$$
(0,0) \\
(1,0), (0,1) \\
(2,0), (1,1), (0,2) \\
\ldots
$$
It's a simple exercise to generate this order for $A \times B$. Generating the order for $A \times B$ is somewhat more challenging, but still not too bad. When generating the triples summing to $n$, if we focus on just the first two parts of each pair, then we're interested in a list of all pairs $(i,j)$ such that $i+j \leq n$, in some sort of lexicographic order. Whichever variant of the lexicographic order you choose, you should be able to figure out how to generate it by looking at some examples.