Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Change SKU
 
neuro
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-09-29
France
 

Hi,
It is possible to change the field sku with an export/importation with dataflow? I would like to replace the current sku by bar codes and to put the current sku in an attribute.

A small help would be very appreciated, thx ;)

French translation:
Serait-il possible de mettre à la place de mes SKU actuels des codes à barre et stocker ces SKU dans un attribut?

Thx too :)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Is this to integrate to a POS?

Consider:

Adding an attribute to the product type

copying the skus to the new attribute in sql

updating the sku entries in catalog_product_entity, again in sql.

You can backup the individual tables if you are scared…

 
Magento Community Magento Community
Magento Community
Magento Community
 
neuro
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-09-29
France
 

Really thx smile
I’ll make a php script my own for copy & update all this.
I just was so tired yesterday but cheers wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
neuro
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2008-09-29
France
 

Yes we have a POS (point of sales I suppose) & will manage our stocks too with bar code tools.
We try to replace our actually e-commerce solution with Magento (approx 500 sales per day) so we need to manage our stocks with POS tools.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mediagang
Sr. Member
 
Avatar
Total Posts:  111
Joined:  2008-01-16
Leeds UK
 

I needed to change my SKU codes.  I couldn’t find a way of doing this using the DataFlow. Instead ran a SQL script as mentioned above.  This worked but do back up first!

 
Magento Community Magento Community
Magento Community
Magento Community
 
elitriona
Sr. Member
 
Total Posts:  106
Joined:  2008-10-23
 

Is there anyone who could explain how they did this? What the sql script is and/or what tables are involved?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Here you go - this takes a csv file where each line has an old SKU followed by a comma (,) and a new SKU. The API is used to take each old/new pair and update accordingly. However, you are going to have to amend this script to suit your SKU codes. This script is specific to a shop where the SKU is made up of a product ID followed by a dash, the size code, another dash and then a colour code. The old/new pairings expected by this script are just the product ID’s, it then updates all of the products with a matching XXXX-SIZE-COLOUR pattern, matching the XXXX for all of them. Hence, the format of your .csv file is:

XXXX1, YYYY1
XXXX2, YYYY2
...
XXXXN, YYYYN

After you have adapted the code to your purpose I suggest making a DB backup and running a test on a couple of SKU’s. It can take a minute or two to be able to search for the new codes in the backend, Magento is slow sometimes, particularly with the API.
You will also need to put in values for your API connector, hostname, user and pass. You may also need to change where the sku_update.csv file goes.
Place the script out of harms way in you user directory, and not in www docroot. Run it with the command line flavour of PHP with:
php sku_update.php > test.txt
Check the output and if you want more verbose info on products uncomment the var_dump line.
If all works as planned then run it with the full list of required changes, overnight as it can take a while.

<?php
// sku_update.php
// 17 September 2009

// Takes /var/www/html/api/sku_update.csv and updates sku codes accordingly
// File is comma separated with old pid followed by new pid

$host'yourshop.co.uk';
$client= new SoapClient('http://'.$host.'/index.php/api/soap/?wsdl');

// Can be added in Magento-Admin -> Web Services with role set to admin
$apiuser'APIUSER';
$apikey 'APIPASS';

// Login to SOAP API with the above credentials
$sess_id$client->login($apiuser$apikey);

$updates_file="/var/www/html/api/sku_update.csv";
$sku_entry=array();
$sku_from=array();
$updates_handle=fopen($updates_file'r');
if(
$updates_handle)
while($sku_entry=fgetcsv($updates_handle1000","))
  
{ $old_sku=$sku_entry[0];
    
$new_sku=$sku_entry[1];
    echo 
"Updating ".$old_sku." to ".$new_sku."\n\n";
    try
    
{ $filters = array('sku' => array('like'=>'%'.$old_sku.'%'));
      
$matching_skus=$client->call($sess_id'product.list', array($filters));
      foreach(
$matching_skus as $matching_sku)
      
//var_dump($matching_sku);
        
$sku_from=explode("-",$matching_sku['sku']);
        
$sku_to=$new_sku."-".$sku_from[1]."-".$sku_from[2];
        echo 
"SKU: ".$matching_sku['sku']." -> ".$sku_to."\n";
        try
        
{ $do_it=$client->call($sess_id'product.update', array($matching_sku['sku'], array('sku'=>$sku_to)));
          
sleep(10);
        
}
        
catch (Exception $e)
        
echo "WSDL call failed!\n";
          return;
        
}
      }
    }
    
catch (Exception $e)
    
echo "Cannot retrieve products from Magento\n".$e."\n\n";
      return;
    
}
  }
  fclose
($updates_handle);
}
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
elitriona
Sr. Member
 
Total Posts:  106
Joined:  2008-10-23
 

THANK YOU!!! Very helpful smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

I posted the above in a wiki article, update it with whatever you end up with:

http://www.magentocommerce.com/wiki/howto/update_skus_with_dataflow_en-masse_from_a_.csv_file

 
Magento Community Magento Community
Magento Community
Magento Community
 
fanta00
Jr. Member
 
Total Posts:  28
Joined:  2009-11-23
 

Great , exactly what I was looking for,

but I’m stuck on “Run it with the command line flavour of PHP with: php sku_update.php > test.txt”.... Where do I run it?  should I look for something to run command line in my server control panel? How it will be named?

 
Magento Community Magento Community
Magento Community
Magento Community
 
fanta00
Jr. Member
 
Total Posts:  28
Joined:  2009-11-23
 

Ok, I’ve sorted out the command line, but I have problem with the php file itself. As I am not PHP Guru I don’t know how to edit the code for my needs, if I just want to update the SKU into the new SKU like for example :
old SKU : 125
new SKU: 500AS

Which line should I edit in this code? It actually works for me but just with the first entry in csv file, the of the skus are ignored. How to make a loop or sth like that in this code?

Many thanks for any help

 
Magento Community Magento Community
Magento Community
Magento Community
 
mhunkler
Guru
 
Total Posts:  304
Joined:  2009-05-30
 

Sorry but i just don’t understand this guide at all… How can I change this to just update sku’s however i want… just a simple xyz to 123, nothing to do with attributes or anything… and where do you run it, in SSH?  Thanks in advance, and for your hard work

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top