Jump to content

thijsvk

Members
  • Posts

    43
  • Joined

  • Last visited

Community Answers

  1. thijsvk's post in [Solved] Automatic Stock Update (Csv) Solution was marked as the answer   
    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
  2. thijsvk's post in [SOLVED] Category Content dissapeared after upgrading Layered Navigation to V2.0.13 was marked as the answer   
    Seems that part of the problem is the need to grant your MySQL user the 'Create Temporary Tables' privilege.
    I've had my host add the privilege and at least now the products are displayed again. The next/new issue is that the filters are not displayed.
     
    https://www.prestashop.com/forums/topic/453373-layered-navigation-disappears-in-front-end/
     
    Edit:
    It appears that the filters are back, however, they are all the way at the bottom in the left hand column, so present but 'invisible'.
    The hunt goes on!
     
    Edit II:
    Go to positions > Run Live Edit > move the module up to where I want it.
    IT WORKS!!!
  3. thijsvk's post in Url 2nd domain (redirected) does not display breadcrumb path. was marked as the answer   
    I seem to have managed to fix it.
    The parking and redirect are fine, but I needed to map the second domain to the primary in the CP of my hosting provider.
    Now everything is fine. Hopefully this helps others
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More