Martin_S Posted October 3, 2010 Share Posted October 3, 2010 My supplier offers live data feeds on stock status (CSV and XML) and I would like to show my customers the stock information on product pages in my shop, as I do a kind of a drop shipping. So if the supplier has the product in stock, it would show "is stock" on my shop and "out of stock" if the product is not available in thier warehouse. Is this possbile or not? I only see the import tool but I dont know if its updated automatically from the live feed. Please help. thanks Link to comment Share on other sites More sharing options...
Martin_S Posted October 4, 2010 Author Share Posted October 4, 2010 No way? No module for this? I just want to show live supplier stock status for each product. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 4, 2010 Share Posted October 4, 2010 See: http://www.prestashop.com/forums/viewthread/67552/development/what_db_fields_are_used_when_adding_a_productNow, are you talking about actually live info directly from your supplier?How do they provide this info? That is the key, here Link to comment Share on other sites More sharing options...
Martin_S Posted October 4, 2010 Author Share Posted October 4, 2010 See: http://www.prestashop.com/forums/viewthread/67552/development/what_db_fields_are_used_when_adding_a_productNow, are you talking about actually live info directly from your supplier?How do they provide this info? That is the key, here Yes, they provide URL to the XML file or download and [spam-filter] CSV data feeds. Its available online. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 4, 2010 Share Posted October 4, 2010 I find it hard to believe that it is *live* if it is just a download.I would think they would provide a webservice or something like that.You got a url? if you want you can PM me. Link to comment Share on other sites More sharing options...
Martin_S Posted October 4, 2010 Author Share Posted October 4, 2010 I find it hard to believe that it is *live* if it is just a download.I would think they would provide a webservice or something like that.You got a url? if you want you can PM me. PM sent, like I said, they also offer XML feed online Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 4, 2010 Share Posted October 4, 2010 Now that is cool. However, it would be better if they'd let you pass a productID to the feed to get only that product's status. Then it would be MUCH, MUCH faster...Maybe you could suggest that to them?? Link to comment Share on other sites More sharing options...
princechlesh Posted October 5, 2010 Share Posted October 5, 2010 I wish to write a program to read various data about the stock market (eg, price of a stock, VIX), and then process it with some programming (eg, C/C++, PERL). Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 5, 2010 Share Posted October 5, 2010 I wish to write a program to read various data about the stock market (eg, price of a stock, VIX), and then process it with some programming (eg, C/C++, PERL). Please explain better what you want. The original request has nothing to do with stock market values. Link to comment Share on other sites More sharing options...
Martin_S Posted October 5, 2010 Author Share Posted October 5, 2010 Now that is cool. However, it would be better if they'd let you pass a productID to the feed to get only that product's status. Then it would be MUCH, MUCH faster...Maybe you could suggest that to them?? I may ask, but would that help me? Is there a way to display this in my shop?I thought, prestashop allows to use the imort tool to show this information "live" from the source .. but its only one-time import as it looks. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 5, 2010 Share Posted October 5, 2010 martin_S, I sent you a PM. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 5, 2010 Share Posted October 5, 2010 In category.php in your store root directory, you will see this code around line 62: $smarty->assign(array( 'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL, 'id_category' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)), 'path' => Tools::getPath(intval($category->id), $category->name) )); Place the code below BEFORE the code above. Explaination below... /************************************************/ // If the status file is > 1 day old, go get it // and save it so searches will be faster. /************************************************/ $filename = 'stock.xml'; if(file_exists($filename)) { clearstatcache(); $ft = filemtime($filename); $past = mktime(0, 0, 0, date("m"), date("d")-1,date("Y")); if($ft<$past) { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } } else { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } /************************************************/ // Load the file into a SimpleXML object /************************************************/ $xmlstring = file_get_contents($filename); $xml = new SimpleXMLElement($xmlstring); foreach($cat_products as &$product) { /************************************************/ // Find the node for the id_product // and echo out the stock value // else return 0. // Should only be one node returned per id_product. /************************************************/ $result = $xml->xpath('/stockreport/products/product/code[text()="'.$product['reference'].'"]/..'); if($result) { list( , $node) = each($result); $qty = intval($node->stock); $found=true; } else { $found=false; } /************************************************/ // Now, update stock quantity in ps_product /************************************************/ if($found and $product['quantity'] <> $qty) { $product['quantity'] = $qty; $sql = 'UPDATE `'._DB_PREFIX_.'product` SET quantity = '.$qty.' WHERE reference = "'.$product['reference'].'"'; Db::getInstance()->Execute($sql); } } What the code does is it checks the file stock.xml to see it is is more than a day old. If it is or if it isn't found, it downloads it.Then it iterates through all the products on the page and checks to see if they are in the XML file. If they are, it updates the stock value in the database and continues on.This will happen for each page of products in your category. It checks to see it the quantity in the XML is different so it won't be doing DB updates every time.This is about as real time as you are going to get. I thought about using ajax but it was troublesome because the call had to be made for each product on the page so I figured out a different way of doing it. It will be a little slow the first time it has to download the XML but after that is is very fast.Good luck with your shop...For a good laugh, I posted some of your XML on PHPBuilder forums but didn't really look at the products. Heaven knows I quickly went in and mdified my post after seeing some of them... ;-) Link to comment Share on other sites More sharing options...
Martin_S Posted October 5, 2010 Author Share Posted October 5, 2010 thank you, is this safe to try?? Link to comment Share on other sites More sharing options...
Martin_S Posted October 5, 2010 Author Share Posted October 5, 2010 In category.php in your store root directory, you will see this code around line 62: $smarty->assign(array( 'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL, 'id_category' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)), 'path' => Tools::getPath(intval($category->id), $category->name) )); Place the code below BEFORE the code above. Explaination below... /************************************************/ // If the status file is > 1 day old, go get it // and save it so searches will be faster. /************************************************/ $filename = 'stock.xml'; if(file_exists($filename)) { clearstatcache(); $ft = filemtime($filename); $past = mktime(0, 0, 0, date("m"), date("d")-1,date("Y")); if($ft<$past) { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } } else { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } /************************************************/ // Load the file into a SimpleXML object /************************************************/ $xmlstring = file_get_contents($filename); $xml = new SimpleXMLElement($xmlstring); foreach($cat_products as &$product) { /************************************************/ // Find the node for the id_product // and echo out the stock value // else return 0. // Should only be one node returned per id_product. /************************************************/ $result = $xml->xpath('/stockreport/products/product/code[text()="'.$product['reference'].'"]/..'); if($result) { list( , $node) = each($result); $qty = intval($node->stock); $found=true; } else { $found=false; } /************************************************/ // Now, update stock quantity in ps_product /************************************************/ if($found and $product['quantity'] <> $qty) { $product['quantity'] = $qty; $sql = 'UPDATE `'._DB_PREFIX_.'product` SET quantity = '.$qty.' WHERE reference = "'.$product['reference'].'"'; Db::getInstance()->Execute($sql); } } What the code does is it checks the file stock.xml to see it is is more than a day old. If it is or if it isn't found, it downloads it.Then it iterates through all the products on the page and checks to see if they are in the XML file. If they are, it updates the stock value in the database and continues on.This will happen for each page of products in your category. It checks to see it the quantity in the XML is different so it won't be doing DB updates every time.This is about as real time as you are going to get. I thought about using ajax but it was troublesome because the call had to be made for each product on the page so I figured out a different way of doing it. It will be a little slow the first time it has to download the XML but after that is is very fast. wow.. I will try it and see, thanks!Good luck with your shop... Thank you very much. For a good laugh, I posted some of your XML on PHPBuilder forums but didn't really look at the products. Heaven knows I quickly went in and mdified my post after seeing some of them... ;-) :-D :-D Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 5, 2010 Share Posted October 5, 2010 BTW, the email listed on your profile bounced. I used the email function from the profile page. Link to comment Share on other sites More sharing options...
Martin_S Posted October 6, 2010 Author Share Posted October 6, 2010 BTW, the email listed on your profile bounced. I used the email function from the profile page. I updated the email address, try again please ;-) Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 7, 2010 Share Posted October 7, 2010 Martin, per our last conversation, change any instances of this:$product['reference']to this:$product['supplier_reference']in the code I posted above and it should work for you. Link to comment Share on other sites More sharing options...
YHK Posted October 13, 2010 Share Posted October 13, 2010 I was wondering when doing this change to the category.php file, will this download and xml bounce happen everytime a customer is on the site and loads a product page? Is there anyway i could do something like this on my own on like a weekly basis instead of it done everytime a customer loads the pages. What happens if the url where the xml file is hosted doesnt load at the time its requested? Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 13, 2010 Share Posted October 13, 2010 I was wondering when doing this change to the category.php file, will this download and xml bounce happen everytime a customer is on the site and loads a product page? Of course, you just need to take out the part that FTPs the XML file(s). Is there anyway i could do something like this on my own on like a weekly basis instead of it done everytime a customer loads the pages. What happens if the url where the xml file is hosted doesnt load at the time its requested? Then it woj't update any qtys because it will look at the old file, if there is one. I don't remember if I put an exception handler in to check if he file actually exists, ubt it shouldn't update anything if it doesn't find the file. Link to comment Share on other sites More sharing options...
gngnet Posted October 13, 2010 Share Posted October 13, 2010 First I'd like to say hi to every one,This seems to be very useful feature, could it be turned in to a module and data-feed URL be entered on a supplier basis ?Module fields required being something like:-Supplier (from drop-down list of suppliers already in database)Feed (URL to suppliers XML data feed)update period (number of hours / days before update)I noticed in the XML feed in the post that there were some 'End Of Line' products, maybe this code could also automatically disable a product if its status is 'End Of Line' and stock is '0' (check-box optional)Just some thoughts on what looks like a great feature.Once again very useful thanks MrBaseball Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 14, 2010 Share Posted October 14, 2010 I am beginning plans to turn it into a module. There are some logistical and UI issues that have to be overcome, first. 1 Link to comment Share on other sites More sharing options...
ismtech Posted November 28, 2010 Share Posted November 28, 2010 Hello Mr Baseball and all on this postPlease can you let me know if you have made any progress on turning this into a module for prestashop as this is something I am in need of aswell.I have looked at other options too which are working for other carts, maybe we can spend a few minutes going through it if you can spare some time, please let me know.Look forward to your replyRegards Link to comment Share on other sites More sharing options...
MrBaseball34 Posted November 30, 2010 Share Posted November 30, 2010 After taking a look at this, it seems that with the variety of vendor exports and formats, it would be near impossible to configure a module to do this.I thought, first, that I could build a configuration tool where it would load an XML file, read the schema and then offer a way for you to drag/drop various nodes into a configuration that would be used for importing data.However, it is too difficult for me to work on at this time as I have way too many things on my plate right now to do any open source work. Heck, I haven't even had time to revisit the GoogleBase module I've been working on. Link to comment Share on other sites More sharing options...
ismtech Posted November 30, 2010 Share Posted November 30, 2010 thank you for your replyI understand about the time constraint, however if you do find time in future would be excellent if we can go over this together.Kind Regards Link to comment Share on other sites More sharing options...
cassim Posted January 25, 2011 Share Posted January 25, 2011 In category.php in your store root directory, you will see this code around line 62: $smarty->assign(array( 'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL, 'id_category' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)), 'path' => Tools::getPath(intval($category->id), $category->name) )); Place the code below BEFORE the code above. Explaination below... /************************************************/ // If the status file is > 1 day old, go get it // and save it so searches will be faster. /************************************************/ $filename = 'stock.xml'; if(file_exists($filename)) { clearstatcache(); $ft = filemtime($filename); $past = mktime(0, 0, 0, date("m"), date("d")-1,date("Y")); if($ft<$past) { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } } else { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } /************************************************/ // Load the file into a SimpleXML object /************************************************/ $xmlstring = file_get_contents($filename); $xml = new SimpleXMLElement($xmlstring); foreach($cat_products as &$product) { /************************************************/ // Find the node for the id_product // and echo out the stock value // else return 0. // Should only be one node returned per id_product. /************************************************/ $result = $xml->xpath('/stockreport/products/product/code[text()="'.$product['reference'].'"]/..'); if($result) { list( , $node) = each($result); $qty = intval($node->stock); $found=true; } else { $found=false; } /************************************************/ // Now, update stock quantity in ps_product /************************************************/ if($found and $product['quantity'] <> $qty) { $product['quantity'] = $qty; $sql = 'UPDATE `'._DB_PREFIX_.'product` SET quantity = '.$qty.' WHERE reference = "'.$product['reference'].'"'; Db::getInstance()->Execute($sql); } } What the code does is it checks the file stock.xml to see it is is more than a day old. If it is or if it isn't found, it downloads it.Then it iterates through all the products on the page and checks to see if they are in the XML file. If they are, it updates the stock value in the database and continues on.This will happen for each page of products in your category. It checks to see it the quantity in the XML is different so it won't be doing DB updates every time.This is about as real time as you are going to get. I thought about using ajax but it was troublesome because the call had to be made for each product on the page so I figured out a different way of doing it. It will be a little slow the first time it has to download the XML but after that is is very fast.Good luck with your shop...For a good laugh, I posted some of your XML on PHPBuilder forums but didn't really look at the products. Heaven knows I quickly went in and mdified my post after seeing some of them... ;-) Hi that sounds great.will you be able to make that on a other xml also ?I need to update my own stock always to this.It have no numbers as stock just :Ukendt leveringstid (unknown delivery time) Ja Lager (yes in stock) Or it shows a number of days before in stockCan you make your code update my stock after this ?http://customdata.dk/p.xml Link to comment Share on other sites More sharing options...
Andy1 Posted September 16, 2011 Share Posted September 16, 2011 Has anyone tried this with 1.4.4.1? Link to comment Share on other sites More sharing options...
Andy1 Posted September 16, 2011 Share Posted September 16, 2011 All I have in my category php file is: <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include(dirname(__FILE__).'/config/config.inc.php'); ControllerFactory::getController('CategoryController')->run(); Link to comment Share on other sites More sharing options...
MrBaseball34 Posted October 6, 2011 Share Posted October 6, 2011 All I have in my category php file is: make the changes in /classes/Category.php not /category.php Link to comment Share on other sites More sharing options...
Andy1 Posted November 2, 2011 Share Posted November 2, 2011 Thank you for the reply, and sorry it has taken me so long to respond. Within the XML file there are two product codes, a 'Main Product Code' and a 'Sub Product Code'. Do you know if these are for Reference Number or EAN within the back office? Many Thanks Andy Link to comment Share on other sites More sharing options...
paulcreedy Posted June 18, 2012 Share Posted June 18, 2012 Hi MrBaseball Looking for some code to do exactly the same thing I stumbled upon yours. I'd like to customise it for the two different feeds that my 'future' shop is going to use. However ideally I'd like to take it out of the main code and have this in a separate folder just for feeds, and call it automatically once a day via the server. Knowing very little about PHP and even less about Prestashop could you point me in the direction of how to make this code stand alone without putting it inside another Prestashop file? There are far too many suppliers out that to make a universal module, and feeds keep changing also, but there's enough info in there for me to customise it to the feeds I use. Thank you Link to comment Share on other sites More sharing options...
paulcreedy Posted June 23, 2012 Share Posted June 23, 2012 Could someone tell me what I need to put in front of this code to make it stand alone instead of inserting it into a preexisting file? Link to comment Share on other sites More sharing options...
gmurray Posted January 28, 2013 Share Posted January 28, 2013 I have the Prestashop 1.5.3.1 and when I open category.php I do not have the following code: $smarty->assign(array( 'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL, 'id_category' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)), 'path' => Tools::getPath(intval($category->id), $category->name) )); I guess it is different in the latest versions - can someone let me know when I would place this code in the latest version: /************************************************/ // If the status file is > 1 day old, go get it // and save it so searches will be faster. /************************************************/ $filename = 'stock.xml'; if(file_exists($filename)) { clearstatcache(); $ft = filemtime($filename); $past = mktime(0, 0, 0, date("m"), date("d")-1,date("Y")); if($ft<$past) { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } } else { @copy('http://www.1on1wholesale.co.uk/members_area/feeds.2.0/status-xml.asp', 'stock.xml'); } /************************************************/ // Load the file into a SimpleXML object /************************************************/ $xmlstring = file_get_contents($filename); $xml = new SimpleXMLElement($xmlstring); foreach($cat_products as &$product) { /************************************************/ // Find the node for the id_product // and echo out the stock value // else return 0. // Should only be one node returned per id_product. /************************************************/ $result = $xml->xpath('/stockreport/products/product/code[text()="'.$product['reference'].'"]/..'); if($result) { list( , $node) = each($result); $qty = intval($node->stock); $found=true; } else { $found=false; } /************************************************/ // Now, update stock quantity in ps_product /************************************************/ if($found and $product['quantity'] <> $qty) { $product['quantity'] = $qty; $sql = 'UPDATE `'._DB_PREFIX_.'product` SET quantity = '.$qty.' WHERE reference = "'.$product['reference'].'"'; Db::getInstance()->Execute($sql); } } Thanks Guy Link to comment Share on other sites More sharing options...
Recommended Posts