PrestaShop Forums: [[SOLVED]]Automatic update product quantities - PrestaShop Forums

Jump to content


Welcome to the PrestaShop Forum! We hope you'll share your comments and suggestions with us. We ask that you please post in English to the main sections of the PrestaShop Forum. If you want to write in another language, please post in the corresponding PrestaShop Community section below.

Please note that PrestaShop Community sections are largely self-moderated. PrestaShop team members may or may not participate in non-English sections. To improve the chances of receiving feedback to your question or comment, please post it in English to the main sections of our Forum.

NYC

Vous parlez français ? par ici !


[[SOLVED]]Automatic update product quantities


[[SOLVED]]Automatic update product quantities

#1 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 27 May 2009 - 03:13 PM

Hi again,

I'm newbie with prestashop, i've created new products with variation (sizes), each size of products have different EAN and different quantities. How can i update that quantities from one external php file protected by password?

I want something like cronjob to do the task and keep my available quantities updated.

The external php file (from other store) have on first collum the EAN of related size, on second collum (dont need to connect) have the name of product and 3rd collum have the available quantites...

Is that possible to do? Maybe one script like other shopping carts uses to update currencies... I dont know...

Can someone help me?

Thanls thanks thanks...
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#2 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 27 May 2009 - 03:30 PM

Welcome to the club.

Theres a lot of people needing some kind of module that can do update of products prices, quantities and availability but so far nothing can do that.

If you figure out how to do that please share with us.

#3 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 27 May 2009 - 03:36 PM

I'll try to change one php script to update currencies on zen cart, but i need to know exactly how is the function of products variations in db of presta.

Thanks... If i solve this i share it
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#4 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 27 May 2009 - 07:44 PM

From 1243434625:

Welcome to the club.

Theres a lot of people needing some kind of module that can do update of products prices, quantities and availability but so far nothing can do that.

If you figure out how to do that please share with us.


Hi, the problem of quantities update is solved...

I can share it but i'm new here...

I dont know how to share it....

Is a basic script but maybe can help someone...
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#5 San Diego

    PrestaShop Apprentice

  • 15 Apr 2009
  • Members
  • PipPip
  • 407 posts

Posted 27 May 2009 - 08:25 PM

hi
welcome too
just post it right here and mark your threat as solved
just attach the files you changed
thanks for sharing

sd

#6 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 27 May 2009 - 08:59 PM

Great news mate, can you perhaps expand it to update price and availability?

#7 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 27 May 2009 - 09:15 PM

yes

is it possible if you have all the data in the same csv
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#8 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 27 May 2009 - 09:40 PM

I do have all in one file.
Mate, you are a life saver if you can manage that to work!

#9 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 27 May 2009 - 09:49 PM

Hi,

Here is the solution. PLEASE BACKUP YOUR DATABASE FIRST. I'VE FINISHED IT TODAY, I TRY AND IT WORKS, BUT IT COULD BE A PROBLEM.

Follow the steps you will find in php file.

Best regards...

I'm waiting for your replay

Attached File(s)


Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#10 San Diego

    PrestaShop Apprentice

  • 15 Apr 2009
  • Members
  • PipPip
  • 407 posts

Posted 27 May 2009 - 09:53 PM

thanks for sharing
i don´t need it right now
will give it a try soon i get time

sd

#11 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 28 May 2009 - 08:34 AM

Hi,

One update to the file, on line 44, you can change the "," to ";" if your csv use other type of separator...
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#12 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 28 May 2009 - 10:05 AM

Hi, Im just testing this and im having some problems... :(
Can you post sample row of your csv just to see how to format it? becouse currently i use complete CSV with all 30 columns.

#13 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 28 May 2009 - 10:18 AM

Excellent, iw figured it out!

This ROCKS!!! man i love you! (not as the man loves the woman, but friendly kind of love) ;-)

This solution shud go to sticky!!!!!

#14 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 28 May 2009 - 10:21 AM

remember that you can use all variables rou want in the some formar and order of table you are updating. Ex.:

reference - supplier_reference - location - ean13 - wholesale_price - price (...)

your csv must have this fields or not, but with the some order.

You can only update one table. In this case is the table of product_attribute.

You have to change as well the line 44 to the symbol that separate each collum of csv, set it in php file like: , or ; (..)

In my csv i just have 2 fileds ean13 and quantity (in this order)

Hope can help you, best regards.
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#15 mozack

    PrestaShop Apprentice

  • 25 May 2009
  • Members
  • PipPip
  • 215 posts
  • Location:Agueda - Portugal

Posted 28 May 2009 - 10:22 AM

Problem solved....

