I have 2 events running if subscribe to newsletter is checked on the checkout page.
- sales_model_service_quote_submit_success
- newsletter_subscriber_save_after
Can i prevent event #2 from happening if event #1 has already ran?
This looks like a situation where you might want to store a variable that logs whether that first event has run or not.
If you have an observer for sales_model_service_quote_submit_success, you can make good use of the DataPersistorInterface class to store a temporary session variable that marks whether sales_model_service_quote_submit_success already ran.
So..
class QuoteSubmitSuccessObserver implements ObserverInterface
{
protected $dataPersistor;
public function __construct(\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor) {
$this->dataPersistor = $dataPersistor;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$this->dataPersistor->set('quote_submit_success', true)
}
}
And
class NewsletterSubscriberSaveObserver implements ObserverInterface
{
protected $dataPersistor;
public function __construct(\Magento\Framework\App\Request\DataPersistorInterface $dataPersistor) {
$this->dataPersistor = $dataPersistor;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
if (!$this->dataPersistor->get('quote_submit_success')) {
… do something here …
}
}
}
$this->_logger->clear($key)
Commented
Nov 28, 2018 at 9:45