Hello Everyone! I’ve created a script that takes a base product and creates all possible combinations of that product to be imported into my ecommerce store. I kinda frankensteined it and was hoping that someone could look over it and let me know where i can improve upon and make it more efficient. Here’s my code:
[php]
<?php $row = 1; $first = true; $file = toUpload.".".csv; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 500000, ",")) !== FALSE) { $num = 1; $row++; for ($c=0; $c < 1; $c++) { echo file_put_contents($file, $data[0] . "," . $data[1] . "," . $data[2] . "," . $data[3] . "," . $data[4] . "," . $data[5] . "," . $data[6] . "," . $data[7] . "," . $data[8] . "," . $data[9] . "," . $data[10] . "," . $data[11] . "," . $data[12] . "," . $data[13] . "," . $data[14] . "," . $data[15] . "," . $data[16] . "," . $data[17] . "," . $data[18] . "," . $data[19] . "," . $data[20] . "," . $data[21] . "," . $data[22] . "," . $data[23] . "," . $data[24] . "," . $data[25] . "," . $data[26] . "," . $data[27] . "," . $data[28] . "," . $data[29] . "," . $data[30] . "," . $data[31] . "," . $data[32] . "," . $data[33] . "," . $data[34] . "," . $data[35] . "," . $data[36] . "," . $data[37] . "," . $data[38] . "," . $data[39] . "," . $data[40] . "," . $data[41] . "," . $data[42] . "," . $data[43] . "," . $data[44] . "," . $data[45] . "," . $data[46] . "," . $data[47] . "," . $data[48] . "," . $data[49] . "," . $data[50] . "," . $data[51] . "," . $data[52] . "," . $data[53] . "," . $data[54] . "," . $data[55] . "," . $data[56] . "," . $data[57] . "," . $data[58] . "," . $data[59] . "," . $data[60] . "," . $data[61] . "," . $data[62] . "," . $data[63] . "," . $data[64] . "," . $data[65] . "," . $data[66] . "," . $data[67] . "," . $data[68] . "," . $data[69] . "," . $data[70] . "," . $data[71] . "," . $data[72] . "," . $data[73] . "," . $data[74] . "," . $data[75] . "\r\n" , FILE_APPEND); if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 500000, ",")) !== FALSE) { if ($first) { $first = false; continue; } $num = 1; $row++; for ($c=0; $c < $num; $c++) { echo file_put_contents($file,"admin" . ",". "base" . "," .$data[2] . "-Small-Satin-No Frame" . ",". "25.00" . ",". "Image Options" . "," . "simple" . ",".$data[6] . "," . "0" . "," .$data[8] . "-Small-Satin-No Frame" ."," . $data[9] . "," .$data[10]. "," .$data[11]. "," . $data[12] . "," .$data[13]. "," .$data[14]. "," .$data[15]. "," .$data[16] . "," . "No Layout Updates" . "," . "Product Info Column" . "," . "No". "," .$data[20]. "," .$data[21]. "," . ".9" . "," . "Enabled". "," . "None". "," . "No". "," . "1". "," . "Yes". "," . "No". "," . "Small" . "," . "Satin" . "," . "No Frame" . "," .$data[32]. "," .$data[33]. "," .$data[34]. "," .$data[35]. "," .$data[36]. "," .$data[37]. "," .$data[38]. "," .$data[39]. "," .$data[40]. "," .$data[41]. "," .$data[42]. "," . "9999". "," . "0". "," . "1". "," . "0". "," . "0". "," . "1". "," . "1". "," . "1". "," . "0". "," . "1". "," . "1". "," .$data[54]. "," .$data[55]. "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," .$data[64]. "-Small-Satin-No Frame" . "," . "0". "," . "simple" . "," .$data[67] . "," .$data[68]. "," .$data[69]. "," .$data[70]. "," .$data[71]. "," . "14" . "," . "11" . "," . "0.016" . "," . "no" . "\r\n" , FILE_APPEND); echo file_put_contents($file,"admin" . ",". "base" . "," .$data[2] . "-Small-Satin-Flat Black" . ",". "104.00" . ",". "Image Options" . "," . "simple" . ",".$data[6] . "," . "0" . "," .$data[8] . "-Small-Satin-Flat Black" ."," .$data[9] . "," .$data[10]. "," .$data[11]. "," . $data[12] . "," .$data[13]. "," .$data[14]. "," .$data[15]. "," .$data[16] . "," . "No Layout Updates" . "," . "Product Info Column" . "," . "No". "," .$data[20]. "," .$data[21]. "," . "112" . "," . "Enabled". "," . "None". "," . "No". "," . "1". "," . "Yes". "," . "No". "," . "Small" . "," . "Satin" . "," . "Flat Black" . "," .$data[32]. "," .$data[33]. "," .$data[34]. "," .$data[35]. "," .$data[36]. "," .$data[37]. "," .$data[38]. "," .$data[39]. "," .$data[40]. "," .$data[41]. "," .$data[42]. "," . "9999". "," . "0". "," . "1". "," . "0". "," . "0". "," . "1". "," . "1". "," . "1". "," . "0". "," . "1". "," . "1". "," .$data[54]. "," .$data[55]. "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," .$data[64]. "-Small-Satin-Flat Black" . "," . "0". "," . "simple" . "," .$data[67] . "," .$data[68]. "," .$data[69]. "," .$data[70]. "," .$data[71]. "," . "14" . "," . "11" . "," . "0.016" . "," . "no" . "\r\n" , FILE_APPEND); echo file_put_contents($file,"admin" . ",". "base" . "," .$data[2] . "-Small-Satin-Natural Wood" . ",". "123.00" . ",". "Image Options" . "," . "simple" . ",".$data[6] . "," . "0" . "," .$data[8] . "-Small-Satin-Natural Wood" ."," .$data[9] . "," .$data[10]. "," .$data[11]. "," . $data[12] . "," .$data[13]. "," .$data[14]. "," .$data[15]. "," .$data[16] . "," . "No Layout Updates" . "," . "Product Info Column" . "," . "No". "," .$data[20]. "," .$data[21]. "," . "112" . "," . "Enabled". "," . "None". "," . "No". "," . "1". "," . "Yes". "," . "No". "," . "Small" . "," . "Satin" . "," . "Natural Wood" . "," .$data[32]. "," .$data[33]. "," .$data[34]. "," .$data[35]. "," .$data[36]. "," .$data[37]. "," .$data[38]. "," .$data[39]. "," .$data[40]. "," .$data[41]. "," .$data[42]. "," . "9999". "," . "0". "," . "1". "," . "0". "," . "0". "," . "1". "," . "1". "," . "1". "," . "0". "," . "1". "," . "1". "," .$data[54]. "," .$data[55]. "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," .$data[64]. "-Small-Satin-Natural Wood" . "," . "0". "," . "simple" . "," .$data[67] . "," .$data[68]. "," .$data[69]. "," .$data[70]. "," .$data[71]. "," . "14" . "," . "11" . "," . "0.016" . "," . "no" . "\r\n" , FILE_APPEND); echo file_put_contents($file,"admin" . ",". "base" . "," .$data[2] . "-Small-Satin-Dark Wood" . ",". "123.00" . ",". "Image Options" . "," . "simple" . ",".$data[6] . "," . "0" . "," .$data[8] . "-Small-Satin-Dark Wood" ."," .$data[9] . "," .$data[10]. "," .$data[11]. "," . $data[12] . "," .$data[13]. "," .$data[14]. "," .$data[15]. "," .$data[16] . "," . "No Layout Updates" . "," . "Product Info Column" . "," . "No". "," .$data[20]. "," .$data[21]. "," . "112" . "," . "Enabled". "," . "None". "," . "No". "," . "1". "," . "Yes". "," . "No". "," . "Small" . "," . "Satin" . "," . "Dark Wood" . "," .$data[32]. "," .$data[33]. "," .$data[34]. "," .$data[35]. "," .$data[36]. "," .$data[37]. "," .$data[38]. "," .$data[39]. "," .$data[40]. "," .$data[41]. "," .$data[42]. "," . "9999". "," . "0". "," . "1". "," . "0". "," . "0". "," . "1". "," . "1". "," . "1". "," . "0". "," . "1". "," . "1". "," .$data[54]. "," .$data[55]. "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," .$data[64]. "-Small-Satin-Dark Wood" . "," . "0". "," . "simple" . "," .$data[67] . "," .$data[68]. "," .$data[69]. "," .$data[70]. "," .$data[71]. "," . "14" . "," . "11" . "," . "0.016" . "," . "no" . "\r\n" , FILE_APPEND); echo file_put_contents($file,"admin" . ",". "base" . "," .$data[2] . "-Small-Satin-Brushed Gold" . ",". "117.00" . ",". "Image Options" . "," . "simple" . "," .$data[6] . "," . "0" . "," .$data[8] . "-Small-Satin-Brushed Gold" . "," .$data[9] . "," .$data[10]. "," .$data[11]."," . $data[12] . "," .$data[13]. "," .$data[14]. "," .$data[15]. "," .$data[16] . "," . "No Layout Updates" . "," . "Product Info Column" . "," . "No". "," .$data[20]. "," .$data[21]. "," . "112" . "," . "Enabled". "," . "None". "," . "No". "," . "1". "," . "Yes". "," . "No". "," . "Small" . "," . "Satin" . "," . "Brushed Gold" . "," .$data[32]. "," .$data[33]. "," .$data[34]. "," .$data[35]. "," .$data[36]. "," .$data[37]. "," .$data[38]. "," .$data[39]. "," .$data[40]. "," .$data[41]. "," .$data[42]. "," . "9999". "," . "0". "," . "1". "," . "0". "," . "0". "," . "1". "," . "1". "," . "1". "," . "0". "," . "1". "," . "1". "," .$data[54]. "," .$data[55]. "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," . "1". "," . "0". "," .$data[64]. "-Small-Satin-Brushed Gold" . "," . "0". "," . "simple" . "," .$data[67] . "," .$data[68]. "," .$data[69]. "," .$data[70]. "," .$data[71]. "," . "14" . "," . "11" . "," . "0.016" . "," . "no" . "\r\n" , FILE_APPEND); } } fclose($handle); } } } } ?>[/php]