I'm using Magento CE 1.9.1
I made an import script to import products from a provider xml feed.
This feed is update everyday at 3 a.m .
My profider send me in his xml only products where are in stock in his shop.
So how can I update my product stock statut to out of stock (by product sku) when the product sku doesn't exist in the xml feed ?
I put an example to explain what I want, data provided in the xml :
Monday : Tuesday :
Sku qty Sku qty
ABC 22 ABC 12
BDE 30 FGH 4
FGH 15
What I have to do : Tuesday I have to set programmatically my product BDE to "out of stock" because it doesn't appear in the xml.
There is my import script :
$file = 'feed.xml';
$feed = simplexml_load_file($file);
foreach($feed as $product){
//some datas in xml feed
$sku = $product->identifiant_unique;
$prix = $product->prix;
$titre = $product->categorie3;
$quantiteStock = $product->quantiteStock;
$poid = $product->poids_net;
//Setters
$produit = Mage::getModel('catalog/product');
$produit->setName($titre.' '.$sku);
$produit->setSku($sku);
$produit->setWeight($poid);
$produit->setAttributeSetId(4);
$produit->setDescription($titre.' '.$sku);
$produit->setShortDescription($titre.' '.$sku);
$produit->setTypeId($product['type_id'])->setWebsiteIds(array(1))->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$produit->setPrice($prix);
$produit->setIsMassupdate(true);
$produit->setExcludeUrlRewrite(true);
$produit->save();
// For Inventory Management
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($produit);
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('stock_id', 1);
$stockItem->setData('store_id', 1);
$stockItem->setData('manage_stock', 1);
$stockItem->setData('use_config_manage_stock', 0);
$stockItem->setData('min_sale_qty', 1);
$stockItem->setData('use_config_min_sale_qty', 0);
$stockItem->setData('max_sale_qty', 1000);
$stockItem->setData('use_config_max_sale_qty', 0);
$stockItem->setData('qty', $quantiteStock);
$stockItem->save();
}
Thanks