MarcoSch Posted September 20, 2018 Share Posted September 20, 2018 I have adapted the script for automatic stock update to delete multiple combinations that no longer availible. It works for me on my 1.6.1.17 productiv shop after i testet the script on a cloned shop. The original script can be found here https://www.prestashop.com/forums/topic/476997-solved-automatic-stock-update-csv-solution/ What i have done is this: <?php error_reporting(E_ALL); // PRESTASHOP SETTINGS FILE require_once ('configs.php'); // REMOTE CSV FILE (CUSTOMIZE YOURCSVFILEPATH, CAN BE AN URL OR A LOCAL PATH) $remote_csv_file = 'deleted_products.csv'; //MY PATH; CHANGE TO YOUR NEED, SAME FOR THE FILE NAME // DB CONNECTION (CUSTOMIZE YOURDBHOSTNAME AND YOURDBPORT) $db = new PDO("mysql:host=localhost;port=3306;dbname="._DB_NAME_."", _DB_USER_, _DB_PASSWD_); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); set_time_limit(600); // MAIN CYCLE $row_num = 0; if (($handle = fopen($remote_csv_file, "r")) !== false) { while (($data = fgetcsv($handle, 60000, ";")) !== false) { $row_num++; if ($row_num == 1) { // SKIP FIRST LINE (HEADER) continue; } if ($data[0] == '') { // SKIP EMPTY VALUES continue; } $reference = trim($data[0]); try { $res4 = $db->prepare("DELETE FROM "._DB_PREFIX_."product_attribute WHERE reference = :reference"); $res4->execute(array(':reference'=>$reference)); } catch (PDOException $e) { echo 'Sql Error: '. $e->getMessage() .'<br /><br />'; } } fclose($handle); } ?> I also tried to delete single products, what actually should work the same way. But in my case unfortunately some Main Products have the same reference as a combination of them. By example Main Product is 12345-S And combinations are 12345-S = Small 12345-M = Medium 12345-L = Large 12345-XL = XL So if i use the above script (adapted to ps_product) for 'single products' it will also delete the main products which has combinations and the whole product include the combination is gone. I didn't figure out yet how i can tell the script that it only delete products that has no combination since i found no entry in the table ps_product that tells the script that the product what i want to delte has no combinations. Maybe some one has a clue to handle that? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now