1

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?

  • Thanks for Mage::getModel('core/date')->gmtDate() use not use Varien_Date::now() – Dinuka Thilanga Mar 17 '17 at 10:06
1

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:

$id = 43453;

$product = Mage::getModel('catalog/product')->load($id);
$product->setUpdatedAt(Mage::getModel('core/date')->gmtDate());
$product->save();

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.

  • Ah! I'm so stupid!) I was trying to save my product from test script without setting admin store as current: Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); – esigns Jun 16 '16 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.