Difference between catalog_product_save_after and catalog_product_save_commit_after? The 2019 Stack Overflow Developer Survey Results Are InObserver to be called after shipment is savedDifference between $this->helper('catalog/image')->… vs. (string)$this->helper('catalog/image')->catalog_product_save_after Event for MassactionCustomer Authentication between EE and CEGet difference between model versions after saveIs there in any performance difference between defining event in front/admin and global?Difference between `checkout_onepage_controller_success_action` and `sales_order_place_after`?Will $product->save() trigger catalog_product_save_after?Difference between catalog_product_prepare_save and catalog_product_save_beforeMagento 2: Why catalog_product_save_after event is not listed?Difference between `sales_order_place_after` and `sales_order_save_after`?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Unitary representations of finite groups over finite fields
Why is the maximum length of OpenWrt’s root password 8 characters?
Why doesn't UInt have a toDouble()?
Geography at the pixel level
Does adding complexity mean a more secure cipher?
Is there a way to generate a uniformly distributed point on a sphere from a fixed amount of random real numbers?
Is it okay to consider publishing in my first year of PhD?
"as much details as you can remember"
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Can we generate random numbers using irrational numbers like π and e?
What do hard-Brexiteers want with respect to the Irish border?
The difference between dialogue marks
I am an eight letter word. What am I?
How to notate time signature switching consistently every measure
Worn-tile Scrabble
How much of the clove should I use when using big garlic heads?
How come people say “Would of”?
What does もの mean in this sentence?
A word that means fill it to the required quantity
What is this business jet?
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
Are spiders unable to hurt humans, especially very small spiders?
How to type a long/em dash `—`
Difference between catalog_product_save_after and catalog_product_save_commit_after?
The 2019 Stack Overflow Developer Survey Results Are InObserver to be called after shipment is savedDifference between $this->helper('catalog/image')->… vs. (string)$this->helper('catalog/image')->catalog_product_save_after Event for MassactionCustomer Authentication between EE and CEGet difference between model versions after saveIs there in any performance difference between defining event in front/admin and global?Difference between `checkout_onepage_controller_success_action` and `sales_order_place_after`?Will $product->save() trigger catalog_product_save_after?Difference between catalog_product_prepare_save and catalog_product_save_beforeMagento 2: Why catalog_product_save_after event is not listed?Difference between `sales_order_place_after` and `sales_order_save_after`?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Can anyone explain the difference between these events. Just the quick and dirty please. Thank you.
I have an Observer method like so:
public function detectProductChanges($observer)
$product = $observer->getProduct();
$old = $product->getOrigData();
$new = $product->getData();
if ($product->hasDataChanges() && $old['status'] == 1 && $new['status'] == 2)
$this->_sendStatusMail($product);
It's not getting to the sendStatusMail()
I'm hooking into the event:
<events>
<catalog_product_save_after>
<observers>
<productchange>
<type>singleton</type>
<class>A_ProductNotification_Model_Observer</class>
<method>detectProductChanges</method>
</productchange>
</observers>
</catalog_product_save_after>
</events>
Should i be using: catalog_product_save_commit_after
GOAL:
Have an email sent after product is disabled.
private function _sendStatusMail($product)
if (!Mage::getStoreConfig('trans_email/ident_custom3/email')) return false;
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('elec_productnotification_tpl');
$emailTemplate->setTemplateSubject('Product has been disabled');
$emailTemplate->setSenderEmail($salesData['email']);
$emailTemplateVariables['style_number'] = $product->getElecStyle();
$emailTemplateVariables['frame_color'] = $product->getAttributeText('frame_color');
$emailTemplateVariables['size'] = $product->getAttributeText('size');
$emailTemplateVariables['elec_color'] = $product->getAttributeText('elec_color');
$emailTemplateVariables['store_name'] = Mage::getModel('core/store')->load($product->getStoreId())->getName();
$emailTemplateVariables['product_name'] = Mage::getModel('catalog/product')->load($product->getId())->getName();
$emailTemplateVariables['product_sku'] = $product->getSku();
$emailTemplateVariables['dates'] = date("F jS Y h:i:sA", strtotime('-7 hours'));
// Get General email address (Admin->Configuration->General->Store Email Addresses)
$emails = explode(',', Mage::getStoreConfig('trans_email/ident_custom3/email'));
foreach ($emails as $email) $emailTemplate->send($email, $product->getStoreId(), $emailTemplateVariables);
}
event-observer ee-1.12 ee-1.12.0.2
add a comment |
Can anyone explain the difference between these events. Just the quick and dirty please. Thank you.
I have an Observer method like so:
public function detectProductChanges($observer)
$product = $observer->getProduct();
$old = $product->getOrigData();
$new = $product->getData();
if ($product->hasDataChanges() && $old['status'] == 1 && $new['status'] == 2)
$this->_sendStatusMail($product);
It's not getting to the sendStatusMail()
I'm hooking into the event:
<events>
<catalog_product_save_after>
<observers>
<productchange>
<type>singleton</type>
<class>A_ProductNotification_Model_Observer</class>
<method>detectProductChanges</method>
</productchange>
</observers>
</catalog_product_save_after>
</events>
Should i be using: catalog_product_save_commit_after
GOAL:
Have an email sent after product is disabled.
private function _sendStatusMail($product)
if (!Mage::getStoreConfig('trans_email/ident_custom3/email')) return false;
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('elec_productnotification_tpl');
$emailTemplate->setTemplateSubject('Product has been disabled');
$emailTemplate->setSenderEmail($salesData['email']);
$emailTemplateVariables['style_number'] = $product->getElecStyle();
$emailTemplateVariables['frame_color'] = $product->getAttributeText('frame_color');
$emailTemplateVariables['size'] = $product->getAttributeText('size');
$emailTemplateVariables['elec_color'] = $product->getAttributeText('elec_color');
$emailTemplateVariables['store_name'] = Mage::getModel('core/store')->load($product->getStoreId())->getName();
$emailTemplateVariables['product_name'] = Mage::getModel('catalog/product')->load($product->getId())->getName();
$emailTemplateVariables['product_sku'] = $product->getSku();
$emailTemplateVariables['dates'] = date("F jS Y h:i:sA", strtotime('-7 hours'));
// Get General email address (Admin->Configuration->General->Store Email Addresses)
$emails = explode(',', Mage::getStoreConfig('trans_email/ident_custom3/email'));
foreach ($emails as $email) $emailTemplate->send($email, $product->getStoreId(), $emailTemplateVariables);
}
event-observer ee-1.12 ee-1.12.0.2
you should use event<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26
add a comment |
Can anyone explain the difference between these events. Just the quick and dirty please. Thank you.
I have an Observer method like so:
public function detectProductChanges($observer)
$product = $observer->getProduct();
$old = $product->getOrigData();
$new = $product->getData();
if ($product->hasDataChanges() && $old['status'] == 1 && $new['status'] == 2)
$this->_sendStatusMail($product);
It's not getting to the sendStatusMail()
I'm hooking into the event:
<events>
<catalog_product_save_after>
<observers>
<productchange>
<type>singleton</type>
<class>A_ProductNotification_Model_Observer</class>
<method>detectProductChanges</method>
</productchange>
</observers>
</catalog_product_save_after>
</events>
Should i be using: catalog_product_save_commit_after
GOAL:
Have an email sent after product is disabled.
private function _sendStatusMail($product)
if (!Mage::getStoreConfig('trans_email/ident_custom3/email')) return false;
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('elec_productnotification_tpl');
$emailTemplate->setTemplateSubject('Product has been disabled');
$emailTemplate->setSenderEmail($salesData['email']);
$emailTemplateVariables['style_number'] = $product->getElecStyle();
$emailTemplateVariables['frame_color'] = $product->getAttributeText('frame_color');
$emailTemplateVariables['size'] = $product->getAttributeText('size');
$emailTemplateVariables['elec_color'] = $product->getAttributeText('elec_color');
$emailTemplateVariables['store_name'] = Mage::getModel('core/store')->load($product->getStoreId())->getName();
$emailTemplateVariables['product_name'] = Mage::getModel('catalog/product')->load($product->getId())->getName();
$emailTemplateVariables['product_sku'] = $product->getSku();
$emailTemplateVariables['dates'] = date("F jS Y h:i:sA", strtotime('-7 hours'));
// Get General email address (Admin->Configuration->General->Store Email Addresses)
$emails = explode(',', Mage::getStoreConfig('trans_email/ident_custom3/email'));
foreach ($emails as $email) $emailTemplate->send($email, $product->getStoreId(), $emailTemplateVariables);
}
event-observer ee-1.12 ee-1.12.0.2
Can anyone explain the difference between these events. Just the quick and dirty please. Thank you.
I have an Observer method like so:
public function detectProductChanges($observer)
$product = $observer->getProduct();
$old = $product->getOrigData();
$new = $product->getData();
if ($product->hasDataChanges() && $old['status'] == 1 && $new['status'] == 2)
$this->_sendStatusMail($product);
It's not getting to the sendStatusMail()
I'm hooking into the event:
<events>
<catalog_product_save_after>
<observers>
<productchange>
<type>singleton</type>
<class>A_ProductNotification_Model_Observer</class>
<method>detectProductChanges</method>
</productchange>
</observers>
</catalog_product_save_after>
</events>
Should i be using: catalog_product_save_commit_after
GOAL:
Have an email sent after product is disabled.
private function _sendStatusMail($product)
if (!Mage::getStoreConfig('trans_email/ident_custom3/email')) return false;
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('elec_productnotification_tpl');
$emailTemplate->setTemplateSubject('Product has been disabled');
$emailTemplate->setSenderEmail($salesData['email']);
$emailTemplateVariables['style_number'] = $product->getElecStyle();
$emailTemplateVariables['frame_color'] = $product->getAttributeText('frame_color');
$emailTemplateVariables['size'] = $product->getAttributeText('size');
$emailTemplateVariables['elec_color'] = $product->getAttributeText('elec_color');
$emailTemplateVariables['store_name'] = Mage::getModel('core/store')->load($product->getStoreId())->getName();
$emailTemplateVariables['product_name'] = Mage::getModel('catalog/product')->load($product->getId())->getName();
$emailTemplateVariables['product_sku'] = $product->getSku();
$emailTemplateVariables['dates'] = date("F jS Y h:i:sA", strtotime('-7 hours'));
// Get General email address (Admin->Configuration->General->Store Email Addresses)
$emails = explode(',', Mage::getStoreConfig('trans_email/ident_custom3/email'));
foreach ($emails as $email) $emailTemplate->send($email, $product->getStoreId(), $emailTemplateVariables);
}
event-observer ee-1.12 ee-1.12.0.2
event-observer ee-1.12 ee-1.12.0.2
edited Jun 10 '16 at 20:33
thismethod
asked Jun 8 '16 at 17:34
thismethodthismethod
128318
128318
you should use event<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26
add a comment |
you should use event<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26
you should use event
<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
you should use event
<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26
add a comment |
2 Answers
2
active
oldest
votes
Saving happens in a MySQL transaction and the save_after
event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction.
The save_commit_after
event is triggered after the transaction has been committed, i.e. when the changes were written to the database.
Also, on save_commit_after
, the _hasDataChanges
property already has been reset to false
, so your check would not work. On the other hand, if there were no changes, both events would not even be triggered, because Mage_Core_Model_Abstract::save() does nothing if there were no data changes:
if (!$this->_hasModelChanged())
return $this;
That being said, I don't see why your code should not work.
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
add a comment |
vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php
public function save(MagentoFrameworkModelAbstractModel $object)
// ...
$this->beginTransaction();
try
// ...
if ($object->isSaveAllowed())
// ...
$this->_beforeSave($object);
// ...
if ($this->isObjectNotNew($object))
$this->updateObject($object);
else
$this->saveNewObject($object);
// ...
$this->processAfterSaves($object);
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
// ...
catch (Exception $e)
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
return $this;
Let's have a look at saving product entity.
-product_model save
|-product_resource save
|--begin transaction (0 lvl)
|---before product save events
|---creating new product or updating existing one
|---after product save events
|----one of event is saving another entity CatalogInventory Stock
|-----catalog_inventory_stock resource save
|------begin another transaction (1 lvl)
|-------before stock save events
|-------updating / creating stock item
|-------after product save events (here could be one more
dependable entity which could cause one more save
operation and begin another transaction)
|------commit of 1st level !!! No callbacks executed
|--commit of 0 level ALL CALLBACKS ARE EXECUTED
Here is the code of commit function:
/**
* Commit resource transaction
*
* @return $this
* @api
*/
public function commit()
$this->getConnection()->commit();
/**
* Process after commit callbacks
*/
if ($this->getConnection()->getTransactionLevel() === 0)
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
try
foreach ($callbacks as $callback)
call_user_func($callback);
catch (Exception $e)
$this->getLogger()->critical($e);
return $this;
Let's have a look at our example more closely.
$this->getConnection()->commit();
put values into DB for our 1st level (it's Stock). If something bad happens here, exception will be thrown and all changes will be rolled back.Then it goes to process callbacks. As we are currently at 1st level, no callbacks will be called. And we are moving out from catalog_product_after_save event to commit product changes (0 level).
$this->getConnection()->commit();
put values into DB for our 0 level (it's Product itself). If something bad happens here exception will also be thrown and all changes also will be rolled back.Then we are moving to callbacks execution. Now we are at 0 level and callbacks will be run. Anything you bad inside
call_user_func($callback);
will be catched up and just logged. Nothing will be rolled back if callback cause an exception
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%2f120004%2fdifference-between-catalog-product-save-after-and-catalog-product-save-commit-af%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Saving happens in a MySQL transaction and the save_after
event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction.
The save_commit_after
event is triggered after the transaction has been committed, i.e. when the changes were written to the database.
Also, on save_commit_after
, the _hasDataChanges
property already has been reset to false
, so your check would not work. On the other hand, if there were no changes, both events would not even be triggered, because Mage_Core_Model_Abstract::save() does nothing if there were no data changes:
if (!$this->_hasModelChanged())
return $this;
That being said, I don't see why your code should not work.
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
add a comment |
Saving happens in a MySQL transaction and the save_after
event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction.
The save_commit_after
event is triggered after the transaction has been committed, i.e. when the changes were written to the database.
Also, on save_commit_after
, the _hasDataChanges
property already has been reset to false
, so your check would not work. On the other hand, if there were no changes, both events would not even be triggered, because Mage_Core_Model_Abstract::save() does nothing if there were no data changes:
if (!$this->_hasModelChanged())
return $this;
That being said, I don't see why your code should not work.
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
add a comment |
Saving happens in a MySQL transaction and the save_after
event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction.
The save_commit_after
event is triggered after the transaction has been committed, i.e. when the changes were written to the database.
Also, on save_commit_after
, the _hasDataChanges
property already has been reset to false
, so your check would not work. On the other hand, if there were no changes, both events would not even be triggered, because Mage_Core_Model_Abstract::save() does nothing if there were no data changes:
if (!$this->_hasModelChanged())
return $this;
That being said, I don't see why your code should not work.
Saving happens in a MySQL transaction and the save_after
event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction.
The save_commit_after
event is triggered after the transaction has been committed, i.e. when the changes were written to the database.
Also, on save_commit_after
, the _hasDataChanges
property already has been reset to false
, so your check would not work. On the other hand, if there were no changes, both events would not even be triggered, because Mage_Core_Model_Abstract::save() does nothing if there were no data changes:
if (!$this->_hasModelChanged())
return $this;
That being said, I don't see why your code should not work.
answered Jun 8 '16 at 20:43
Fabian SchmenglerFabian Schmengler
55.3k21138354
55.3k21138354
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
add a comment |
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Thank you for the answer. When i add a Mage::log() in place of sendStatusMail() i get the log message correctly. But it's not sending emails. I ensured that "Disable Email Communications" is set to NO and that my email address is in my custom email > store email addresses. Any other ideas why it's not working? @fschmengler
– thismethod
Jun 10 '16 at 19:23
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
Without knowing your sendStatusMail method, no. That's probably material for another question. Or does the same method work if called from a different context?
– Fabian Schmengler
Jun 10 '16 at 20:00
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
I updated my original question to show the sendStatusMail method. If you don't mind further assisting. Thank you.
– thismethod
Jun 10 '16 at 20:34
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
Any chance you could give me your opinion on my sendStatusMail($product) method?
– thismethod
Jun 13 '16 at 19:18
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
I can't spot any errors there, sorry
– Fabian Schmengler
Jun 13 '16 at 20:50
add a comment |
vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php
public function save(MagentoFrameworkModelAbstractModel $object)
// ...
$this->beginTransaction();
try
// ...
if ($object->isSaveAllowed())
// ...
$this->_beforeSave($object);
// ...
if ($this->isObjectNotNew($object))
$this->updateObject($object);
else
$this->saveNewObject($object);
// ...
$this->processAfterSaves($object);
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
// ...
catch (Exception $e)
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
return $this;
Let's have a look at saving product entity.
-product_model save
|-product_resource save
|--begin transaction (0 lvl)
|---before product save events
|---creating new product or updating existing one
|---after product save events
|----one of event is saving another entity CatalogInventory Stock
|-----catalog_inventory_stock resource save
|------begin another transaction (1 lvl)
|-------before stock save events
|-------updating / creating stock item
|-------after product save events (here could be one more
dependable entity which could cause one more save
operation and begin another transaction)
|------commit of 1st level !!! No callbacks executed
|--commit of 0 level ALL CALLBACKS ARE EXECUTED
Here is the code of commit function:
/**
* Commit resource transaction
*
* @return $this
* @api
*/
public function commit()
$this->getConnection()->commit();
/**
* Process after commit callbacks
*/
if ($this->getConnection()->getTransactionLevel() === 0)
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
try
foreach ($callbacks as $callback)
call_user_func($callback);
catch (Exception $e)
$this->getLogger()->critical($e);
return $this;
Let's have a look at our example more closely.
$this->getConnection()->commit();
put values into DB for our 1st level (it's Stock). If something bad happens here, exception will be thrown and all changes will be rolled back.Then it goes to process callbacks. As we are currently at 1st level, no callbacks will be called. And we are moving out from catalog_product_after_save event to commit product changes (0 level).
$this->getConnection()->commit();
put values into DB for our 0 level (it's Product itself). If something bad happens here exception will also be thrown and all changes also will be rolled back.Then we are moving to callbacks execution. Now we are at 0 level and callbacks will be run. Anything you bad inside
call_user_func($callback);
will be catched up and just logged. Nothing will be rolled back if callback cause an exception
add a comment |
vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php
public function save(MagentoFrameworkModelAbstractModel $object)
// ...
$this->beginTransaction();
try
// ...
if ($object->isSaveAllowed())
// ...
$this->_beforeSave($object);
// ...
if ($this->isObjectNotNew($object))
$this->updateObject($object);
else
$this->saveNewObject($object);
// ...
$this->processAfterSaves($object);
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
// ...
catch (Exception $e)
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
return $this;
Let's have a look at saving product entity.
-product_model save
|-product_resource save
|--begin transaction (0 lvl)
|---before product save events
|---creating new product or updating existing one
|---after product save events
|----one of event is saving another entity CatalogInventory Stock
|-----catalog_inventory_stock resource save
|------begin another transaction (1 lvl)
|-------before stock save events
|-------updating / creating stock item
|-------after product save events (here could be one more
dependable entity which could cause one more save
operation and begin another transaction)
|------commit of 1st level !!! No callbacks executed
|--commit of 0 level ALL CALLBACKS ARE EXECUTED
Here is the code of commit function:
/**
* Commit resource transaction
*
* @return $this
* @api
*/
public function commit()
$this->getConnection()->commit();
/**
* Process after commit callbacks
*/
if ($this->getConnection()->getTransactionLevel() === 0)
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
try
foreach ($callbacks as $callback)
call_user_func($callback);
catch (Exception $e)
$this->getLogger()->critical($e);
return $this;
Let's have a look at our example more closely.
$this->getConnection()->commit();
put values into DB for our 1st level (it's Stock). If something bad happens here, exception will be thrown and all changes will be rolled back.Then it goes to process callbacks. As we are currently at 1st level, no callbacks will be called. And we are moving out from catalog_product_after_save event to commit product changes (0 level).
$this->getConnection()->commit();
put values into DB for our 0 level (it's Product itself). If something bad happens here exception will also be thrown and all changes also will be rolled back.Then we are moving to callbacks execution. Now we are at 0 level and callbacks will be run. Anything you bad inside
call_user_func($callback);
will be catched up and just logged. Nothing will be rolled back if callback cause an exception
add a comment |
vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php
public function save(MagentoFrameworkModelAbstractModel $object)
// ...
$this->beginTransaction();
try
// ...
if ($object->isSaveAllowed())
// ...
$this->_beforeSave($object);
// ...
if ($this->isObjectNotNew($object))
$this->updateObject($object);
else
$this->saveNewObject($object);
// ...
$this->processAfterSaves($object);
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
// ...
catch (Exception $e)
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
return $this;
Let's have a look at saving product entity.
-product_model save
|-product_resource save
|--begin transaction (0 lvl)
|---before product save events
|---creating new product or updating existing one
|---after product save events
|----one of event is saving another entity CatalogInventory Stock
|-----catalog_inventory_stock resource save
|------begin another transaction (1 lvl)
|-------before stock save events
|-------updating / creating stock item
|-------after product save events (here could be one more
dependable entity which could cause one more save
operation and begin another transaction)
|------commit of 1st level !!! No callbacks executed
|--commit of 0 level ALL CALLBACKS ARE EXECUTED
Here is the code of commit function:
/**
* Commit resource transaction
*
* @return $this
* @api
*/
public function commit()
$this->getConnection()->commit();
/**
* Process after commit callbacks
*/
if ($this->getConnection()->getTransactionLevel() === 0)
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
try
foreach ($callbacks as $callback)
call_user_func($callback);
catch (Exception $e)
$this->getLogger()->critical($e);
return $this;
Let's have a look at our example more closely.
$this->getConnection()->commit();
put values into DB for our 1st level (it's Stock). If something bad happens here, exception will be thrown and all changes will be rolled back.Then it goes to process callbacks. As we are currently at 1st level, no callbacks will be called. And we are moving out from catalog_product_after_save event to commit product changes (0 level).
$this->getConnection()->commit();
put values into DB for our 0 level (it's Product itself). If something bad happens here exception will also be thrown and all changes also will be rolled back.Then we are moving to callbacks execution. Now we are at 0 level and callbacks will be run. Anything you bad inside
call_user_func($callback);
will be catched up and just logged. Nothing will be rolled back if callback cause an exception
vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php
public function save(MagentoFrameworkModelAbstractModel $object)
// ...
$this->beginTransaction();
try
// ...
if ($object->isSaveAllowed())
// ...
$this->_beforeSave($object);
// ...
if ($this->isObjectNotNew($object))
$this->updateObject($object);
else
$this->saveNewObject($object);
// ...
$this->processAfterSaves($object);
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
// ...
catch (Exception $e)
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
return $this;
Let's have a look at saving product entity.
-product_model save
|-product_resource save
|--begin transaction (0 lvl)
|---before product save events
|---creating new product or updating existing one
|---after product save events
|----one of event is saving another entity CatalogInventory Stock
|-----catalog_inventory_stock resource save
|------begin another transaction (1 lvl)
|-------before stock save events
|-------updating / creating stock item
|-------after product save events (here could be one more
dependable entity which could cause one more save
operation and begin another transaction)
|------commit of 1st level !!! No callbacks executed
|--commit of 0 level ALL CALLBACKS ARE EXECUTED
Here is the code of commit function:
/**
* Commit resource transaction
*
* @return $this
* @api
*/
public function commit()
$this->getConnection()->commit();
/**
* Process after commit callbacks
*/
if ($this->getConnection()->getTransactionLevel() === 0)
$callbacks = CallbackPool::get(spl_object_hash($this->getConnection()));
try
foreach ($callbacks as $callback)
call_user_func($callback);
catch (Exception $e)
$this->getLogger()->critical($e);
return $this;
Let's have a look at our example more closely.
$this->getConnection()->commit();
put values into DB for our 1st level (it's Stock). If something bad happens here, exception will be thrown and all changes will be rolled back.Then it goes to process callbacks. As we are currently at 1st level, no callbacks will be called. And we are moving out from catalog_product_after_save event to commit product changes (0 level).
$this->getConnection()->commit();
put values into DB for our 0 level (it's Product itself). If something bad happens here exception will also be thrown and all changes also will be rolled back.Then we are moving to callbacks execution. Now we are at 0 level and callbacks will be run. Anything you bad inside
call_user_func($callback);
will be catched up and just logged. Nothing will be rolled back if callback cause an exception
answered yesterday
zhartaunikzhartaunik
2,69011544
2,69011544
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%2f120004%2fdifference-between-catalog-product-save-after-and-catalog-product-save-commit-af%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
you should use event
<catalog_product_status_update>
– Nickool
Jun 8 '16 at 19:17
Is that the reason it's not firing? Simply using the wrong event? @Nickool
– thismethod
Jun 8 '16 at 19:26