How to use a Magento 1 model to update multiple rows?Update magento attribute field based on value from a 'custom' tableHow do I Create one Magento Product with 40 different types of Fabrics to choose from?Managing Multiple Magento StoresProgramatically update customer address by its entity idHow To Fetch And Display Last 4 Table Rows?how to add customer attribute with default values set for all existing entities?How to use SQL in Magento modulesMagento, I only need one data in databaseGetting current request page sizeHow can I use partial (code block) in multiple templates?
How can I be pwned if I'm not registered on the compromised site?
Are Wave equations equivalent to Maxwell equations in free space?
Integrating function with /; in its definition
Replacing tantalum capacitor with ceramic capacitor for Op Amps
Professor forcing me to attend a conference
What is Tony Stark injecting into himself in Iron Man 3?
I can't die. Who am I?
Where is the fallacy here?
Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?
Why aren't there more gauls like Obelix?
Affine transformation of circular arc in 3D
Is divide-by-zero a security vulnerability?
Paper published similar to PhD thesis
Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?
What does it mean when I add a new variable to my linear model and the R^2 stays the same?
What's the best tool for cutting holes into duct work?
Quitting employee has privileged access to critical information
How do you make a gun that shoots melee weapons and/or swords?
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
Using the imperfect indicative vs. subjunctive with si
The (Easy) Road to Code
Why won't the strings command stop?
If nine coins are tossed, what is the probability that the number of heads is even?
How to make sure I'm assertive enough in contact with subordinates?
How to use a Magento 1 model to update multiple rows?
Update magento attribute field based on value from a 'custom' tableHow do I Create one Magento Product with 40 different types of Fabrics to choose from?Managing Multiple Magento StoresProgramatically update customer address by its entity idHow To Fetch And Display Last 4 Table Rows?how to add customer attribute with default values set for all existing entities?How to use SQL in Magento modulesMagento, I only need one data in databaseGetting current request page sizeHow can I use partial (code block) in multiple templates?
I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:
update
my_table
set
processed_on = "2015-09-09 11:11:04"
where
id in(34, 56, 77, 39)
magento-1.9 model
add a comment |
I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:
update
my_table
set
processed_on = "2015-09-09 11:11:04"
where
id in(34, 56, 77, 39)
magento-1.9 model
add a comment |
I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:
update
my_table
set
processed_on = "2015-09-09 11:11:04"
where
id in(34, 56, 77, 39)
magento-1.9 model
I am processing some records and I need to set a datetime field to the current time for multiple rows. I have all the row IDs. What's the best way to do this with Magento 1? The SQL would be like this:
update
my_table
set
processed_on = "2015-09-09 11:11:04"
where
id in(34, 56, 77, 39)
magento-1.9 model
magento-1.9 model
edited 7 hours ago
Ryan
asked yesterday
RyanRyan
1337
1337
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.
An example would look like this:
$rowIds = array(1,2,3)
foreach($rowIds as $rowId)
$data = array('processed_on' => "2015-09-09 11:11:04");
$model = Mage::getModel('your_model')->load($rowId)->addData($data);
try
$model->setId($rowId)->save();
echo "Record updated";
catch (Exception $e)
echo $e->getMessage();
You should removesetId($id)
before callingsave()
since$id
is not defined and the model has already an id, because it is an existent record.
– HelgeB
yesterday
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(array(1,2,3));
foreach ($collection as $product)
$product->setProcessedOn('2015-09-09 11:11:04');
# add this to avoid pricerule update
$product->setIsMassupdate(true);
$collection->save();
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getModel('your/model')->getCollection()
->addIdFilter(array(1,2,3));
foreach ($collection as $item)
$item->setProcessedOn('2015-09-09 11:11:04');
$collection->save();
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264758%2fhow-to-use-a-magento-1-model-to-update-multiple-rows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.
An example would look like this:
$rowIds = array(1,2,3)
foreach($rowIds as $rowId)
$data = array('processed_on' => "2015-09-09 11:11:04");
$model = Mage::getModel('your_model')->load($rowId)->addData($data);
try
$model->setId($rowId)->save();
echo "Record updated";
catch (Exception $e)
echo $e->getMessage();
You should removesetId($id)
before callingsave()
since$id
is not defined and the model has already an id, because it is an existent record.
– HelgeB
yesterday
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
add a comment |
To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.
An example would look like this:
$rowIds = array(1,2,3)
foreach($rowIds as $rowId)
$data = array('processed_on' => "2015-09-09 11:11:04");
$model = Mage::getModel('your_model')->load($rowId)->addData($data);
try
$model->setId($rowId)->save();
echo "Record updated";
catch (Exception $e)
echo $e->getMessage();
You should removesetId($id)
before callingsave()
since$id
is not defined and the model has already an id, because it is an existent record.
– HelgeB
yesterday
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
add a comment |
To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.
An example would look like this:
$rowIds = array(1,2,3)
foreach($rowIds as $rowId)
$data = array('processed_on' => "2015-09-09 11:11:04");
$model = Mage::getModel('your_model')->load($rowId)->addData($data);
try
$model->setId($rowId)->save();
echo "Record updated";
catch (Exception $e)
echo $e->getMessage();
To update existing rows in a model, you need to load each row first, call addData() with the new data, then save the row.
An example would look like this:
$rowIds = array(1,2,3)
foreach($rowIds as $rowId)
$data = array('processed_on' => "2015-09-09 11:11:04");
$model = Mage::getModel('your_model')->load($rowId)->addData($data);
try
$model->setId($rowId)->save();
echo "Record updated";
catch (Exception $e)
echo $e->getMessage();
edited 15 hours ago
answered yesterday
MClaudioMClaudio
162
162
You should removesetId($id)
before callingsave()
since$id
is not defined and the model has already an id, because it is an existent record.
– HelgeB
yesterday
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
add a comment |
You should removesetId($id)
before callingsave()
since$id
is not defined and the model has already an id, because it is an existent record.
– HelgeB
yesterday
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
You should remove
setId($id)
before calling save()
since $id
is not defined and the model has already an id, because it is an existent record.– HelgeB
yesterday
You should remove
setId($id)
before calling save()
since $id
is not defined and the model has already an id, because it is an existent record.– HelgeB
yesterday
1
1
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
You should also vaiud load/delete/save methods inside loops.
– sv3n
12 hours ago
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(array(1,2,3));
foreach ($collection as $product)
$product->setProcessedOn('2015-09-09 11:11:04');
# add this to avoid pricerule update
$product->setIsMassupdate(true);
$collection->save();
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(array(1,2,3));
foreach ($collection as $product)
$product->setProcessedOn('2015-09-09 11:11:04');
# add this to avoid pricerule update
$product->setIsMassupdate(true);
$collection->save();
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(array(1,2,3));
foreach ($collection as $product)
$product->setProcessedOn('2015-09-09 11:11:04');
# add this to avoid pricerule update
$product->setIsMassupdate(true);
$collection->save();
Instead of load/save inside foreach, you can try this:
$collection = Mage::getResourceModel('catalog/product_collection')
->addIdFilter(array(1,2,3));
foreach ($collection as $product)
$product->setProcessedOn('2015-09-09 11:11:04');
# add this to avoid pricerule update
$product->setIsMassupdate(true);
$collection->save();
answered 12 hours ago
sv3nsv3n
9,85262355
9,85262355
add a comment |
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getModel('your/model')->getCollection()
->addIdFilter(array(1,2,3));
foreach ($collection as $item)
$item->setProcessedOn('2015-09-09 11:11:04');
$collection->save();
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getModel('your/model')->getCollection()
->addIdFilter(array(1,2,3));
foreach ($collection as $item)
$item->setProcessedOn('2015-09-09 11:11:04');
$collection->save();
add a comment |
Instead of load/save inside foreach, you can try this:
$collection = Mage::getModel('your/model')->getCollection()
->addIdFilter(array(1,2,3));
foreach ($collection as $item)
$item->setProcessedOn('2015-09-09 11:11:04');
$collection->save();
Instead of load/save inside foreach, you can try this:
$collection = Mage::getModel('your/model')->getCollection()
->addIdFilter(array(1,2,3));
foreach ($collection as $item)
$item->setProcessedOn('2015-09-09 11:11:04');
$collection->save();
answered 12 hours ago
sv3nsv3n
9,85262355
9,85262355
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264758%2fhow-to-use-a-magento-1-model-to-update-multiple-rows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown