I'm trying to update the price of all products in a catalog of over 10,000 products. I make an API call to the vendor and receive an XML document back that contains all of the products and correct prices. I parse the XML and then use the SKU to identify the product in Magento and then update. I'm running into problems with memory limit errors.
I'm trying the following code, which is very fast, except it isn't actually saving the price update. Can anyone help me out here?
$sku = $xml->sku;//parsed from the vendor's API response
$product = Mage::getModel('catalog/product');
$id = $product->getIdBySku($sku);
if(!$id):
// Don't create any new products.
else:
// Update it if it already exists
try {
$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes($id, array(
'price' => $price
), 1);
}
catch (Exception $ex) {
printf($ex->getLine() . ": " . $ex->getMessage() . "\n");
}
return;
endif;
Any suggestions are most appreciated. I'm running this via command line and intend for it to run via cron on a nightly basis.
========
UPDATE:
I did the below, and now it works, but I have no idea why. The only change I made was the following:
$update = $action->updateAttributes($id, array(
'price' => $price
), 1);
Why would this even matter? What else could have caused this?
0 comments:
Post a Comment