For 45.000+ products I want to update a specific date attribute.
I use this custom attribute "new_stock", that all needs the value of "01-01-2000".
How can I easily update this attribute for all these products?
I tried this code, inside a custom .php file and run it by browser.
But that did not work
<?php
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id', array('in' => $productIds));
foreach($products as $product)
{
$product->setNewStock('2000-01-01');
// below code use for time format
$product->setNewStockIsFormated(true);
$product->getResource()->saveAttribute($product, 'new_stock');
}?>
load()
at the start of your foreach loop. You already have the$product
that you need, and$id
is unset anyway, so just remove that whole line. Also try changingsetSpecialFromDateIsFormated
tosetNewStockIsFormated
(though you might not need this line at all, actually).$productIds
array or theaddAttributeToFilter
option. For all products, just use$products = Mage::getModel('catalog/product')->getCollection()