PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

[[SOLVED]]Automatic update product quantities

58 replies to this topic
#1
mozack

    PrestaShop Apprentice

  • Members
  • PipPip
  • 215 posts
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

  • Members
  • PipPipPip
  • 583 posts
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

  • Members
  • PipPip
  • 215 posts
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

  • Members
  • PipPip
  • 215 posts

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

  • Members
  • PipPip
  • 407 posts
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

  • Members
  • PipPipPip
  • 583 posts
Great news mate, can you perhaps expand it to update price and availability?

#7
mozack

    PrestaShop Apprentice

  • Members
  • PipPip
  • 215 posts
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

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

#9
mozack

    PrestaShop Apprentice

  • Members
  • PipPip
  • 215 posts
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 Files


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

  • Members
  • PipPip
  • 407 posts
thanks for sharing
i don´t need it right now
will give it a try soon i get time

sd

#11
mozack

    PrestaShop Apprentice

  • Members
  • PipPip
  • 215 posts
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

  • Members
  • PipPipPip
  • 583 posts
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

  • Members
  • PipPipPip
  • 583 posts
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

  • Members
  • PipPip
  • 215 posts
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

  • Members
  • PipPip
  • 215 posts
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

  • Members
  • PipPipPip
  • 583 posts
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

  • Members
  • PipPip
  • 76 posts
good module

#18
VIXUS

    PrestaShop Addict

  • Members
  • PipPipPip
  • 583 posts
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 Assigned\n";
}
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 updated\n";
}
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 updated\n";
}
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 updated\n";
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

  • Members
  • Pip
  • 7 posts
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

  • Members
  • PipPip
  • 170 posts
where put file update.php?

this file update catalog with import csv, okay?

no apply in store.
have a problem.

see screenshot.

Attached Files


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