Thanks, i have solved it by another way. 🤪 Thanks
Thanks, i have solved it by another way. 🤪 Thanks
Thanks, i have solved it by another way. 🤪and can you help me where to put the code exactly please? Thanks
Thanks, i have solved it by another way. 🤪and can you help me where to put the code exactly please? Thanks
<?php // MAIN CYCLE $row_num = 0; if (($handle = fopen($csv_file_sklad_sk, "r")) !== false) { //oodelovac polí prípadne zmeniť while (($data = fgetcsv($handle, 100000, ",")) !== false) { $row_num++; if ($row_num == 1) { // SKIP FIRST LINE (HEADER) continue; } //quantity if ($data[2] == '' || !is_string($data[3])) { // SKIP EMPTY VALUES continue; } //price if ($data[2] == '' || !is_numeric($data[1])) { // SKIP EMPTY VALUES continue; } //price if ($data[2] == '' || !is_numeric($data[0])) { // SKIP EMPTY VALUES continue; } // INPUT SANITIZATION $ean13 = trim($data[2]); $qty = str_replace('> ','',$data[3]); $quantity = ($qty >= 0) ? $qty : 0; $price = ($data[1] >= 0) ? $data[1] : 0; $price_bezna = ($data[0] >= 0) ? $data[0] : 0; $dostupnost = 'up to ... 24-48h'; try { $res4 = $db->prepare("SELECT id_product, id_product_attribute from "._DB_PREFIX_."product_attribute WHERE ean13 = :ean13"); $res4->execute(array(':ean13'=>$ean13)); if ($res4->rowCount() > 0) { // IT'S A PRODUCT COMBINATION $row4 = $res4->fetch(); //quantity $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = :q where id_product_attribute = :id_product_attribute"); $res->execute(array(':q'=>$quantity, ':id_product_attribute'=>$row4['id_product_attribute'])); $res = $db->prepare("update "._DB_PREFIX_."product_attribute set quantity = :q where id_product_attribute = :id_product_attribute"); $res->execute(array(':q'=>$quantity, ':id_product_attribute'=>$row4['id_product_attribute'])); $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = quantity + :q where id_product = :id_product and id_product_attribute = 0"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set quantity = quantity + :q where id_product = :id_product"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); } else { // IT'S A SIMPLE PRODUCT $res4 = $db->prepare("SELECT id_product from "._DB_PREFIX_."product WHERE ean13 = :ean13"); $res4->execute(array(':ean13'=>$ean13)); if ($res4->rowCount() > 0) { $row4 = $res4->fetch(); $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = :q where id_product = :id_product and id_product_attribute = 0"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set quantity = :q where id_product = :id_product"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_shop set wholesale_price = :p where id_product = :id_product"); $res->execute(array(':p'=>$price, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set wholesale_price = :p where id_product = :id_product"); $res->execute(array(':p'=>$price, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_shop set price = :pb * 0.85 / 1.2 where id_product = :id_product"); $res->execute(array(':pb'=>$price_bezna, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set price = :pb * 0.86 / 1.2 where id_product = :id_product"); $res->execute(array(':pb'=>$price_bezna, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_lang set available_now = :d where id_product = :id_product"); $res->execute(array(':d'=>$dostupnost, ':id_product'=>$row4['id_product'])); } } } catch (PDOException $e) { echo 'Sql Error: '. $e->getMessage() .'<br /><br />'; } } fclose($handle); }
Thanks, and can you help me where to put the code exactly please? Thanks
Btw: i am not sure if we have undrestood each other.
Here is my full code and i need following:
Not update quantity, when quantity in CSV is empty or = 0.
(Just update anything else...butquantity ignore - leave as it is in the DB)
<
<?php // MAIN CYCLE $row_num = 0; if (($handle = fopen($csv_file_sklad_sk, "r")) !== false) { //oodelovac polí prípadne zmeniť while (($data = fgetcsv($handle, 100000, ",")) !== false) { $row_num++; if ($row_num == 1) { // SKIP FIRST LINE (HEADER) continue; } //quantity if ($data[2] == '' || !is_string($data[3])) { // SKIP EMPTY VALUES continue; } //price if ($data[2] == '' || !is_numeric($data[1])) { // SKIP EMPTY VALUES continue; } //price if ($data[2] == '' || !is_numeric($data[0])) { // SKIP EMPTY VALUES continue; } // INPUT SANITIZATION $ean13 = trim($data[2]); $qty = str_replace('> ','',$data[3]); $quantity = ($qty >= 0) ? $qty : 0; $price = ($data[1] >= 0) ? $data[1] : 0; $price_bezna = ($data[0] >= 0) ? $data[0] : 0; $dostupnost = 'up to ... 24-48h'; try { $res4 = $db->prepare("SELECT id_product, id_product_attribute from "._DB_PREFIX_."product_attribute WHERE ean13 = :ean13"); $res4->execute(array(':ean13'=>$ean13)); if ($res4->rowCount() > 0) { // IT'S A PRODUCT COMBINATION $row4 = $res4->fetch(); //quantity $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = :q where id_product_attribute = :id_product_attribute"); $res->execute(array(':q'=>$quantity, ':id_product_attribute'=>$row4['id_product_attribute'])); $res = $db->prepare("update "._DB_PREFIX_."product_attribute set quantity = :q where id_product_attribute = :id_product_attribute"); $res->execute(array(':q'=>$quantity, ':id_product_attribute'=>$row4['id_product_attribute'])); $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = quantity + :q where id_product = :id_product and id_product_attribute = 0"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set quantity = quantity + :q where id_product = :id_product"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); } else { // IT'S A SIMPLE PRODUCT $res4 = $db->prepare("SELECT id_product from "._DB_PREFIX_."product WHERE ean13 = :ean13"); $res4->execute(array(':ean13'=>$ean13)); if ($res4->rowCount() > 0) { $row4 = $res4->fetch(); $res = $db->prepare("update "._DB_PREFIX_."stock_available set quantity = :q where id_product = :id_product and id_product_attribute = 0"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set quantity = :q where id_product = :id_product"); $res->execute(array(':q'=>$quantity, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_shop set wholesale_price = :p where id_product = :id_product"); $res->execute(array(':p'=>$price, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set wholesale_price = :p where id_product = :id_product"); $res->execute(array(':p'=>$price, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_shop set price = :pb * 0.85 / 1.2 where id_product = :id_product"); $res->execute(array(':pb'=>$price_bezna, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product set price = :pb * 0.86 / 1.2 where id_product = :id_product"); $res->execute(array(':pb'=>$price_bezna, ':id_product'=>$row4['id_product'])); $res = $db->prepare("update "._DB_PREFIX_."product_lang set available_now = :d where id_product = :id_product"); $res->execute(array(':d'=>$dostupnost, ':id_product'=>$row4['id_product'])); } } } catch (PDOException $e) { echo 'Sql Error: '. $e->getMessage() .'<br /><br />'; } } fclose($handle); }
Thanks, and can you help me where to put the code exactly please? Thanks
Btw: i am not sure if we have undrestood each other.
Here is my full code and i need following:
Not update quantity, when quantity in CSV is empty or = 0.
(Just update any other, and quantity leave as it is)
Thanks, and can you help me where to put the code exactly please? Thanks