Jump to content

thijsvk

Members
  • Posts

    43
  • Joined

  • Last visited

Profile Information

  • Activity
    Other

Recent Profile Visitors

5,630,672 profile views

thijsvk's Achievements

Newbie

Newbie (1/14)

4

Reputation

3

Community Answers

  1. Hmm, I'm still inclined to think that it might have something to do with the permissions, that echo doesn't work because the php file is not actually executed. Unfortunately, I'm rather limited in my knowledge. Might be an idea to ask someone like Vekia or ElPatron to have a look.
  2. Are the products set to have the quantities entered manually? Also, what are the chmod settings on the files? It could be that they don't have the right permissions to be executed
  3. Have you tested it with the path set in the script? $remote_csv_file = './scriptsActualizacion/uno.csv'; In theory you shouldn't have to if they're in the same location, but theory...
  4. Did you actually set a path to your CSV file, or is it set exactly as you posted?
  5. Hi all, sorry for the delay in replying, holidays and all that. Happy Holidays!!! Only just got back to the office, and really shouldn't be here, damn holiday flu. Glad everything is working out for you TACS, in my experience it usually is a bit of a pain to figure out and adjust someone else's code, or that might just be me. Yes, I use comma separation, but you can use any delimiter really, as long as you change it in line 32. thrillmetoo I will upload the macro files as soon as I have time to sanitize them, I have some end of year dead lines, so it will probably be next week before I get around to it. Again, I can't really take credit for this, other than finding it and sharing it here, but it is nice to see it being beneficial to others
  6. Hi ken-bcn, you have a few options if I understand you correctly. Correct me if I'm wrong, but you have different suppliers, and you don't want the quantities to be set to zero. Well, if the script works for you as is, without having to reset to zero, then you can just comment it out, so it doesn't run, just put // in front of each line from '//RESET CYCLE' to '//END'. Do you have stock information from all of your suppliers? If so, you can just use the solution above. Make a master excel stock file, put all the products from all of your suppliers in the first sheet, and then create separate sheets for each of your suppliers and populate them using the import function. Create/record a macro that updates all the different sheets and again with Vlookup, the quantities on the first sheet will automatically update as well. If you want you can put a button on that first sheet so that if you click it, it will call the macro and run the updates. You can then export the first sheet using the stockupdatemacro.xls (make sure you incorporate running the update macro in your stock workbook. That should do it, everything will run as it should in one go. Alternatively, you can take the original process and use it to set up individual cronjobs for each of your suppliers. Each cronjob will then update an individual supplier and its products. Good luck!!!
  7. Hi TACS, thanks for the comments, I know, Notepad++ is awesome, it never occurred to me to use it for this exercise though, I'll have to look into that. with regards to the excess products, If I remember correctly, it will add them, but they won't show up on the front end. However, I prefer to keep the DB clean. For me, the simplest solution is to have all your products in an excel sheet (product column and quantity column, in the same workbook, start another sheet, and import the csv file from your supplier in that sheet. Using Vlookup, you can then have the first sheet check the available quantities for just your products. When you create the (new) macro template, you can record it to update the quantities, and then export the first sheet as the stock csv which will be uploaded.
  8. Hey TACS, it's not that hard really, just follow these steps: Prepare your csv upload, if you are lucky, then you can just use the information as provided by your supplier, otherwise you will need do some more work. Assuming your supplier does not send you a csv file with just 'product_reference' and 'quantity', you will need to create an excel file with a macro that will extract that information and copy it to a new file, and save that file as a csv. Basically, open a new excel file > record macro > while recording, open the supplier file, select the columns you need, copy them, open a new excel file, paste the columns, save as something like 'stockinfo.csv' in a location of your choice > go back to the first excel file and click 'stop recording to finish the macro. Save this file as stockupdatemacro.xls(x). Add a job to Windows System Scheduler to run that macro file as often as you need, to regenerate the CSV file. You will need a program like AutoFTP to automatically (scheduled) upload the CSV file to your webhost, in a location of your choice. Copy the php cron job above and save it as something like cronstockupdate.php and upload this to a location of your choice on your webhost (remember where you upload the files). The cron task manager doesn't really work, so your best bet is to use a site like easycron.com and set it to run the cronjob that you created (you need the location of the cron job for this) and then set it to run as often as needed. And that's it really. If you are able to download the supplier stock info through ftp, you can automate that as well, so it downloads it when you tell it to, and then have the macro job run a few minutes afterwards, followed by the AutoFTP upload a few minutes after that, and then the cronjob a few minutes after that.
  9. 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.
  10. SORTED!!!! The problem was that the reset to zero code didn't execute properly / at all. Whether this had to do with the location within the rest of the code, I have no idea. This resulted in the quantities in the csv file being added to the quantities present in the DB, rather than overwriting them (only for product combination quantities) So after messing with it for several hours, I managed to correct the code, well to execute as intended with the desired result. Not by writing code or anything, don't have the knowledge (not enough time to learn really, and yes, it is rather essential, but tell it to my boss). Below is the entire cron job php code, for use with a csv file consisting of two columns: 'reference' and 'quantity'. The code resets all the quantities in the DB to zero first, and then updates the DB with the quantities from the DB. Of course, the csv needs to be uploaded to the defined location, we use Auto FTP Manager for that. So, if you get a daily csv file with product quantities from your supplier, this would be the way to have 'live' stock information on your site (depending on the frequency with which you receive the information from your supplier(s)). <?php // PRESTASHOP SETTINGS FILE require_once ('../config/settings.inc.php'); // REMOTE CSV FILE (CUSTOMIZE YOURCSVFILEPATH, CAN BE AN URL OR A LOCAL PATH) $remote_csv_file = '../upload/stock/XXXXXX.csv'; //MY PATH; CHANGE TO YOUR NEED, SAME FOR THE FILE NAME // DB CONNECTION (CUSTOMIZE YOURDBHOSTNAME AND YOURDBPORT) $db = new PDO("mysql:host=localhost;port=3306;dbname="._DB_NAME_."", _DB_USER_, _DB_PASSWD_); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); set_time_limit(600); // RESET CYCLE //START $default_qta = 0; $updateAll = $db->prepare("update "._DB_PREFIX_."product SET quantity = :default_qta"); $updateAll->execute(array(':default_qta'=>$default_qta)); $updateAll = $db->prepare("update "._DB_PREFIX_."product_attribute SET quantity = :default_qta"); $updateAll->execute(array(':default_qta'=>$default_qta)); $updateAll = $db->prepare("update "._DB_PREFIX_."stock_available SET quantity = :default_qta"); $updateAll->execute(array(':default_qta'=>$default_qta)); // END // MAIN CYCLE $row_num = 0; if (($handle = fopen($remote_csv_file, "r")) !== false) { while (($data = fgetcsv($handle, 1000, ",")) !== false) { $row_num++; if ($row_num == 1) { // SKIP FIRST LINE (HEADER) continue; } if ($data[0] == '' || !is_numeric($data[1])) { // SKIP EMPTY VALUES continue; } // INPUT SANITIZATION //$reference =':reference'; //$quantity =':quantity'; $reference = trim($data[0]); $quantity = ($data[1] >= 0) ? $data[1] : 0; try { $res4 = $db->prepare("SELECT id_product, id_product_attribute from "._DB_PREFIX_."product_attribute WHERE reference = :reference"); $res4->execute(array(':reference'=>$reference)); if ($res4->rowCount() > 0) { // IT'S A PRODUCT COMBINATION $row4 = $res4->fetch(); $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 reference = :reference"); $res4->execute(array(':reference'=>$reference)); 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'])); } } } catch (PDOException $e) { echo 'Sql Error: '. $e->getMessage() .'<br /><br />'; } } fclose($handle); } ?> It's impossible for me to take real credit for this, since I can't code, if it hadn't been for the original solution and comments here I would still be stuck
  11. I hate to bump, but BUMP. Does anyone have any ideas, thoughts or suggestions? Our new site has gone from developing to production two days ago, and today I looked into this issue again. The stock movements from our order system, are dumped into a csv file, this file is automatically uploaded to the website, and a cron job runs to update the stock levels on the site. As mentioned previously, that all works flawlessly, the issue is still the random stock amounts. The original source has some comments about issues with combinations, and that the quantities need to be set to zero first. AT line 26 //START $default_qta = 0; $updateAll = $db->prepare(“UPDATE “._DB_PREFIX_.”product SET quantity = :default_qta”); $updateAll->execute(array(‘:default_qta’=>$default_qta)); $updateAll = $db->prepare(“UPDATE “._DB_PREFIX_.”product_attribute SET quantity = :default_qta”); $updateAll->execute(array(‘:default_qta’=>$default_qta)); $updateAll = $db->prepare(“UPDATE “._DB_PREFIX_.”stock_available SET quantity = :default_qta”); $updateAll->execute(array(‘:default_qta’=>$default_qta)); // END That code has not worked for me, yet, I'm now considering setting up a separate cron job to reset the quantities to zero (with the above code) and then have the original cron run to update the stock levels. If anyone has any suggestions while I'm testing, please don't hold back
  12. Would this work to hide a cms category? I've tried it with the following: {if $smarty.get.id_cms_category==4} {if $logged} {$cms->content} {else} {l s='access forbidden, please log in first to view this page'} {/if} {else} {$cms->content} {/if} However, I have not yet managed to get it to work, basically, nothing happens, nothing gets 'hidden/blocked'. Individual pages work fine. Any suggestions, would it be possible to use this code to block multiple pages? If so, how? I really need to properly start learning php
  13. I know it's a bit of an old topic to kick back into life, but what changes do I need to make to this solution to make it work on 1.6.1.1? Currently I'm working on a new website for our trade customers and I need to add certain files for download (trade price list, image, other information that we don't want to release to consumers) which can only be visible to customers, and I'll be the one creating the accounts. Right now, if I implement the solution as posted by Vekia, the [spam-filter] himself, I get the following error: Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "C:\xampp\htdocs\prestashop\themes\theme1133\cms.tpl" on line 70 "{else}" unclosed {else} tag <-- thrown in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 70 When I check that line it is a commented out or blank line. If I remove the {else} at the end of the posted solution, it throws a variation of the error, claiming there's an unclosed {if} tag. So add another {/if} and the page loads again as normal, but with errors displayed on the page (cms category page): Notice: Undefined index: cms in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d codeon line 124 Notice: Trying to get property of non-object in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 124 Notice: Trying to get property of non-object in C:\xampp\htdocs\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code on line 124 ] When I click the actual page (CMS ID 10), I can actually proceed to the page, even though I'm a visitor, i.e. not logged in. Can someone help me out?
  14. I'm trying to adapt this solution to my needs (allow access to several CMS pages to visitors, all others need login first), however, I don't even get that far. When I put in the override and remove class_index.php I get a 'Fatal error: Allowed memory size of "X" (tried to allocate "X" bytes) exhausted' on line XXX' Could this be because it is a local installation on XAMPP (PHP.ini has a memory limit of 128M) or could it have something to do with the actual override?
×
×
  • Create New...