/** * Redirect to order view page * * @param int $orderId * @return \Magento\Backend\Model\View\Result\Redirect */ protected function _redirectToOrder($orderId) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]); return $resultRedirect; }
/** * Edit CMS page * * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('page_id'); $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page'); // 2. Initial checking if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addError(__('This page no longer exists.')); /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } // 3. Set entered data if was error when we do save $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true); if (!empty($data)) { $model->setData($data); } // 4. Register model to use later in blocks $this->_coreRegistry->register('cms_page', $model); // 5. Build edit form /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->_initAction(); $resultPage->addBreadcrumb($id ? __('Edit Page') : __('New Page'), $id ? __('Edit Page') : __('New Page')); $resultPage->getConfig()->getTitle()->prepend(__('Pages')); $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Page')); return $resultPage; }
/** * Save status assignment to state * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPostValue(); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $state = $this->getRequest()->getParam('state'); $isDefault = $this->getRequest()->getParam('is_default'); $visibleOnFront = $this->getRequest()->getParam('visible_on_front'); $status = $this->_initStatus(); if ($status && $status->getStatus()) { try { $status->assignState($state, $isDefault, $visibleOnFront); $this->messageManager->addSuccess(__('You have assigned the order status.')); return $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('An error occurred while assigning order status. Status has not been assigned.')); } } else { $this->messageManager->addError(__('We can\'t find this order status.')); } return $resultRedirect->setPath('sales/*/assign'); } return $resultRedirect->setPath('sales/*/'); }
/** * Product edit form * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $productId = (int) $this->getRequest()->getParam('id'); $product = $this->productBuilder->build($this->getRequest()); if ($productId && !$product->getId()) { $this->messageManager->addError(__('This product no longer exists.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/'); } $this->_eventManager->dispatch('catalog_product_edit_action', ['product' => $product]); /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->addHandle('catalog_product_' . $product->getTypeId()); $resultPage->setActiveMenu('Magento_Catalog::catalog_products'); $resultPage->getConfig()->getTitle()->prepend(__('Products')); $resultPage->getConfig()->getTitle()->prepend($product->getName()); if (!$this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->isSingleStoreMode() && ($switchBlock = $resultPage->getLayout()->getBlock('store_switcher'))) { $switchBlock->setDefaultStoreName(__('Default Values'))->setWebsiteIds($product->getWebsiteIds())->setSwitchUrl($this->getUrl('catalog/*/*', ['_current' => true, 'active_tab' => null, 'tab' => null, 'store' => null])); } $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { $block->setStoreId($product->getStoreId()); } return $resultPage; }
/** * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { if (!$this->_validateProducts()) { return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]); } return $this->resultPageFactory->create(); }
/** * Save product action * * @return \Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { $storeId = $this->getRequest()->getParam('store'); $redirectBack = $this->getRequest()->getParam('back', false); $productId = $this->getRequest()->getParam('id'); $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { try { $product = $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest())); $this->productTypeManager->processProduct($product); if (isset($data['product'][$product->getIdFieldName()])) { throw new \Magento\Framework\Exception\LocalizedException(__('Unable to save product')); } $originalSku = $product->getSku(); $product->save(); $productId = $product->getId(); /** * Do copying data to stores */ if (isset($data['copy_to_stores'])) { foreach ($data['copy_to_stores'] as $storeTo => $storeFrom) { $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($storeFrom)->load($productId)->setStoreId($storeTo)->save(); } } $this->messageManager->addSuccess(__('You saved the product.')); if ($product->getSku() != $originalSku) { $this->messageManager->addNotice(__('SKU for product %1 has been changed to %2.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getSku()))); } $this->_eventManager->dispatch('controller_action_catalog_product_save_entity_after', ['controller' => $this]); if ($redirectBack === 'duplicate') { $newProduct = $this->productCopier->copy($product); $this->messageManager->addSuccess(__('You duplicated the product.')); } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $this->_session->setProductData($data); $redirectBack = $productId ? true : 'new'; } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $this->messageManager->addError($e->getMessage()); $this->_session->setProductData($data); $redirectBack = $productId ? true : 'new'; } } else { $resultRedirect->setPath('catalog/*/', ['store' => $storeId]); $this->messageManager->addError('No data to save'); return $resultRedirect; } if ($redirectBack === 'new') { $resultRedirect->setPath('catalog/*/new', ['set' => $product->getAttributeSetId(), 'type' => $product->getTypeId()]); } elseif ($redirectBack === 'duplicate' && isset($newProduct)) { $resultRedirect->setPath('catalog/*/edit', ['id' => $newProduct->getId(), 'back' => null, '_current' => true]); } elseif ($redirectBack) { $resultRedirect->setPath('catalog/*/edit', ['id' => $productId, '_current' => true]); } else { $resultRedirect->setPath('catalog/*/', ['store' => $storeId]); } return $resultRedirect; }
/** * Delete action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); // check if we know what should be deleted $id = $this->getRequest()->getParam('block_id'); if ($id) { try { // init model and delete $model = $this->_objectManager->create('Magento\\Cms\\Model\\Block'); $model->load($id); $model->delete(); // display success message $this->messageManager->addSuccess(__('The block has been deleted.')); // go to grid return $resultRedirect->setPath('*/*/'); } catch (\Exception $e) { // display error message $this->messageManager->addError($e->getMessage()); // go back to edit form return $resultRedirect->setPath('*/*/edit', ['block_id' => $id]); } } // display error message $this->messageManager->addError(__('We can\'t find a block to delete.')); // go to grid return $resultRedirect->setPath('*/*/'); }
/** * Void creditmemo action * * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward */ public function execute() { $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id')); $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo')); $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id')); $creditmemo = $this->creditmemoLoader->load(); if ($creditmemo) { try { $creditmemo->void(); $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction'); $transactionSave->addObject($creditmemo); $transactionSave->addObject($creditmemo->getOrder()); if ($creditmemo->getInvoice()) { $transactionSave->addObject($creditmemo->getInvoice()); } $transactionSave->save(); $this->messageManager->addSuccess(__('You voided the credit memo.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t void the credit memo.')); } $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]); return $resultRedirect; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
/** * Delete action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { // check if we know what should be deleted $id = $this->getRequest()->getParam('page_id'); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($id) { $title = ""; try { // init model and delete $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page'); $model->load($id); $title = $model->getTitle(); $model->delete(); // display success message $this->messageManager->addSuccess(__('The page has been deleted.')); // go to grid $this->_eventManager->dispatch('adminhtml_cmspage_on_delete', ['title' => $title, 'status' => 'success']); return $resultRedirect->setPath('*/*/'); } catch (\Exception $e) { $this->_eventManager->dispatch('adminhtml_cmspage_on_delete', ['title' => $title, 'status' => 'fail']); // display error message $this->messageManager->addError($e->getMessage()); // go back to edit form return $resultRedirect->setPath('*/*/edit', ['page_id' => $id]); } } // display error message $this->messageManager->addError(__('We can\'t find a page to delete.')); // go to grid return $resultRedirect->setPath('*/*/'); }
/** * Administrator logout action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $this->_auth->logout(); $this->messageManager->addSuccess(__('You have logged out.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath($this->_helper->getHomePageUrl()); }
/** * Start create creditmemo action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { /** * Clear old values for creditmemo qty's */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/*/new', ['_current' => true]); return $resultRedirect; }
/** * Start create invoice action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** * Clear old values for invoice qty's */ $this->_getSession()->getInvoiceItemQtys(true); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]); return $resultRedirect; }
/** * Administrator login action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { if ($this->_auth->isLoggedIn()) { if ($this->_auth->getAuthStorage()->isFirstPageAfterLogin()) { $this->_auth->getAuthStorage()->setIsFirstPageAfterLogin(true); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath($this->_backendUrl->getStartupPageUrl()); return $resultRedirect; } return $this->resultPageFactory->create(); }
/** * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { if (!$this->_auth->isLoggedIn()) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setStatusHeader(403, '1.1', 'Forbidden'); return $resultRedirect->setPath('*/auth/login'); } /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setStatusHeader(403, '1.1', 'Forbidden'); $resultPage->addHandle('adminhtml_denied'); return $resultPage; }
/** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $setId = $this->getRequest()->getParam('id'); $resultRedirect = $this->resultRedirectFactory->create(); try { $this->attributeSetRepository->deleteById($setId); $this->messageManager->addSuccess(__('The attribute set has been removed.')); $resultRedirect->setPath('catalog/*/'); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while deleting this set.')); $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*'))); } return $resultRedirect; }
/** * Notify user * * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { $invoiceId = $this->getRequest()->getParam('invoice_id'); if (!$invoiceId) { return $this->resultForwardFactory->create()->forward('noroute'); } $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId); if (!$invoice) { return $this->resultForwardFactory->create()->forward('noroute'); } $this->_objectManager->create('Magento\\Sales\\Model\\Order\\InvoiceNotifier')->notify($invoice); $this->messageManager->addSuccess(__('We sent the message.')); return $this->resultRedirectFactory->create()->setPath('sales/invoice/view', ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId]); }
/** * Create product duplicate * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $product = $this->productBuilder->build($this->getRequest()); try { $newProduct = $this->productCopier->copy($product); $this->messageManager->addSuccess(__('You duplicated the product.')); $resultRedirect->setPath('catalog/*/edit', ['_current' => true, 'id' => $newProduct->getId()]); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $this->messageManager->addError($e->getMessage()); $resultRedirect->setPath('catalog/*/edit', ['_current' => true]); } return $resultRedirect; }
/** * Notify user * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $creditmemoId = $this->getRequest()->getParam('creditmemo_id'); if (!$creditmemoId) { return; } $creditmemo = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Creditmemo')->load($creditmemoId); if (!$creditmemo) { return; } $this->_objectManager->create('Magento\\Sales\\Model\\Order\\CreditmemoNotifier')->notify($creditmemo); $this->messageManager->addSuccess(__('We sent the message.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/order_creditmemo/view', ['creditmemo_id' => $creditmemoId]); return $resultRedirect; }
/** * @return ResponseInterface|void */ public function execute() { $invoicesIds = $this->getRequest()->getPost('invoice_ids'); if (!empty($invoicesIds)) { $invoices = $this->_objectManager->create('Magento\\Sales\\Model\\Resource\\Order\\Invoice\\Collection')->addAttributeToSelect('*')->addAttributeToFilter('entity_id', ['in' => $invoicesIds])->load(); if (!isset($pdf)) { $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices); } else { $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices); $pdf->pages = array_merge($pdf->pages, $pages->pages); } $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s'); return $this->_fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf'); } return $this->resultRedirectFactory->create()->setPath('sales/*/'); }
/** * Save configuration * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { try { // custom save logic $this->_saveSection(); $section = $this->getRequest()->getParam('section'); $website = $this->getRequest()->getParam('website'); $store = $this->getRequest()->getParam('store'); $configData = ['section' => $section, 'website' => $website, 'store' => $store, 'groups' => $this->_getGroupsForSave()]; /** @var \Magento\Config\Model\Config $configModel */ $configModel = $this->_configFactory->create(['data' => $configData]); $configModel->save(); $this->messageManager->addSuccess(__('You saved the configuration.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $messages = explode("\n", $e->getMessage()); foreach ($messages as $message) { $this->messageManager->addError($message); } } catch (\Exception $e) { $this->messageManager->addException($e, __('An error occurred while saving this configuration:') . ' ' . $e->getMessage()); } $this->_saveState($this->getRequest()->getPost('config_state')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/system_config/edit', ['_current' => ['section', 'website', 'store'], '_nosid' => true]); }
/** * Saving edited user information * * @return \Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { $userId = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getUser()->getId(); $password = (string) $this->getRequest()->getParam('password'); $passwordConfirmation = (string) $this->getRequest()->getParam('password_confirmation'); $interfaceLocale = (string) $this->getRequest()->getParam('interface_locale', false); /** @var $user \Magento\User\Model\User */ $user = $this->_objectManager->create('Magento\\User\\Model\\User')->load($userId); $user->setId($userId)->setUsername($this->getRequest()->getParam('username', false))->setFirstname($this->getRequest()->getParam('firstname', false))->setLastname($this->getRequest()->getParam('lastname', false))->setEmail(strtolower($this->getRequest()->getParam('email', false))); if ($this->_objectManager->get('Magento\\Framework\\Locale\\Validator')->isValid($interfaceLocale)) { $user->setInterfaceLocale($interfaceLocale); /** @var \Magento\Backend\Model\Locale\Manager $localeManager */ $localeManager = $this->_objectManager->get('Magento\\Backend\\Model\\Locale\\Manager'); $localeManager->switchBackendInterfaceLocale($interfaceLocale); } /** Before updating admin user data, ensure that password of current admin user is entered and is correct */ $currentUserPasswordField = \Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD; $currentUserPassword = $this->getRequest()->getParam($currentUserPasswordField); $isCurrentUserPasswordValid = !empty($currentUserPassword) && is_string($currentUserPassword); try { if (!($isCurrentUserPasswordValid && $user->verifyIdentity($currentUserPassword))) { throw new AuthenticationException(__('You have entered an invalid password for current user.')); } if ($password !== '') { $user->setPassword($password); $user->setPasswordConfirmation($passwordConfirmation); } $user->save(); /** Send password reset email notification only when password was changed */ if ($password !== '') { $user->sendPasswordResetNotificationEmail(); } $this->messageManager->addSuccess(__('The account has been saved.')); } catch (\Magento\Framework\Validator\Exception $e) { $this->messageManager->addMessages($e->getMessages()); if ($e->getMessage()) { $this->messageManager->addError($e->getMessage()); } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while saving account.')); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath("*/*/"); }
/** * IFrame handler for submitted configuration for wishlist item. * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { // Update wishlist item $updateResult = new \Magento\Framework\Object(); try { $this->_initData(); $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams()); $this->_wishlist->updateItem($this->_wishlistItem->getId(), $buyRequest)->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult); return $this->resultRedirectFactory->create()->setPath('catalog/product/showUpdateResult'); }
/** * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { $this->_setTypeId(); $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->load($this->getRequest()->getParam('id')); if (!$attributeSet->getId()) { return $this->resultRedirectFactory->create()->setPath('catalog/*/index'); } $this->_coreRegistry->register('current_attribute_set', $attributeSet); /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Magento_Catalog::catalog_attributes_sets'); $resultPage->getConfig()->getTitle()->prepend(__('Product Templates')); $resultPage->getConfig()->getTitle()->prepend($attributeSet->getId() ? $attributeSet->getAttributeSetName() : __('New Set')); $resultPage->addBreadcrumb(__('Catalog'), __('Catalog')); $resultPage->addBreadcrumb(__('Manage Product Sets'), __('Manage Product Sets')); return $resultPage; }
/** * Download backup action * * @return void|\Magento\Backend\App\Action */ public function execute() { /* @var $backup \Magento\Backup\Model\Backup */ $backup = $this->_backupModelFactory->create($this->getRequest()->getParam('time'), $this->getRequest()->getParam('type')); if (!$backup->getTime() || !$backup->exists()) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('backup/*'); return $resultRedirect; } $fileName = $this->_objectManager->get('Magento\\Backup\\Helper\\Data')->generateBackupDownloadName($backup); $this->_fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $backup->getSize()); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($backup->output()); return $resultRaw; }
/** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $productIds = $this->getRequest()->getParam('product'); if (!is_array($productIds) || empty($productIds)) { $this->messageManager->addError(__('Please select product(s).')); } else { try { foreach ($productIds as $productId) { $product = $this->_objectManager->get('Magento\\Catalog\\Model\\Product')->load($productId); $product->delete(); } $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', count($productIds))); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); } } return $this->resultRedirectFactory->create()->setPath('catalog/*/index'); }
/** * Editing existing status form * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $status = $this->_initStatus(); if ($status) { $this->_coreRegistry->register('current_status', $status); /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Magento_Sales::system_order_statuses'); $resultPage->getConfig()->getTitle()->prepend(__('Order Status')); $resultPage->getConfig()->getTitle()->prepend(__('Edit Order Status')); return $resultPage; } else { $this->messageManager->addError(__('We can\'t find this order status.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('sales/'); } }
/** * Save search query * * @return \Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { $hasError = false; $data = $this->getRequest()->getPostValue(); $queryId = $this->getRequest()->getPost('query_id', null); /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */ $redirectResult = $this->resultRedirectFactory->create(); if ($this->getRequest()->isPost() && $data) { /* @var $model \Magento\Search\Model\Query */ $model = $this->_objectManager->create('Magento\\Search\\Model\\Query'); // validate query $queryText = $this->getRequest()->getPost('query_text', false); $storeId = $this->getRequest()->getPost('store_id', false); try { if ($queryText) { $model->setStoreId($storeId); $model->loadByQueryText($queryText); if ($model->getId() && $model->getId() != $queryId) { throw new \Magento\Framework\Exception\LocalizedException(__('You already have an identical search term query.')); } elseif (!$model->getId() && $queryId) { $model->load($queryId); } } elseif ($queryId) { $model->load($queryId); } $model->addData($data); $model->setIsProcessed(0); $model->save(); $this->messageManager->addSuccess(__('You saved the search term.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $hasError = true; } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the search query.')); $hasError = true; } } if ($hasError) { $this->_getSession()->setPageData($data); return $redirectResult->setPath('search/*/edit', ['id' => $queryId]); } else { return $redirectResult->setPath('search/*'); } }
/** * Save status form processing * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $data = $this->getRequest()->getPostValue(); $isNew = $this->getRequest()->getParam('is_new'); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $statusCode = $this->getRequest()->getParam('status'); //filter tags in labels/status /** @var $filterManager \Magento\Framework\Filter\FilterManager */ $filterManager = $this->_objectManager->get('Magento\\Framework\\Filter\\FilterManager'); if ($isNew) { $statusCode = $data['status'] = $filterManager->stripTags($data['status']); } $data['label'] = $filterManager->stripTags($data['label']); foreach ($data['store_labels'] as &$label) { $label = $filterManager->stripTags($label); } $status = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Status')->load($statusCode); // check if status exist if ($isNew && $status->getStatus()) { $this->messageManager->addError(__('We found another order status with the same order status code.')); $this->_getSession()->setFormData($data); return $resultRedirect->setPath('sales/*/new'); } $status->setData($data)->setStatus($statusCode); try { $status->save(); $this->messageManager->addSuccess(__('You have saved the order status.')); return $resultRedirect->setPath('sales/*/'); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We couldn\'t add your order status because something went wrong saving.')); } $this->_getSession()->setFormData($data); if ($isNew) { return $resultRedirect->setPath('sales/*/new'); } else { return $resultRedirect->setPath('sales/*/edit', ['status' => $this->getRequest()->getParam('status')]); } } return $resultRedirect->setPath('sales/*/'); }
/** * Update product(s) status action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $productIds = (array) $this->getRequest()->getParam('product'); $storeId = (int) $this->getRequest()->getParam('store', 0); $status = (int) $this->getRequest()->getParam('status'); try { $this->_validateMassStatus($productIds, $status); $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($productIds, ['status' => $status], $storeId); $this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds))); $this->_productPriceIndexerProcessor->reindexList($productIds); } catch (\Magento\Framework\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->_getSession()->addException($e, __('Something went wrong while updating the product(s) status.')); } return $this->resultRedirectFactory->create()->setPath('catalog/*/', ['store' => $storeId]); }
/** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $id = $this->getRequest()->getParam('id'); /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */ $redirectResult = $this->resultRedirectFactory->create(); if ($id) { try { $model = $this->_objectManager->create('Magento\\Search\\Model\\Query'); $model->setId($id); $model->delete(); $this->messageManager->addSuccess(__('You deleted the search.')); return $redirectResult->setPath('search/*/'); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); return $redirectResult->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]); } } $this->messageManager->addError(__('We can\'t find a search term to delete.')); return $redirectResult->setPath('search/*/'); }