Jump to content

bulk Upgrade quantity in product combination


stefano7
 Share

Recommended Posts

Hi,

sorry for my english :)

i need to ugrade quantity combination.

I use this in mysql with csv file and it work's for me:

 

but:

- with this file prestashop doesn't change total quantity of the product but only the single combination.

- there is another simple way to bulk upgrade quantity of combination in mysql or not?

 

 

<?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.
// quantity_update.php
//
// To run open in your browser.
//
// 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", "stanem_pres678", "92S.7G56P.") or die(mysql_error()); 
mysql_select_db("stanem_pres678") or die(mysql_error()); 
 
// If first row of csv file is headings set $row to 1. 
$row = 1; 
// TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute 
$update_table = "ps_stock_available"; 
 
// Get the csv file - INSERT THE ADDRESS OF CSV FILE OR UPLOAD IT TO THE SOME FOLDER OF THIS SCRIPT
$handle = fopen("http://shop.stanem.it/csv/INVENTARIO.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 $ean13, $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 = $c=2; 
    echo "<p> $num fields to update in line $row: <br /></p>\n"; 
    $row++; 
    for ($c=0; $c < $num; $c++) { 
        if ($c = 1) { 
        $idpa = $data[($c - 1)]; 
        echo $idpa . " ID Assigned <br />\n"; 
        }         
        if ($c = 2) { 
        $quantity = $data[($c - 1)]; 
        mysql_query("UPDATE $update_table SET quantity='$quantity' WHERE id_product_attribute = '$idpa'")  
        or die(mysql_error());  
        echo $product_quantity . " Imported to <b>$row</b> in product <b>$ID</b> <br />\n"; 
        } 
 
 
        // ADD ADITIONAL IF STATEMENTS FOR EACH FIELD YOU WANT UPDATE IN THE SOME ORDER OF YOUR CSV FILE 
    } 
 
fclose($handle); 
echo "<h1>COMPLETED.</h1>"; 
?> 
Edited by stefano7 (see edit history)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

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