本文整理汇总了PHP中Magento\Framework\Message\ManagerInterface::addErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerInterface::addErrorMessage方法的具体用法?PHP ManagerInterface::addErrorMessage怎么用?PHP ManagerInterface::addErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Message\ManagerInterface
的用法示例。
在下文中一共展示了ManagerInterface::addErrorMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Force admin to change password
*
* @param EventObserver $observer
* @return void
*/
public function execute(EventObserver $observer)
{
if (!$this->observerConfig->isPasswordChangeForced()) {
return;
}
if (!$this->authSession->isLoggedIn()) {
return;
}
$actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout'];
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getEvent()->getControllerAction();
/** @var \Magento\Framework\App\RequestInterface $request */
$request = $observer->getEvent()->getRequest();
if ($this->authSession->getPciAdminUserIsPasswordExpired()) {
if (!in_array($request->getFullActionName(), $actionList)) {
if ($this->authorization->isAllowed('Magento_Backend::myaccount')) {
$controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true);
} else {
/*
* if admin password is expired and access to 'My Account' page is denied
* than we need to do force logout with error message
*/
$this->authSession->clearStorage();
$this->session->clearStorage();
$this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.'));
$controller->getRequest()->setDispatched(false);
}
}
}
}
示例2: execute
/**
* Execute method.
*/
public function execute()
{
$addressBookName = $this->getRequest()->getParam('name');
$visibility = $this->getRequest()->getParam('visibility');
$website = $this->getRequest()->getParam('website', 0);
if ($this->helperData->isEnabled($website)) {
$client = $this->helperData->getWebsiteApiClient($website);
if (!empty($addressBookName)) {
$response = $client->postAddressBooks($addressBookName, $visibility);
if (isset($response->message)) {
$this->messageManager->addErrorMessage($response->message);
} else {
$this->messageManager->addSuccessMessage('Address book : ' . $addressBookName . ' created.');
}
}
}
}
示例3: syncContact
/**
* Sync a single contact.
*
* @param null $contactId
*
* @return mixed
*/
public function syncContact($contactId = null)
{
if ($contactId) {
$contact = $this->contactFactory->create()->load($contactId);
} else {
$contact = $this->registry->registry('current_contact');
}
if (!$contact->getId()) {
$this->messageManager->addErrorMessage('No contact found!');
return false;
}
$websiteId = $contact->getWebsiteId();
$website = $this->storeManager->getWebsite($websiteId);
$updated = 0;
$customers = $headers = $allMappedHash = [];
$this->helper->log('---------- Start single customer sync ----------');
//skip if the mapping field is missing
if (!$this->helper->getCustomerAddressBook($website)) {
return false;
}
$customerId = $contact->getCustomerId();
if (!$customerId) {
$this->messageManager->addErrorMessage('Cannot manually sync guests!');
return false;
}
if (!$this->helper->isEnabled($websiteId)) {
$this->messageManager->addErrorMessage('Api is not enabled');
return false;
}
$client = $this->helper->getWebsiteApiClient($website);
//create customer filename
$customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
$this->helper->log('Customers file : ' . $customersFile);
/*
* HEADERS.
*/
$mappedHash = $this->helper->getWebsiteCustomerMappingDatafields($website);
$headers = $mappedHash;
//custom customer attributes
$customAttributes = $this->helper->getCustomAttributes($website);
foreach ($customAttributes as $data) {
$headers[] = $data['datafield'];
$allMappedHash[$data['attribute']] = $data['datafield'];
}
$headers[] = 'Email';
$headers[] = 'EmailType';
$this->file->outputCSV($this->file->getFilePath($customersFile), $headers);
/*
* END HEADERS.
*/
$customerCollection = $this->_getCustomerCollection([$customerId], $website->getId());
foreach ($customerCollection as $customer) {
$contactModel = $this->contactFactory->create()->loadByCustomerEmail($customer->getEmail(), $websiteId);
//contact with this email not found
if (!$contactModel->getId()) {
continue;
}
/*
* DATA.
*/
$connectorCustomer = $this->emailCustomer->create()->setMappingHash($mappedHash)->setCustomerData($customer);
$customers[] = $connectorCustomer;
foreach ($customAttributes as $data) {
$attribute = $data['attribute'];
$value = $customer->getData($attribute);
$connectorCustomer->setData($value);
}
//contact email and email type
$connectorCustomer->setData($customer->getEmail());
$connectorCustomer->setData('Html');
// save csv file data for customers
$this->file->outputCSV($this->file->getFilePath($customersFile), $connectorCustomer->toCSVArray());
/*
* END DATA.
*/
//mark the contact as imported
$contactModel->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_IMPORTED);
$subscriber = $this->subscriberFactory->create()->loadByEmail($customer->getEmail());
if ($subscriber->isSubscribed()) {
$contactModel->setIsSubscriber('1')->setSubscriberStatus($subscriber->getSubscriberStatus());
}
//@codingStandardsIgnoreStart
$contactModel->getResource()->save($contactModel);
++$updated;
}
if (is_file($this->file->getFilePath($customersFile))) {
//@codingStandardsIgnoreEnd
//import contacts
if ($updated > 0) {
//register in queue with importer
$this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT, '', \Dotdigitalgroup\Email\Model\Importer::MODE_BULK, $website->getId(), $customersFile);
$client->postAddressBookContactsImport($customersFile, $this->helper->getCustomerAddressBook($website));
}
//.........这里部分代码省略.........