sugemallen Posted January 6, 2010 Share Posted January 6, 2010 Hi AllWhy cant I do this in line 124:$this->available_fields = array('no' => $this->l('Ignore this column'),'id' => $this->l('ID'),'active' => $this->l('Active (0/1)'),'no' => $this->l('Ignore this column'),'no' => $this->l('Ignore this column'), 'category' => $this->l('Categories (x,y,z...)'),I want to change the file so that it matches my csv... After active it is supposed ti ignore the next 2 columns bit it doesn't????Thank you! Link to comment Share on other sites More sharing options...
xavriley Posted January 8, 2010 Share Posted January 8, 2010 I've managed to do this slightly differently;Find the function receiveTab() and change it as follows; private function receiveTab() { if (Tools::getValue('type_value')) { self::$column_mask['active'] = '1'; self::$column_mask['name'] = '2'; self::$column_mask['category'] = '3'; self::$column_mask['price_tex'] = '4'; self::$column_mask['tax_rate'] = '5'; self::$column_mask['reference'] = '12'; self::$column_mask['supplier_reference'] = '13'; self::$column_mask['supplier'] = '14'; self::$column_mask['manufacturer'] = '15'; ... self::$column_mask['#F_AB Exams - '] = '34'; self::$column_mask['#F_Type of Publication - '] = '35'; self::$column_mask['#F_Dimensions in mm - '] = '36'; self::$column_mask['#F_No of Pages - '] = '37'; } } This isn't quite what you were looking for as it basically disables the select boxes on the import screen - you just click 'Import CSV' and it'll do exactly the same every time, no matter what the boxes say.To explain the code -the number on the right is the field of the .csv line (which starts from 0)ie '0' = id_product'1' = active etc.Also, the string "#F_" has to go before any feature names.Other than that, you're good to go. Link to comment Share on other sites More sharing options...
sugemallen Posted January 8, 2010 Author Share Posted January 8, 2010 Thanks! it works fine... I want to do the import automatic every day, do you have an idea to do the import of the following csv'sFirst Categories and then Products...I'm currently opening prestashop admin with the URL for the import page. But I have to press the NEXT -> IMPORT for both files...Do you have an idea??? I believe you must have had the same issue... Link to comment Share on other sites More sharing options...
xavriley Posted January 9, 2010 Share Posted January 9, 2010 Yes I'm currently working through it at the moment.At the moment I'm getting the followingWarning: require_once(/home/xavriley/public_html/prestashop/config/../classes/AdminImport.php) [function.require-once]: failed to open stream: No such file or directory in /home/xavriley/public_html/prestashop/config/config.inc.php on line 20Fatal error: require_once() [function.require]: Failed opening required '/home/xavriley/public_html/prestashop/config/../classes/AdminImport.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xavriley/public_html/prestashop/config/config.inc.php on line 20I've basically had to replace all the Tools::getValue() things with class variables that I've defined class AdminImportOUP extends AdminTab { //these replace the post-variables to automate things var $postSkip = 0; var $postCsv = "somefile.txt"; var $postConvert = null; var $postEntity = 1; var $postSeparator = ";"; var $postMultiple_value_separator = ","; var $postImport = "Import CSV data"; //var $postSubmitImportFile = "Next Step"; var $postSubmitFileUpload = null; .. then for example replace Tools::getValue('csv') with $this->postCsv and so on.Used tamperdata for Firefox to find out what they were. Problem is that when I try and call $this->productImport(); I get the error above (with error reporting turned on). I know it's working for a while though because if you put a print_r($info); into the productImport() function it displays the first line of the csv.If you uncoment the SubmitImportFile it displays the 'second step' of the import where you select fields, so I know that works.It's been several hours so any help would be much appreciated. Link to comment Share on other sites More sharing options...
xavriley Posted January 10, 2010 Share Posted January 10, 2010 Ugh,I've done it and it was a stupid error that cost me all that time. Oh well.So, in order to automate the Import tab here's what I suggest.1) duplicate the file admin->tabs->AdminImport.php2) rename it to something like AdminImportAutomatic.php or whatever. Now open it up and change this; (line 26) class AdminImport extends AdminTab { to this (line 26) class AdminImportAutomatic extends AdminTab { and then do a find and replace for 'AdminImport' and replace with 'AdminImportAutomatic' where it's like this (line 38 onwards) public static $validators = array( 'active' => array('AdminImport', 'getBoolean'), 'tax_rate' => array('AdminImport', 'getPrice'), 'price_tex' => array('AdminImport', 'getPrice'), // Tax excluded 'price_tin' => array('AdminImport', 'getPrice'), // Tax included 'reduction_price' => array('AdminImport', 'getPrice'), 'reduction_percent' => array('AdminImport', 'getPrice'), becomes this (line 38 onwards) public static $validators = array( 'active' => array('AdminImportAutomatic', 'getBoolean'), 'tax_rate' => array('AdminImportAutomatic', 'getPrice'), 'price_tex' => array('AdminImportAutomatic', 'getPrice'), // Tax excluded 'price_tin' => array('AdminImportAutomatic', 'getPrice'), // Tax included 'reduction_price' => array('AdminImportAutomatic', 'getPrice'), 'reduction_percent' => array('AdminImportAutomatic', 'getPrice'), ..... There's quite a few so go through and make sure you get them all.3) Do what I said in the previous post where you change the ReceiveTab() function4) Add these to the start of the class AdminImportAutomatic bit... class AdminImportAutomatic extends AdminTab { //these replace the post-variables to automate things var $postSkip = 0; var $postCsv = "somecsvfile.txt"; // This should be put in the regular admin->import folder var $postConvert = null; // if you don't want to convert from iso to utf8, put "true" if you do var $postEntity = 1; // this is what decides the type of import - 0 for cats, 1 for products, 2 for customers var $postSeparator = ";"; // csv separator - i found it best to stick with semi colon var $postMultiple_value_separator = ","; var $postImport = "Import CSV data"; //THIS IS THE IMPORTANT ONE //var $postSubmitImportFile = "Next Step"; //var $postSubmitImportFile = ""; var $postSubmitFileUpload = null; // AND SO IS THIS And like I said previously, go through the pain of replacing Tools::getValue('skip') with $this->'postSkip'and so on...5) With all that done, go to the Admin section -> Tools -> Tabs Click 'Add New' Name - (whatever you want the tab to be called) Class - AdminImportAutomatic Module - (leave blank) Icon - if you're feeling fancy... Parent - I put it under Tools next to Import6) Go to tools and click this new tab - you should see a success message. Go check the catalog and see if you've got new products in. Give yourself a pat on the back.7) Not done yet! If you want to call the import automatically (ie from a cron job/ bash script) you have to get round the token. For an easy hack, change classes->AdminTab.php line 1439 to public function checkToken() { $token = Tools::getValue('token'); if ($token == "123456789") { return true; } elseif (!$token OR empty($token) OR ($token != $this->token)) { echo ' '.Tools::displayError('Invalid security token').''; return false; } return true; } then call your new tab with http://www.yoursite.com/prestashop/admin/index.php?tab=AdminImportAutomatic&token=123456789PLEASE NOTE - This is probably not the *safest* way to do this but it's up to you. If you're worried about it shove it in an external file and include it or something.All done - hope it works for you. Link to comment Share on other sites More sharing options...
sugemallen Posted January 11, 2010 Author Share Posted January 11, 2010 Hi xavrileyGreat!!!! would it be to much to ask for you to mail or post your adminimport.php here??? or [email protected]I keep getting a blank screen when pressing the tab, so I'm doing something wrong...I'll keep trying to get this going... Maybe I'll learn something else You did a great job!!! Link to comment Share on other sites More sharing options...
xavriley Posted January 11, 2010 Share Posted January 11, 2010 Hi can't post the whole thing right now but I will later;Try this. In AdminImport.php find these lines near the top include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); include_once(PS_ADMIN_DIR.'/../images.inc.php'); @ini_set('max_execution_time', 0); and add these immediately afterward ; ini_set('display_errors','On'); ini_set('error_reporting', E_ALL); Which should turn on error reporting for you, then let me know what it says when you run the script.Also, find the productImport() function around Line 568 and add a print_r() after $info. This means you'll get to see what exactly is going into the array. Paste it up here as well. $info = self::getMaskedRow($line); print_r($info); Link to comment Share on other sites More sharing options...
Jmenchik Posted March 22, 2010 Share Posted March 22, 2010 Hi xavrileyWhen I call my new tab in IE I do not get any notices or errors and no any products have been imported.Maybe I'm wrong somwere. Can You explain replacing this code: Tools::getValue(‘skip’)with$this->‘postSkip’Thanks in advance! Link to comment Share on other sites More sharing options...
keesklapperface Posted May 31, 2010 Share Posted May 31, 2010 xavriley,Thnx alot for taking the time to explain this 'mod' for the adminImportBut in the public function 'postProcess' i replaced the: Tools::isSubmit('submitFileUpload') and Tools::isSubmit('submitImportFile')) with:$this->postSubmitFileUpload and $this->postSubmitImportFileso it now looks like this: public function postProcess() { global $currentIndex; if ($this->postSubmitFileUpload) //if (Tools::isSubmit('submitFileUpload')) { if (!isset($_FILES['file']['tmp_name']) OR empty($_FILES['file']['tmp_name'])) $this->_errors[] = $this->l('no file selected'); elseif (!file_exists($_FILES['file']['tmp_name']) OR !@rename($_FILES['file']['tmp_name'], dirname(__FILE__).'/../import/'.$_FILES['file']['name'].'.'.date('Ymdhis'))) $this->_errors[] = $this->l('an error occured while uploading and copying file'); else Tools::redirectAdmin($currentIndex.'&token;='.Tools::getValue('token').'&conf=18'); } elseif ($this->postSubmitImportFile) //elseif (Tools::isSubmit('submitImportFile')) $this->displayCSV(); elseif ($this->postImport) { if ($this->postTruncate) $this->truncateTables(intval($this->postEntity)); switch (intval($this->postEntity)) { Maybe i'm wrong or you forgot to put that in your post, maybe it saves someone some time. Link to comment Share on other sites More sharing options...
mpoladian Posted August 30, 2010 Share Posted August 30, 2010 Can anyone send me a copy of their AdminImportAutomatic.php file? Or can I send you a copy of mine to see what I may be missing? I've followed all the previous posts above and am soo close, but am not getting anything to show when I go to that page. I must be stuck at the same place as the others before me, can someone please help!I would post my code here, but that would be a lot, so I have attached it to this postThanks,Matt AdminImportAutomatic.php Link to comment Share on other sites More sharing options...
siadmin Posted October 13, 2010 Share Posted October 13, 2010 I believe I've followed all the instructions correctly, but when I run the script i get this error:Warning: Invalid argument supplied for foreach() in /path/to/script/AdminImportProducts.php on line 353Array ( ) the code on that line is as follows.. public static function getMaskedRow($row) { $res = array(); foreach (self::$column_mask AS $type => $nb) $res[$type] = isset($row[$nb]) ? $row[$nb] : null; return $res; } 353 is - 'foreach (self::$column_mask AS $type => $nb)'As far as i can tell this is my last hurdle, the script is adding records to the product tables, but the csv data isnt added, its just null fields.Any help greatly appreciated. Link to comment Share on other sites More sharing options...
sifo Posted October 28, 2010 Share Posted October 28, 2010 I did exactly what xavriley wrote should be done, but I also have just empty screen (Tabs are at the top of page, but nothing else). I even added print_r() as described, but nothing, not even error.Is there anyone who made it to the end?Or do you know other way of doing this? I mean automatic import using cron for example.Thank you. Link to comment Share on other sites More sharing options...
siadmin Posted December 8, 2010 Share Posted December 8, 2010 yes my script works now. http://www.prestashop.com/forums/viewthread/80611/development/automated_store_update/ Link to comment Share on other sites More sharing options...
jayxflash Posted December 3, 2011 Share Posted December 3, 2011 Here is a working version to import combinations tested on version 1.4.6.2. Anyway, at this point I can't use it with cronjobs even with the toke trick. The lynx command always asks for username and password to access the login page. Any ideas? AdminImportCombinations.php Link to comment Share on other sites More sharing options...
keesklapperface Posted December 5, 2011 Share Posted December 5, 2011 Maybe just a crazy idea to run the php directly from the console > php myPhpScript.php Note when running this in a cronjob you'll probably need to add the path of myPhpScript.php 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