I want to create a CRON job which updates my Magento products Inventory by matching sku
and product name
with the third party products inventory. third party is using Sql server
and my Magento project is on MySql
.
1 Answer
you have to write a webservice which will get pass sku and get the qty for that product and use following code to update $qty at magento product.
The following code uses magento soap api to update qty of the product
<?php $client = new SoapClient('http://www.yourdomain.com/index.php/api/v2_soap?wsdl=1');
$session = $client->login($soapusername,$soappassword); // soap user name and password
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('product_category_id',4)->addFieldToFilter('attribute_set_id', $attributeSetId);
foreach($products as $product)
{
$quantity = write a funtion which will take the sku of the product and get the qty of that product
$qty = array();
if($qty > 0 ){
$qty['qty'] = $quantity;
$qty['is_in_stock'] = 1;
}else{
$qty['qty'] = 0;
$qty['is_in_stock'] = 0;
}
$client->catalogInventoryStockItemUpdate($session,$product->getSku(),$qty);
}
?>
Note:- write the above code in cron.this is the code which will update stock of product in magento