dostoyevski Posted October 8, 2022 Share Posted October 8, 2022 Hello, I want to add products to the stock but of products that are already in the store, that is, what I want is to update the stock of products that are already in the store. For this I have the .csv with the data of the products and the quantities that are going to be added. But if I import them, it reloads the products as they are in the csv, but what I want is for it to increase the units of the products that are already added. how can i get that? a greeting. Link to comment Share on other sites More sharing options...
ps8modules Posted October 8, 2022 Share Posted October 8, 2022 Hi. There are many examples and ready-made php scripts on the forum. Just use the search 😉 Link to comment Share on other sites More sharing options...
dostoyevski Posted October 8, 2022 Author Share Posted October 8, 2022 I have done so and I only get payment modules. Is there a way to do it directly from ps, without any module? Link to comment Share on other sites More sharing options...
ps8modules Posted October 8, 2022 Share Posted October 8, 2022 Also tell me what your PHP programming skills are, you also need to know the header of the CSV file, the value separator and what the products will be searched for (name, reference, ean...). Link to comment Share on other sites More sharing options...
ps8modules Posted October 8, 2022 Share Posted October 8, 2022 (edited) Sample for pairing by product reference: include_once('./config/config.inc.php'); // csv header // product_reference, product_quantity $csvFile = './update.csv'; $csvSeparator = ','; $fieldProductReference = 0; // field product_reference $fieldProductQuantity = 1; // field product_quantity $log = ''; $log .= 'START IMPORT<br>'; $db = Db::getInstance(); $rowNum = 0; if (($handle = fopen($csvFile, "r")) !== false) { while (($data = fgetcsv($handle, 1000, $csvSeparator)) !== false) { $rowNum++; if ($rowNum == 1) { // SKIP FIRST LINE (HEADER) continue; } $reference = trim($data[$fieldProductReference]); $quantity = trim($data[$fieldProductQuantity]); $productAttributeId = 0; $getIdProduct = 0; if ($reference && is_numeric($quantity) && $quantity){ // find ID product by reference $getIdProduct = $db->getValue("SELECT id_product FROM "._DB_PREFIX_."product WHERE reference = '".$reference."'"); // product not found if (!$getIdProduct){ $log .= 'reference '.$reference.' not found <br>'; $rowNum++; } else { // product found, update StockAvailable::setQuantity($getIdProduct, $productAttributeId, $quantity); $log .= 'product '.$getIdProduct.' updated quantity '.$quantity.' <br>'; } } } // END while $log .= 'END IMPORT<br>'; echo $log; } // end foreach Edited October 8, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
dostoyevski Posted October 9, 2022 Author Share Posted October 9, 2022 And where is that code supposed to go? should i create a module? Link to comment Share on other sites More sharing options...
ps8modules Posted October 9, 2022 Share Posted October 9, 2022 (edited) You don't have to create a module, just save the code in the root of the eshop and insert your CSV file in the same location. If you put the file in another location, you need to change the path to config.inc.php and $csvFile. Of course, from a security point of view, you can add your own token and read from the url using the $_GET method. Edited October 9, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted October 9, 2022 Share Posted October 9, 2022 E.g.: $securityToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'; $urlToken = $_GET['token']; /* your url = https://my-website.com/importCsvFile.php?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 */ /* check security token */ if ($securityToken != $urlToken){exit('token is not valid');} /* and check if CSV file exists */ if (!file_exists($csvFile)){exit('csv file not found');} Link to comment Share on other sites More sharing options...
dostoyevski Posted October 10, 2022 Author Share Posted October 10, 2022 21 hours ago, 4you.software said: You don't have to create a module, just save the code in the root of the eshop and insert your CSV file in the same location. If you put the file in another location, you need to change the path to config.inc.php and $csvFile. Of course, from a security point of view, you can add your own token and read from the url using the $_GET method. Do I have to save it to a file and save it with the .php extension? what name do I give the file? Link to comment Share on other sites More sharing options...
ps8modules Posted October 10, 2022 Share Posted October 10, 2022 (edited) What else should I do? Edited October 10, 2022 by 4you.software (see edit history) 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 10, 2022 Share Posted October 10, 2022 (edited) You cannot upload PHP files to the forum, nor can you insert complete PHP code in the editor. You have to figure it out yourself. Wouldn't it be easier to pay someone a few dollars or a euro to create and configure it for you according to your CSV file? Edited October 10, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
Constantino Posted October 12, 2022 Share Posted October 12, 2022 On 10/8/2022 at 5:31 PM, dostoyevski said: I have done so and I only get payment modules. Is there a way to do it directly from ps, without any module? why don't you want to use a third-party tool? Link to comment Share on other sites More sharing options...
ps8modules Posted October 12, 2022 Share Posted October 12, 2022 13 minutes ago, Constantino said: why don't you want to use a third-party tool? Because he doesn't do it for himself but for his customer and solves it in other forums as well. This is a beginner developer 😉 He wants to learn it 👍 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