IMHO, trzymałbym tyko w cookie id koszyka, a resztę danych z koszyka albo w bazie danych (tabela o nazwie np. basket) lub ewentualnie w folderze (o nazwie np. baskets) w postaci plików o nazwie id koszyka, dane w plikach w postaci JSON-a.
Do generowania unikalnego id dla koszyka proponuje użyć np.
[ kod on-line ]
function uniqidReal($lenght=13) {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($lenght / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
} else {
throw new Exception("no cryptographically secure random function available");
}
return substr(bin2hex($bytes), 0, $lenght);
}
echo uniqidReal();
wtedy mamy w przypadku użycia folderu np.

przykładowy zapis do pliku
// Dwa produkty znajdują się w koszyku
$basket = [
[
'id_item' => 1111,
'content' => [
'quantity' => 1,
'size' => 'XL',
'color' => 'white'
]
],
[
'id_item' => 2222,
'content' => [
'quantity' => 2,
'size' => 'M',
'color' => 'blue'
]
]
];
// dla demonstracji zawartości
// print_r($basket);
// Zapisujemy dane do pliku, używamy jako nazwy wcześniej wygenerowany id
// pobrany czy to z $_COOKIE, czy z $_SESSION, czy z $_POST
file_put_contents("baskets/{$id}.dat", json_encode($basket));
pobieranie danych z pliku np.
$basket_json_data = file_get_contents("baskets/{$id}.dat");
$basket = json_decode($basket_json_data, true);
if ($basket === null) {
// to jest tylko bardzo prosty przykład obsługi problemu
// odczytu danych
echo "Wystąpił problem z pobraniem zawartości koszyka";
} else {
// dla demonstarcji
print_r($basket);
}
id koszyka możesz mieć w $_COOKIE, czy w $_SESSION lub
<form action="cart.php" method="post">
<input type="hidden" name="id_basket" value="<?=$id_basket?>">
<input type="hidden" name="id_item" value="<?=$this_product?>">
<label for="size_product">Wybierz rozmiar:</label>
<label>
<input type="radio" name="size_product" value="s" required>
S
</label>
<label>
<input type="radio" name="size_product" value="m">
M
</label>
<label>
<input type="radio" name="size_product" value="l">
L
</label>
<label>
<input type="radio" name="size_product" value="xl">
XL
</label>
<label>
<input type="radio" name="size_product" value="xxl">
XXL
</label>
<button type="submit" name="btn_add_to_basket">Dodaj do koszyka</button>
</form>
wersja z <select>
<form action="cart.php" method="post">
<input type="hidden" name="id_basket" value="<?=$id_basket?>">
<input type="hidden" name="id_item" value="<?=$this_product?>">
<label for="size_product">Wybierz rozmiar:</label>
<select id="size_product" name="size_product" required>
<option value="" disabled selected hidden></option>
<option value="s">S</option>
<option value="m">M</option>
<option value="l">L</option>
<option value="xl">XL</option>
<option value="xxl">XXL</option>
</select>
<button type="submit" name="btn_add_to_basket">Dodaj do koszyka</button>
</form>
<form action="cart.php" method="post">
<input type="hidden" name="id_basket" value="<?=$id_basket?>">
<input type="hidden" name="id_item" value="<?=$this_product?>">
<label for="quantity_product">Ilość:</label>
<input type="number" id="quantity_product" name="quantity_product" min="1" value="1" required>
<label for="size_product">Wybierz rozmiar:</label>
<select id="size_product" name="size_product" required>
<option value="" disabled selected hidden></option>
<option value="s">S</option>
<option value="m">M</option>
<option value="l">L</option>
<option value="xl">XL</option>
<option value="xxl">XXL</option>
</select>
<label for="color_product">Wybierz kolor:</label>
<select id="color_product" name="color_product" required>
<option value="" disabled selected hidden></option>
<option value="white">Biały</option>
<option value="black">Czarny</option>
<option value="blue">Niebieski</option>
</select>
<button type="submit" name="btn_add_to_basket">Dodaj do koszyka</button>
</form>