mozack Posted May 27, 2009 Share Posted May 27, 2009 Hi again,I'm newbie with prestashop, i've created new products with variation (sizes), each size of products have different EAN and different quantities. How can i update that quantities from one external php file protected by password?I want something like cronjob to do the task and keep my available quantities updated. The external php file (from other store) have on first collum the EAN of related size, on second collum (dont need to connect) have the name of product and 3rd collum have the available quantites... Is that possible to do? Maybe one script like other shopping carts uses to update currencies... I dont know...Can someone help me?Thanls thanks thanks... Link to comment Share on other sites More sharing options...
VIXUS Posted May 27, 2009 Share Posted May 27, 2009 Welcome to the club.Theres a lot of people needing some kind of module that can do update of products prices, quantities and availability but so far nothing can do that.If you figure out how to do that please share with us. Link to comment Share on other sites More sharing options...
mozack Posted May 27, 2009 Author Share Posted May 27, 2009 I'll try to change one php script to update currencies on zen cart, but i need to know exactly how is the function of products variations in db of presta.Thanks... If i solve this i share it Link to comment Share on other sites More sharing options...
mozack Posted May 27, 2009 Author Share Posted May 27, 2009 Welcome to the club.Theres a lot of people needing some kind of module that can do update of products prices, quantities and availability but so far nothing can do that.If you figure out how to do that please share with us. Hi, the problem of quantities update is solved...I can share it but i'm new here...I dont know how to share it....Is a basic script but maybe can help someone... Link to comment Share on other sites More sharing options...
San Diego Posted May 27, 2009 Share Posted May 27, 2009 hiwelcome toojust post it right here and mark your threat as solvedjust attach the files you changedthanks for sharingsd Link to comment Share on other sites More sharing options...
VIXUS Posted May 27, 2009 Share Posted May 27, 2009 Great news mate, can you perhaps expand it to update price and availability? Link to comment Share on other sites More sharing options...
mozack Posted May 27, 2009 Author Share Posted May 27, 2009 yesis it possible if you have all the data in the same csv Link to comment Share on other sites More sharing options...
VIXUS Posted May 27, 2009 Share Posted May 27, 2009 I do have all in one file.Mate, you are a life saver if you can manage that to work! Link to comment Share on other sites More sharing options...
mozack Posted May 27, 2009 Author Share Posted May 27, 2009 Hi,Here is the solution. PLEASE BACKUP YOUR DATABASE FIRST. I'VE FINISHED IT TODAY, I TRY AND IT WORKS, BUT IT COULD BE A PROBLEM.Follow the steps you will find in php file.Best regards...I'm waiting for your replay quantity_update.zip 1 Link to comment Share on other sites More sharing options...
San Diego Posted May 27, 2009 Share Posted May 27, 2009 thanks for sharingi don´t need it right nowwill give it a try soon i get timesd Link to comment Share on other sites More sharing options...
mozack Posted May 28, 2009 Author Share Posted May 28, 2009 Hi,One update to the file, on line 44, you can change the "," to ";" if your csv use other type of separator... Link to comment Share on other sites More sharing options...
VIXUS Posted May 28, 2009 Share Posted May 28, 2009 Hi, Im just testing this and im having some problems... Can you post sample row of your csv just to see how to format it? becouse currently i use complete CSV with all 30 columns. Link to comment Share on other sites More sharing options...
VIXUS Posted May 28, 2009 Share Posted May 28, 2009 Excellent, iw figured it out!This ROCKS!!! man i love you! (not as the man loves the woman, but friendly kind of love) ;-)This solution shud go to sticky!!!!! Link to comment Share on other sites More sharing options...
mozack Posted May 28, 2009 Author Share Posted May 28, 2009 remember that you can use all variables rou want in the some formar and order of table you are updating. Ex.:reference - supplier_reference - location - ean13 - wholesale_price - price (...)your csv must have this fields or not, but with the some order.You can only update one table. In this case is the table of product_attribute.You have to change as well the line 44 to the symbol that separate each collum of csv, set it in php file like: , or ; (..)In my csv i just have 2 fileds ean13 and quantity (in this order)Hope can help you, best regards. Link to comment Share on other sites More sharing options...
mozack Posted May 28, 2009 Author Share Posted May 28, 2009 Problem solved....Thanks. Link to comment Share on other sites More sharing options...
VIXUS Posted May 28, 2009 Share Posted May 28, 2009 Managed to add script to cron job and its perfect.Im posting this peace of code (that was killin me for hours untill iw get it right) to save others some else a time and headache./usr/bin/php /home/username/folder/script.phpcheers! Link to comment Share on other sites More sharing options...
DesignMonstr Posted June 13, 2009 Share Posted June 13, 2009 good module Link to comment Share on other sites More sharing options...
VIXUS Posted July 15, 2009 Share Posted July 15, 2009 file update.php <?php // -------------------------------------------------- // quantity_update.php // Change MySql database quantity and prices and other data from csv file // Standalone script - run it by web browser // Last Updated: May 27 2009 // Author: Mozack // // Instructions // // Backup your database. // Define the veriables below. // Upload this file to your server. // update.php // // To run open in your browser. // Example: http://www.mysite.com/secure_folder/update.php // // That's it!!! Check that everything is changed properly and make neccessary corrections. // // WHEN DONE REMOVE THIS FILE FROM YOUR SERVER OR KEEP WITH THIS FILE ONE INDEX.PHP REDIRECTING !!!!! // --------------------------------------------------- //Configuration variables //--------------------------------------------------- // Connect to MySQL change with your data mysql_connect("LOCALHOST", "here goes your login", "here goes your password") or die(mysql_error()); mysql_select_db("heregoes your database name") or die(mysql_error()); // If first row of csv file is headings set $row to 1. $row = 0; // TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute $update_table = "ps_product"; // Get the csv file - INSERT THE ADDRESS OF CSV FILE OR UPLOAD IT TO THE SOME FOLDER OF THIS SCRIPT $handle = fopen("update.csv", "r"); // Go through the csv file and print each row with fields to the screen. // And import them into the database updating only the price and quantity // YOU MUST SET THE VARIABLES $reference, $price AND $quantity IF YOU ARE NOT UPDATING PRESTASHOP TABLES // IF YOU WANT TO UPDATE OTHER DATA IN THE SOME TABLE LIKE SUPPLIER_REFERENCE, LOCATION, ECOTAX, ETC YOU MAST HAVE // ALL THE DATA IN THE SOME CSV FILE AND THE COLLUMS IN THE SOME ORDER OF THIS CODE. YOU MUST ADD MORE IF STATEMENTS TO ADD // ADITIONAL DATA TO IMPORT while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) { $num = count($data); echo "\n"; echo "( $row )\n"; $row++; for ($c=0; $c < $num; $c++) { if ($c = 1) { $reference = $data[($c - 1)]; echo $reference . " - Reference Assigned\n"; } if ($c = 2) { $price = $data[($c - 1)]; mysql_query("UPDATE $update_table SET price='$price' WHERE reference='$reference'") or die(mysql_error()); echo $price . " - Price updated\n"; } if ($c = 3) { $quantity = $data[($c - 1)]; mysql_query("UPDATE $update_table SET quantity='$quantity' WHERE reference='$reference'") or die(mysql_error()); echo $quantity . " - Quantity updated\n"; } if ($c = 4) { $active = $data[($c - 1)]; mysql_query("UPDATE $update_table SET active='$active' WHERE reference='$reference'") or die(mysql_error()); echo $active . " - Activity updated\n"; echo "_____________________________________________________\n"; } // ADD ADITIONAL IF STATEMENTS FOR EACH FIELD YOU WANT UPDATE IN THE SOME ORDER OF YOUR CSV FILE } } fclose($handle); echo " \n"; echo " - - - SUCESSFULY COMPLETED - - - "; ?> NOTICE, code does not report any mistakes (eg. not found reference) so if anyone knows how to improve this code please share here...file update.csv(columns in excel) reference, price, quantity, activity PCDE-OP360MTE2200 8.853,000000 100 1 PCDE-OP360MTE2500 8.853,000000 100 1 PCDE-OP360MTE5300 132,000000 600 1 PCDE-OP360MTE7400 4.755,000000 600 1 PCDE-OP360MTE2240 8.853,000000 605 1 Link to comment Share on other sites More sharing options...
babysoros Posted July 31, 2009 Share Posted July 31, 2009 hello i am new in here can u explain how to use this file? i am already use csv dan they said 1 fields to update in line 0:1;"1";"1";"1";"1";"1" EAN13 Assigned Undefined offset: 1 in C:\wamp\www\prestashop\Protected_folder\quantity_update.php on line 54Table 'bla bla bla ' doesn't existhow can i know what is my table? Link to comment Share on other sites More sharing options...
wallacept Posted August 11, 2009 Share Posted August 11, 2009 where put file update.php?this file update catalog with import csv, okay?no apply in store.have a problem.see screenshot. Link to comment Share on other sites More sharing options...
VIXUS Posted August 11, 2009 Share Posted August 11, 2009 OMG, i see that you are updating with mine "update.csv" file... mine file is just a sample so that you know how to set your own csv.reference;price;quantity;activity0/1 where put file update.php? well iw put it in folder i called update and i acess it through web browser and i protected it with password.you can there set secure acess to or even put it somewhere in root, your choice... Link to comment Share on other sites More sharing options...
wallacept Posted August 11, 2009 Share Posted August 11, 2009 ok Dj-Terror...where put i say.but the code not apply?not update...!see screenshot?exist error.execute php, but in database nothing, not update. Link to comment Share on other sites More sharing options...
VIXUS Posted August 11, 2009 Share Posted August 11, 2009 well i dont know... it works for me, it works for other people...I asume that you are doing something wrong... and i cant help you there...try to go through PHP and see if all of needed data related to your database is properly inserted. Link to comment Share on other sites More sharing options...
wallacept Posted August 11, 2009 Share Posted August 11, 2009 what problem? see:update.csv OP360MTE2200;8;100;1 OP360MTE2500;833;100;1 OP360MTE5300;132;600;1 OP360MTE7400;43;600;1 OP360MTE2240;844;605;1 update.php <?php // -------------------------------------------------- // quantity_update.php // Change MySql database quantity and prices and other data from csv file // Standalone script - run it by web browser // Last Updated: May 27 2009 // Author: Mozack // // Instructions // // Backup your database. // Define the veriables below. // Upload this file to your server. // update.php // // To run open in your browser. // Example: http://www.mysite.com/secure_folder/update.php // // That's it!!! Check that everything is changed properly and make neccessary corrections. // // WHEN DONE REMOVE THIS FILE FROM YOUR SERVER OR KEEP WITH THIS FILE ONE INDEX.PHP REDIRECTING !!!!! // --------------------------------------------------- //Configuration variables //--------------------------------------------------- // Connect to MySQL change with your data mysql_connect("LOCALHOST", "root", "") or die(mysql_error()); mysql_select_db("presta100") or die(mysql_error()); // If first row of csv file is headings set $row to 1. $row = 0; // TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute $update_table = "ps_product"; // Get the csv file - INSERT THE ADDRESS OF CSV FILE OR UPLOAD IT TO THE SOME FOLDER OF THIS SCRIPT $handle = fopen("update.csv", "r+"); // Go through the csv file and print each row with fields to the screen. // And import them into the database updating only the price and quantity // YOU MUST SET THE VARIABLES $reference, $price AND $quantity IF YOU ARE NOT UPDATING PRESTASHOP TABLES // IF YOU WANT TO UPDATE OTHER DATA IN THE SOME TABLE LIKE SUPPLIER_REFERENCE, LOCATION, ECOTAX, ETC YOU MAST HAVE // ALL THE DATA IN THE SOME CSV FILE AND THE COLLUMS IN THE SOME ORDER OF THIS CODE. YOU MUST ADD MORE IF STATEMENTS TO ADD // ADITIONAL DATA TO IMPORT while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) { $num = count($data); echo "\n"; echo "( $row )\n"; $row++; for ($c=0; $c < $num; $c++) { if ($c = 1) { $reference = $data[($c - 1)]; echo $reference . " - Reference Assigned\n"; } if ($c = 2) { $price = $data[($c - 1)]; mysql_query("UPDATE $update_table SET price='$price' WHERE reference='$reference'") or die(mysql_error()); echo $price . " - Price updated\n"; } if ($c = 3) { $quantity = $data[($c - 1)]; mysql_query("UPDATE $update_table SET quantity='$quantity' WHERE reference='$reference'") or die(mysql_error()); echo $quantity . " - Quantity updated\n"; } if ($c = 4) { $active = $data[($c - 1)]; mysql_query("UPDATE $update_table SET active='$active' WHERE reference='$reference'") or die(mysql_error()); echo $active . " - Activity updated\n"; echo "_____________________________________________________\n"; } // ADD ADITIONAL IF STATEMENTS FOR EACH FIELD YOU WANT UPDATE IN THE SOME ORDER OF YOUR CSV FILE } } fclose($handle); echo " \n"; echo " - - - SUCESSFULY COMPLETED - - - "; ?> Link to comment Share on other sites More sharing options...
VIXUS Posted August 11, 2009 Share Posted August 11, 2009 do you actualy have a product with reference OP360MTE2200 ?i dont know... try on live shop not localy... Link to comment Share on other sites More sharing options...
wallacept Posted August 11, 2009 Share Posted August 11, 2009 I can not get a reference that does not exist? localhost is not in the update? has to be online?if this code apply others persons...humm... Link to comment Share on other sites More sharing options...
wallacept Posted August 14, 2009 Share Posted August 14, 2009 I apply I only lack one thing. if the reference does not exist insert the product. is with INSERT? but how? Link to comment Share on other sites More sharing options...
ukbaz Posted August 27, 2009 Share Posted August 27, 2009 Any chance you could post example of the cron script? ThanksBaz Link to comment Share on other sites More sharing options...
VIXUS Posted August 27, 2009 Share Posted August 27, 2009 Any chance you could post example of the cron script? ThanksBaz look at post #15 Link to comment Share on other sites More sharing options...
wallacept Posted August 30, 2009 Share Posted August 30, 2009 DJ-Terror, update.php only update okay? but if product not exits not update.how, if product not exists, put/insert in database? Link to comment Share on other sites More sharing options...
Bogdans Posted September 22, 2009 Share Posted September 22, 2009 Hi allI put the update.php file to C: \ wamp \ www \ PrestaShop \ secure_folderI typed in the browser address C: \ wamp \ www \ PrestaShop \ secure_folder \ update.phpand receive message from someone rezol poza.ma can help this problem?Thanks much for any information> inversaţi Link to comment Share on other sites More sharing options...
Bogdans Posted September 29, 2009 Share Posted September 29, 2009 We solve the problem.Works perfect script.It updates the price and quantity Link to comment Share on other sites More sharing options...
mozack Posted October 22, 2009 Author Share Posted October 22, 2009 Thanks to all is using that script.I start it and saw that have some mods. I'm not programmer but i'll try to put that as module with upload (for csv).Let's see what happen Link to comment Share on other sites More sharing options...
Bogdans Posted December 9, 2009 Share Posted December 9, 2009 I want some help mozackThe file for importing. Csv products that contain the description of syntax elements such as html td> importate.What are not had to do because I import them? Link to comment Share on other sites More sharing options...
mozack Posted December 9, 2009 Author Share Posted December 9, 2009 I dont understand what you want or what happen with the file, can you send me pscreen or one link to see the problem, if any?If you want to import products description, i never try it before, but my be it possible...Let me know clearly what you want to do...Best Regards. Link to comment Share on other sites More sharing options...
Bogdans Posted December 9, 2009 Share Posted December 9, 2009 I want to import products test 2tools/import test 1.csv test 2.csv Link to comment Share on other sites More sharing options...
mozack Posted December 9, 2009 Author Share Posted December 9, 2009 Yes, is possible,But first you need to check if all data is in the some table (ps_???), after that you need all collums with data or bypass some data: EX.: If you have the meta-description and you dont have any data, dont use this collum.Do this to all your data in csv file, dont use if you haven't data to insert. In php you choose the collums you want to use like collum1, 2 ,4 etcWith html, this can be used once mysql table have this data as well.Check carefully the both, sql table and csv and check what you have to use or not.Hope it help youBest regards Link to comment Share on other sites More sharing options...
Bogdans Posted December 10, 2009 Share Posted December 10, 2009 want to import products from Back officeWe corrected files test1 and test 2 Link to comment Share on other sites More sharing options...
2Nine Posted March 8, 2010 Share Posted March 8, 2010 have anyone around been messin' with the inserting of items not found in database?my problem is this: every week my supplier sends me a CSV with actual state of the warehouse, i need update of existing items (prices, quantities), but if the product is not there, i need the script to insert iti've seen some similar requests earlier in this thread, but with no answers, so i'm asking again only to know if anything changed and someone may has the solution... Link to comment Share on other sites More sharing options...
tutygr Posted May 19, 2010 Share Posted May 19, 2010 It works perfect for me too. But I cannot update products with attributes directly using the reference number. Anyway to do that?Thank you! Link to comment Share on other sites More sharing options...
guest* Posted August 29, 2010 Share Posted August 29, 2010 It works perfect for me too. But I cannot update products with attributes directly using the reference number. Anyway to do that?Thank you! You have to ammend in line 34 this: $update_table = 'ps_product_attribute'; and it only updates with ean. If you want to update by reference you have to ammend the block to assign it, or change the $ean13 into $reference by all variables. Link to comment Share on other sites More sharing options...
guest* Posted August 29, 2010 Share Posted August 29, 2010 It works also for me in Presta 1.3.1.1 but I have one fatal problem. Quantities are updated only once. If I try to update again so the one piece is not updating into 2 pcs, i.e. if I have stock 0 before "importing" and add with the import 1 pc, so there is 1 pcs. written, if I "import" again then this 1 pc do not change into2 pcs. Also I have the problem that my file which ist generated by a barcode-scanner contains the EAN more than 1 time, beacause I receive f.ex. into stock 3 pcs. The csv is written then in this wayEAN1234567891011;11234567891011;11234567891011;12222222222222;12222222222222;1and so on. When I "import" this file with no end statement of absolute quantities, so it ammend only 1 pc. and the same ean are ignored.Is there any way to ammend the code to manage this ? Link to comment Share on other sites More sharing options...
fitgura Posted August 30, 2010 Share Posted August 30, 2010 Somebody justt tell me how it works, because nothings change in my DB, but the script run correctly..I use PS 1.3.1.1The main problem is that all of my products was imported from csv, and are these in ps_product table and not ps_product attributeok I set the correct table name in the filebut after the script ran down I checked the table in phpmyadmin and nothing was changed!!!Why is it???is that works with ps 1.3.1.1???????? Link to comment Share on other sites More sharing options...
guest* Posted August 31, 2010 Share Posted August 31, 2010 Sorry, yes you are right, it changed for me only one time the stock and also you can use only one of the tables, not both. Sorry I must pass, because I'm not a coder... Perhaps somebody else fit in php can take a look on that ?I changed also the login querries from " into ', and than it works for only one time... to update more than one time is not possible... Link to comment Share on other sites More sharing options...
shake Posted September 11, 2010 Share Posted September 11, 2010 this works perfectly for items in a single table, but how about when i need to update fields requiring 2 tablesi/e - my csv file has ean, price, quantity, name i update table ps_product (which has ean, price, quantity columns) but i also need to update the name column which is in a different table (ps_product_lang)is there any way to do this? Thanks Link to comment Share on other sites More sharing options...
chineseboy Posted September 11, 2010 Share Posted September 11, 2010 I also need to update products in multiple tables, I need to update the meta title etc. Any ideas?EDIT: I've changed the code so that I can update the date that I want but none of the new data is updating in the database. I'm trying to change the meta title, keywords and description. Any one got any more info? Link to comment Share on other sites More sharing options...
shake Posted September 12, 2010 Share Posted September 12, 2010 i believe i've sorted it change: // TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute $update_table = "ps_product"; to: // TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute $update_table = "ps_product inner join ps_product_lang on (ps_product.id_product = ps_product_lang.id_product)"; now you can update both, linked by the product idi/e when $ean = ean, (or whichever) in your csv file matches, the associated can also be updated from the product_lang table, so you can update price, quantity, ean from ps_product, but then also name, description, meta_title from ps_product_lang Link to comment Share on other sites More sharing options...
chineseboy Posted September 12, 2010 Share Posted September 12, 2010 Thanks for that shake. Tried it but the problem is that the data in my database isn't actually updating. The file is telling me that it is updating, but it isn't. The fields for meta information are all empty. It was doing the same thing before I'd implemented your changes. Any other things you can think of that could fix it? Link to comment Share on other sites More sharing options...
guest* Posted September 15, 2010 Share Posted September 15, 2010 You can import Metas, descriptions, etc- by using the import in BO. In Version 1.3.1.1 the metas are included as a standard... Or You can use HediSQL and write directly your import in Shop-DB. Link to comment Share on other sites More sharing options...
chineseboy Posted September 15, 2010 Share Posted September 15, 2010 Thanks cd500. The import function is throwing up lots of errors when attempting to update products, though not when importing brand new products. I think I need to fix something with the import.php or validate.php. Link to comment Share on other sites More sharing options...
mozack Posted September 16, 2010 Author Share Posted September 16, 2010 Hi to all,When i made this, i has in mind update just quantities from product or variation ean. It was made just because i have more than 1 store. 1 main store that have the quantities and the others goes to the first and check the quantities variations and update it to have the same quantities in all my stores.Now, you are trying to use that to other functions, by this way, i cannot still help you to make this changes. You can change the work method to your needs...Thanks Mozack Link to comment Share on other sites More sharing options...
guest* Posted September 17, 2010 Share Posted September 17, 2010 Hi Mozack,I also tried only to update quantities by ean. Code does not work, i.e. you can update only once, a sencond time is not possible and also is not possible to update attributes. Sorry I tried..Sem chance, o script nao funciona.Abracos de uma brasileira vivente na Áustria.Conny Link to comment Share on other sites More sharing options...
Bogdans Posted September 29, 2010 Share Posted September 29, 2010 welcome MozackI wish I could be updated and the name, manufacturer, descriptioncan you help me?Your script works very well.Thank you so much Link to comment Share on other sites More sharing options...
guest* Posted September 30, 2010 Share Posted September 30, 2010 OK, it works, unfortunately it is not what I need. I need a script which INCREASES the stock by the importing value. This Script only updates the stock by value given in csv.Do somebody knows how I can adapt the code for checking what is written in quantity and ADD the one given in csv ? Link to comment Share on other sites More sharing options...
Jaktis Posted October 4, 2010 Share Posted October 4, 2010 Thank you for this script, I don't know why I didn't find it before, but it has been a long time avaited for =)Here's my addition to the use of this script, a shell script to login and download a csv for the updater to use. Simply run this script via cron before the quantity_update.php .Explanation:row 2 login and download suppliers csv from ftprow 3 As my product file was tab separated text file, this row changes the separation from tabs to semicolons and saves the file as new.csv.row 4 Row 3 also added some blank rows between all products, after this gone they are and saved in a temporary file...row 5Overwrites the values from the temporary csv to the new.csvrow 6Removes the temporary csv #!/bin/bash wget -N -r -nH --cut-dirs=2 -t 180 -P /home/xyz/update/ ftp://username:[email protected]/dir_to_csv/csv.txt sed -e 's_\(\t\)\{1,\}_;_g' /home/xyz/update/beholdning.txt > /home/xyz/update/ny.csv sed '/^$/d' /home/xyz/update/new.csv > /home/xyz/update/temp.csv cut -d ';' -f 1-2 /home/xyz/update/temp.csv > /home/xyz/update/new.csv rm /home/xyz/update/temp.csv 1 Link to comment Share on other sites More sharing options...
mozack Posted October 7, 2010 Author Share Posted October 7, 2010 Hello,Well every time i come here, someone has changed the script to their needs. You're welcome.I'll try to add a new feature on it. Check the data of csv file, verify and update the current products as it do now. But the new feature is:- If sku is not in database, it send an e-mail with the list of missing sku's to admin. The point is have all products of csv file in our website.I'll try that asapRegardsMozack Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 7, 2010 Share Posted October 7, 2010 Guys, I wrote a class that downloads an XML feed and changes the qtys. It downloads the XML file if it is >1 day old and stores it locally.Then it looks up the product based on information in the XML file.It kind of does this real-time, if a product is viewed and the qty is not == the value in the XML, it changes it.It works from category.php and product.php.If you'd like it to modify to do with csv, let me know.It could also be modified to ftp the file, kind of like how I do it with one of our vendor update files. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 8, 2010 Share Posted October 8, 2010 What happened to the last post in this thread? I rcvd a notification that said this message was posted: Great news mate, can you perhaps expand it to update price and availability? Will the poster please repost? Are you talking about my class?If so, then yes it could be modified to do that as well. Link to comment Share on other sites More sharing options...
guest* Posted October 9, 2010 Share Posted October 9, 2010 I'm using now this Tool to change all by mass....http://addons.prestashop.com/en/search.php?id_category_search=0&search_query=prestagate Link to comment Share on other sites More sharing options...
chetwyn Posted September 14, 2012 Share Posted September 14, 2012 Hey guys, because this is being done from the backend what Hook do we need to call to execute the "email when in stock" functionality so all the users get the email when the product is back in stock ? Link to comment Share on other sites More sharing options...
chetwyn Posted September 14, 2012 Share Posted September 14, 2012 (edited) Sorry guys. But just wanted to be clear. After the script has run it does not send out email alerts to all the customer that requested to be notified once that product is back in stock. Do we need to call some hook or.. ? please help. Here's is my working code. <?php // -------------------------------------------------- // // To run open in your browser. // Example: http://www.mysite.com/secure_folder/update.php // // --------------------------------------------------- //Configuration variables //--------------------------------------------------- // Connect to MySQL change with your data - Not required, we'll use global class //mysql_connect("LOCALHOST", "here goes your login", "here goes your password") or die(mysql_error()); //mysql_select_db("heregoes your database name") or die(mysql_error()); // If first row of csv file is headings set $row to 1. $row = 0; // TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute $update_table = "ps_product_attribute"; // Get the csv file - INSERT THE ADDRESS OF CSV FILE OR UPLOAD IT TO THE SOME FOLDER OF THIS SCRIPT // $handle = fopen("update.csv", "r"); $fileName = "update.csv"; // Load gloabl libs $site_base_path = "../"; include($site_base_path . 'config/config.inc.php'); require_once($site_base_path . 'classes/Link.php'); require_once($site_base_path . 'classes/Product.php'); require_once($site_base_path . 'init.php'); // Go through the csv file and print each row with fields to the screen. // And import them into the database updating only the price and quantity if (file_exists($filename)) { echo "The file $filename exists"; $handle = fopen($fileName, "r"); while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { $num = count($data); echo "\n"; echo "( $row )\n"; $row++; for ($c=0; $c < $num; $c++) { if ($c = 1) { $reference = $data[($c - 1)]; echo $reference . " - Reference Assigned\n"; } if ($c = 2) { $quantity = $data[($c - 1)]; echo "</br> "."UPDATE ".$update_table." SET quantity=".$quantity." WHERE reference='".$reference."'"."</br> "; Db::getInstance()->Execute("UPDATE ".$update_table." SET quantity=".$quantity." WHERE reference='".$reference."'"); echo $quantity . " - Quantity updated\n"; } /* if ($c = 3) { $price = $data[($c - 1)]; Db::getInstance()->Execute(("UPDATE $update_table SET price='$price' WHERE reference='$reference'") or die(mysql_error()); echo $price . " - Price updated\n"; } if ($c = 4) { $active = $data[($c - 1)]; mysql_query("UPDATE $update_table SET active='$active' WHERE reference='$reference'") or die(mysql_error()); echo $active . " - Activity updated\n"; echo "_____________________________________________________\n"; } */ } } } // Update quantity in ps_product table to equal total quantity for combinations. $sqlRecs = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("select id_product, sum(quantity) as qty from ps_product_attribute group by id_product"); foreach($sqlRecs as $rec){ Db::getInstance()->Execute("update ps_product set quantity = ".$rec['qty'].' where id_product = '.$rec['id_product']); echo "\n</br> Updated ID: ".$rec['id_product']."\n"; } fclose($handle); echo " \n"; echo " - - - SUCESSFULY COMPLETED - - - "; ?> Edited September 14, 2012 by chetwyn (see edit history) 1 Link to comment Share on other sites More sharing options...
chetwyn Posted September 15, 2012 Share Posted September 15, 2012 bump... Link to comment Share on other sites More sharing options...
rseigel Posted October 10, 2012 Share Posted October 10, 2012 Any ideas how to get this to work in 1.5 since the quantity field moved from the product table to stock_available table? 1 Link to comment Share on other sites More sharing options...
davide.l Posted December 29, 2014 Share Posted December 29, 2014 There have been developments for prestashop 1.6?? Link to comment Share on other sites More sharing options...
thijsvk Posted November 17, 2015 Share Posted November 17, 2015 This is my solution on 1.6.1.1 (cross post). My knowledge is limited, so the more people look at it, and give input the better. Link to comment Share on other sites More sharing options...
Recommended Posts