I am migrating a custom e-commerce site over to Magento. We have well over a hundred thousand products. Many are drop shipped from a number of suppliers. Several suppliers can provide the same product. Naturally they will all have different stock and provide different pricing. We have a custom script that parses all the feeds from all the suppliers and create a single feed that contains the new stock and pricing for all the products. With this volume we couldn't use Magento to import the changes. Thus we are using Magmi. Unfortunately Magmi, from what I can tell, will not zero out the stock if an item isn't in the feed. I could just import the products into another table and do a SQL call to set stock = 0 where the products are not in the new table then run magmi against with the feed file.
Magento – Best way to bulk update stock and price for thousands of products
import
Related Solutions
I don't know if this helps you much, but I did something like this using a custom script like this.
In my case I had to read the values from a CSV file, but anything goes as long as you are able to get your data into an array that looks like this:
$values = array(
array(
'value'=>'Some value',
'position'=>'3'
),
....
);
I also did this for the manufacturer
attribute but it works for any other attribute. Let's assume you have the array in the form described above. Here goes:
$manufacturer = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer'); //get the main attribute
$storeViews = Mage::getModel('core/store')->getCollection()->addFieldToFilter('store_id', array('gt'=>0)); //get all stores
$ids = $storeViews->getAllIds();//get all store ids
$saveOptions = array();//init options to save
if ($manufacturer){
$_options = $manufacturer->getSource()->getAllOptions(false);//get all existing options so you won't add duplicates
$options = array();
foreach ($_options as $_option){ //format the existing options for save
$options[$_option['label']] = $_option['value'];
}
}
//read from the array to import $values
foreach ($values as $value){
if (!isset($options[$name])){//check if the option does not exist
$index = 'option_'.(count($toInsert) + 1);
$toInsert[$index] = array();//if it doesn't exist add it to import array
$toInsert[$index][0] = $value['value'];//set the option label for admin view
foreach ($ids as $store){
//empty values for stores - you can also set translated values if you need for each store
$toInsert[$index][$store] = '';
}
$toInsertOrder[$index] = $value['position'];//set the option position
}
}
Now you should have in the array $toInsert
the labels that need to be added, and in $toInsertOrder
the positions of the labels. just set the options to the attribute and save it.
$result = array('value' => $toInsert,'order' => $toInsertOrder);
$manufacturer->setData('option', $result);
$manufacturer->save();
You can create one table in your database with all the product entry in it.
After update on Monday structure of DB.
sku qty created_at flag
ABC 22 date("Y-m-d H:i:s") 0
BDE 13 date("Y-m-d H:i:s") 0
FGH 15 date("Y-m-d H:i:s") 0
On Tuesday set flag to 1 for the available sku. So after that on Tuesday structure of DB.
sku qty created_at flag
ABC 12 date("Y-m-d H:i:s") 1
BDE 13 date("Y-m-d H:i:s") 0
FGH 4 date("Y-m-d H:i:s") 1
retrieve all the sku with the flag=0 and set their 'is_in_stock' to 0. after that update you table with the available sku on tuesday and set their flag to 0 for nextday.
After update on Tuesday structure of DB.
sku qty created_at flag
ABC 12 date("Y-m-d H:i:s") 0
BDE 13 date("Y-m-d H:i:s") 0 (You can remove old entry as per you logic)
FGH 04 date("Y-m-d H:i:s") 0
Best Answer
First idea: If your only problem is to set all the products to 0 before the import, why don't you do it?
I'm not sure, wether this is a good idea, and wether there are side effects, but importing is often a dirty job, so a SQL before the import might solve the problem.
This means, for the time of the import you don't have any products.
Second idea: If this is a problem, you can think about, building a proxy for the feed, fetching all the products from the shop and add the missing products