order_items can hold several lines for the same product in one order (the cart added it twice). Rank the products in each order by their total value in that order — not the individual lines.
01lines — how many order lines the product has in the order
02product_value — the sum of qty * unit_price over those lines
03value_rank — 1 for the most valuable product in the order. Products with the same value share a rank, and the next rank skips accordingly (1, 1, 3).
Sort by order_id, value_rank, then product_id.