Thanks.
Biquini Moda Praia - http://www.biquinimodapraia.com.br
Biquini Moda Praia Blog - http://www.biquinimo...og-loja-online/
Bikini Perfeito - http://www.bikiniperfeito.com
Bikinis Brasileiros Online - http://www.bikinisbr...eirosonline.com
4everus.net - http://www.4everus.net - Social Life
Mozack Blog - http://www.mozack.net

#16 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 28 May 2009 - 11:12 PM

Managed to add script to cron job and its perfect.

Im posting this peace of code (that was killin me for hours untill iw get it right) to save others some else a time and headache.

/usr/bin/php /home/username/folder/script.php

cheers!

#17 erdesignerz

    PrestaShop Apprentice

  • 04 Apr 2008
  • Members
  • PipPip
  • 76 posts
  • Location:New York

Posted 13 June 2009 - 01:39 PM

good module

#18 VIXUS

    PrestaShop Addict

  • 24 Jan 2009
  • Members
  • PipPipPip
  • 576 posts

Posted 15 July 2009 - 05:43 PM

file update.php

<?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.
// update.php
//
// To run open in your browser.
// Example: http://www.mysite.com/secure_folder/update.php
//
// 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", "here goes your login", "here goes your password") or die(mysql_error());
mysql_select_db("heregoes your database name") or die(mysql_error());

// If first row of csv file is headings set $row to 1.
$row = 0;
// TABLE OF PRODUCTS AND VARIATIONS - IN PRESTASHOP IS PREFIX_product_attribute
$update_table = "ps_product";

// Get the csv file - INSERT THE ADDRESS OF CSV FILE OR UPLOAD IT TO THE SOME FOLDER OF THIS SCRIPT
$handle = fopen("update.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 $reference, $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 = count($data);
echo "n";
echo "( $row )n";
$row++;
for ($c=0; $c < $num; $c++) {
if ($c = 1) {
$reference = $data[($c - 1)];
echo $reference . " - Reference Assignedn";
}
if ($c = 2) {
$price = $data[($c - 1)];
mysql_query("UPDATE $update_table SET price='$price' WHERE reference='$reference'")
or die(mysql_error());
echo $price . " - Price updatedn";
}
if ($c = 3) {
$quantity = $data[($c - 1)];
mysql_query("UPDATE $update_table SET quantity='$quantity' WHERE reference='$reference'")
or die(mysql_error());
echo $quantity . " - Quantity updatedn";
}
if ($c = 4) {
$active = $data[($c - 1)];
mysql_query("UPDATE $update_table SET active='$active' WHERE reference='$reference'")
or die(mysql_error());
echo $active . " - Activity updatedn";
echo "_____________________________________________________n";
}

// ADD ADITIONAL IF STATEMENTS FOR EACH FIELD YOU WANT UPDATE IN THE SOME ORDER OF YOUR CSV FILE
}
}

fclose($handle);
echo " n";
echo " - - - SUCESSFULY COMPLETED - - - ";
?>



NOTICE, code does not report any mistakes (eg. not found reference) so if anyone knows how to improve this code please share here...
file update.csv

(columns in excel) reference, price, quantity, activity


PCDE-OP360MTE2200 8.853,000000 100 1
PCDE-OP360MTE2500 8.853,000000 100 1
PCDE-OP360MTE5300 132,000000 600 1
PCDE-OP360MTE7400 4.755,000000 600 1
PCDE-OP360MTE2240 8.853,000000 605 1


#19 babysoros

    PrestaShop Newbie

  • 18 May 2009
  • Members
  • Pip
  • 7 posts

Posted 31 July 2009 - 03:43 AM

hello i am new in here can u explain how to use this file? i am already use csv dan they said
1 fields to update in line 0:
1;"1";"1";"1";"1";"1" EAN13 Assigned
Undefined offset: 1 in C:\wamp\www\prestashop\Protected_folder\quantity_update.php on line 54
Table 'bla bla bla ' doesn't exist

how can i know what is my table?

#20 wallacept

    PrestaShop Apprentice

  • 31 Mar 2009
  • Members
  • PipPip
  • 170 posts

Posted 11 August 2009 - 10:46 AM

where put file update.php?

this file update catalog with import csv, okay?

no apply in store.
have a problem.

see screenshot.

Attached File(s)

  • Attached File  screen.png (49bytes)
    Number of downloads: 2493

CCampea Store- http://www.ccampea.com/lojacc - Store online motos, bikes, helmets

CCampea Twitter- http://twitter.com/ccampealoja

CCampea Facebook - CCampea Facebook - Store Online Motos, Bikes and Accessories

CCampea ThisNext - CCampea This





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users