I need to change the updated_at
column value for product using it's id.
I've already tried next pieces of code:
$productIds = [26957];
$m = Mage::getSingleton('catalog/product_action');
$m->updateAttributes(
$productIds,
array('updated_at' => Varien_Date::now()),
0
);
Result:
"Fatal error: Uncaught Exception: Notice: Undefined index: value in app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1495"
And this one:
$productIds = [26957];
foreach($productIds as $id) {
$product = Mage::getModel('catalog/product')->load($id);
$product->setUpdatedAt(Mage::getModel('core/date')->gmtDate());
$product->save();
}
Result:
"Fatal error: Uncaught Exception: Warning: Invalid argument supplied for foreach() in app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1180"
And this:
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('id', array('in' => array(26957)));
while ($product = $_products->fetchItem()) {
$product->setUpdatedAt(Mage::getModel('core/date')->gmtDate());
$product->save();
}
And the result is:
Fatal error: Uncaught Mage_Core_Exception: Product ean is required in app/Mage.php on line 594
How can I do that?
Best Answer
First method - I can't help you, actually I have'n used such a model to anything.
In second piece of code, error is connected with
$productsIds
as argument of foreach loop. You can try to write the Ids in different way for example$productIds = array(3344)
; Although I suppose, this one should work, if you have just one product to update:If piece
Mage::getModel('core/date')->gmtDate()
returns correct date (can't check it now),Third method - I am not sure if collection has method save.