diff --git a/app/code/Magento/Contact/Block/ContactForm.php b/app/code/Magento/Contact/Block/ContactForm.php new file mode 100644 index 0000000000000..907bccb5a494b --- /dev/null +++ b/app/code/Magento/Contact/Block/ContactForm.php @@ -0,0 +1,24 @@ +_isScopePrivate = true; + } +} diff --git a/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php b/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php new file mode 100644 index 0000000000000..446279ee14ef7 --- /dev/null +++ b/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php @@ -0,0 +1,44 @@ +contextMock = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context') + ->disableOriginalConstructor() + ->getMock(); + + $this->contactForm = new ContactForm( + $this->contextMock + ); + } + + /** + * @return void + */ + public function testScope() + { + $this->assertTrue($this->contactForm->isScopePrivate()); + } +} diff --git a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml index e5e4b57692094..843206e4e00d5 100644 --- a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml +++ b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/Developer/Model/View/Layout/Plugin.php b/app/code/Magento/Developer/Model/View/Layout/Plugin.php deleted file mode 100644 index 4f4f059813d58..0000000000000 --- a/app/code/Magento/Developer/Model/View/Layout/Plugin.php +++ /dev/null @@ -1,61 +0,0 @@ -appState = $appState; - $this->logger = $logger; - } - - /** - * @param \Magento\Framework\View\Layout $subject - * @param callable $proceed - * @param string $name - * @return string - * @throws \Exception - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function aroundRenderNonCachedElement(\Magento\Framework\View\Layout $subject, \Closure $proceed, $name) - { - $result = ''; - try { - $result = $proceed($name); - } catch (\Exception $e) { - if ($this->appState->getMode() === State::MODE_DEVELOPER) { - throw $e; - } - $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage(); - $this->logger->critical($message); - } - return $result; - } -} diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index 94be2446cc140..d793eb340a284 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -10,9 +10,6 @@ - - - Magento\Developer\Model\View\Page\Config\RendererFactory diff --git a/app/code/Magento/GroupedProduct/Controller/Adminhtml/Edit/Popup.php b/app/code/Magento/GroupedProduct/Controller/Adminhtml/Edit/Popup.php index 95954e00212f9..5a46c44b01fd4 100644 --- a/app/code/Magento/GroupedProduct/Controller/Adminhtml/Edit/Popup.php +++ b/app/code/Magento/GroupedProduct/Controller/Adminhtml/Edit/Popup.php @@ -1,12 +1,18 @@ registry = $registry; $this->factory = $factory; @@ -54,7 +60,7 @@ protected function _isAllowed() /** * Get associated grouped products grid popup * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { @@ -84,8 +90,8 @@ public function execute() $product->setAttributeSetId($setId); } $this->registry->register('current_product', $product); - - $this->_view->loadLayout(false); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + return $resultLayout; } } diff --git a/app/code/Magento/GroupedProduct/Test/Unit/Controller/Adminhtml/Edit/PopupTest.php b/app/code/Magento/GroupedProduct/Test/Unit/Controller/Adminhtml/Edit/PopupTest.php index 2b25b5154679d..4daa62a813c2c 100644 --- a/app/code/Magento/GroupedProduct/Test/Unit/Controller/Adminhtml/Edit/PopupTest.php +++ b/app/code/Magento/GroupedProduct/Test/Unit/Controller/Adminhtml/Edit/PopupTest.php @@ -5,6 +5,8 @@ */ namespace Magento\GroupedProduct\Test\Unit\Controller\Adminhtml\Edit; +use Magento\Framework\Controller\ResultFactory; + class PopupTest extends \PHPUnit_Framework_TestCase { /** @@ -17,6 +19,11 @@ class PopupTest extends \PHPUnit_Framework_TestCase */ protected $action; + /** + * @var \Magento\Backend\App\Action\Context + */ + protected $context; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -33,25 +40,46 @@ class PopupTest extends \PHPUnit_Framework_TestCase protected $registry; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultFactoryMock; + + /** + * @var \Magento\Framework\View\Result\Layout|\PHPUnit_Framework_MockObject_MockObject */ - protected $view; + protected $resultLayoutMock; protected function setUp() { $this->request = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false); $this->factory = $this->getMock('Magento\Catalog\Model\ProductFactory', ['create'], [], '', false); $this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); - $this->view = $this->getMock('Magento\Framework\App\ViewInterface', [], [], '', false); + $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultLayoutMock = $this->getMockBuilder('Magento\Framework\View\Result\Layout') + ->disableOriginalConstructor() + ->getMock(); + + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->with(ResultFactory::TYPE_LAYOUT, []) + ->willReturn($this->resultLayoutMock); $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->context = $this->objectManager->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'request' => $this->request, + 'resultFactory' => $this->resultFactoryMock + ] + ); $this->action = $this->objectManager->getObject( 'Magento\GroupedProduct\Controller\Adminhtml\Edit\Popup', [ - 'request' => $this->request, + 'context' => $this->context, 'factory' => $this->factory, - 'registry' => $this->registry, - 'view' => $this->view + 'registry' => $this->registry ] ); } @@ -90,10 +118,7 @@ public function testPopupActionNoProductId() $this->request->expects($this->at(3))->method('getParam')->with('set')->will($this->returnValue($setId)); $this->registry->expects($this->once())->method('register')->with('current_product', $product); - $this->view->expects($this->once())->method('loadLayout')->with(false); - $this->view->expects($this->once())->method('renderLayout'); - - $this->action->execute(); + $this->assertSame($this->resultLayoutMock, $this->action->execute()); } public function testPopupActionWithProductIdNoSetId() @@ -130,9 +155,6 @@ public function testPopupActionWithProductIdNoSetId() $this->request->expects($this->at(3))->method('getParam')->with('set')->will($this->returnValue($setId)); $this->registry->expects($this->once())->method('register')->with('current_product', $product); - $this->view->expects($this->once())->method('loadLayout')->with(false); - $this->view->expects($this->once())->method('renderLayout'); - - $this->action->execute(); + $this->assertSame($this->resultLayoutMock, $this->action->execute()); } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export.php index b8550e267fb84..d6efeb305fb49 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export.php @@ -3,15 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +namespace Magento\ImportExport\Controller\Adminhtml; + +use Magento\Backend\App\Action; /** * Export controller - * - * @author Magento Core Team */ -namespace Magento\ImportExport\Controller\Adminhtml; - -class Export extends \Magento\Backend\App\Action +class Export extends Action { /** * Check access (in the ACL) for current user diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php index 9263327568b79..1995511a49876 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php @@ -1,52 +1,57 @@ _fileFactory = $fileFactory; + $this->fileFactory = $fileFactory; parent::__construct($context); } /** * Load data with filter applying and create file for download. * - * @return $this + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { - if ($this->getRequest()->getPost(\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP)) { + if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) { try { /** @var $model \Magento\ImportExport\Model\Export */ $model = $this->_objectManager->create('Magento\ImportExport\Model\Export'); $model->setData($this->getRequest()->getParams()); - return $this->_fileFactory->create( + return $this->fileFactory->create( $model->getFileName(), $model->export(), DirectoryList::VAR_DIR, $model->getContentType() ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); @@ -55,6 +60,9 @@ public function execute() } else { $this->messageManager->addError(__('Please correct the data sent.')); } - return $this->_redirect('adminhtml/*/index'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('adminhtml/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php index 02d22f56f3335..38296ff530dc6 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/GetFilter.php @@ -1,27 +1,29 @@ getRequest()->getParams(); if ($this->getRequest()->isXmlHttpRequest() && $data) { try { - $this->_view->loadLayout(); - + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); /** @var $attrFilterBlock \Magento\ImportExport\Block\Adminhtml\Export\Filter */ - $attrFilterBlock = $this->_view->getLayout()->getBlock('export.filter'); + $attrFilterBlock = $resultLayout->getLayout()->getBlock('export.filter'); /** @var $export \Magento\ImportExport\Model\Export */ $export = $this->_objectManager->create('Magento\ImportExport\Model\Export'); $export->setData($data); @@ -29,14 +31,16 @@ public function execute() $export->filterAttributeCollection( $attrFilterBlock->prepareCollection($export->getEntityAttributeCollection()) ); - $this->_view->renderLayout(); - return; + return $resultLayout; } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); } } else { $this->messageManager->addError(__('Please correct the data sent.')); } - $this->_redirect('adminhtml/*/index'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('adminhtml/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php index 64c5863b4203d..9b1a0c3ecbdf5 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Export/Index.php @@ -1,26 +1,28 @@ _view->loadLayout(); - $this->_setActiveMenu('Magento_ImportExport::system_convert_export'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Import/Export')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Export')); - $this->_addBreadcrumb(__('Export'), __('Export')); - - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_ImportExport::system_convert_export'); + $resultPage->getConfig()->getTitle()->prepend(__('Import/Export')); + $resultPage->getConfig()->getTitle()->prepend(__('Export')); + $resultPage->addBreadcrumb(__('Export'), __('Export')); + return $resultPage; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import.php index a8285c67d12a4..a9ea50ef17e2f 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import.php @@ -5,12 +5,12 @@ */ namespace Magento\ImportExport\Controller\Adminhtml; +use Magento\Backend\App\Action; + /** * Import controller - * - * @author Magento Core Team */ -class Import extends \Magento\Backend\App\Action +class Import extends Action { /** * Check access (in the ACL) for current user. diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php index 97319e424308f..ec4f027d4a9ac 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Index.php @@ -1,28 +1,31 @@ messageManager->addNotice( $this->_objectManager->get('Magento\ImportExport\Helper\Data')->getMaxUploadSizeMessage() ); - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_ImportExport::system_convert_import'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Import/Export')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Import')); - $this->_addBreadcrumb(__('Import'), __('Import')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_ImportExport::system_convert_import'); + $resultPage->getConfig()->getTitle()->prepend(__('Import/Export')); + $resultPage->getConfig()->getTitle()->prepend(__('Import')); + $resultPage->addBreadcrumb(__('Import'), __('Import')); + return $resultPage; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php index c513ef2cd0af3..dcded711cc100 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Start.php @@ -1,54 +1,47 @@ getRequest()->getPostValue(); if ($data) { - $this->_view->loadLayout(false); - + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); /** @var $resultBlock \Magento\ImportExport\Block\Adminhtml\Import\Frame\Result */ - $resultBlock = $this->_view->getLayout()->getBlock('import.frame.result'); + $resultBlock = $resultLayout->getLayout()->getBlock('import.frame.result'); /** @var $importModel \Magento\ImportExport\Model\Import */ $importModel = $this->_objectManager->create('Magento\ImportExport\Model\Import'); try { $importModel->importSource(); $importModel->invalidateIndex(); - $resultBlock->addAction( - 'show', - 'import_validation_container' - )->addAction( - 'innerHTML', - 'import_validation_container_header', - __('Status') - ); + $resultBlock->addAction('show', 'import_validation_container') + ->addAction('innerHTML', 'import_validation_container_header', __('Status')); } catch (\Exception $e) { $resultBlock->addError($e->getMessage()); - $this->_view->renderLayout(); - return; + return $resultLayout; } - $resultBlock->addAction( - 'hide', - ['edit_form', 'upload_button', 'messages'] - )->addSuccess( - __('Import successfully done') - ); - $this->_view->renderLayout(); - } else { - $this->_redirect('adminhtml/*/index'); + $resultBlock->addAction('hide', ['edit_form', 'upload_button', 'messages']) + ->addSuccess(__('Import successfully done')); + return $resultLayout; } + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('adminhtml/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php index b12e7efafa1ad..64e267e253b72 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php @@ -1,14 +1,18 @@ getProcessedRowsCount() == $import->getInvalidRowsCount()) { $resultBlock->addNotice(__('File is totally invalid. Please fix errors and re-upload file.')); @@ -31,8 +35,7 @@ protected function _processValidationError( if ($import->isImportAllowed()) { $resultBlock->addNotice( __( - 'Please fix errors and re-upload file or simply press "Import" button' . - ' to skip rows with errors' + 'Please fix errors and re-upload file or simply press "Import" button to skip rows with errors' ), true ); @@ -50,15 +53,16 @@ protected function _processValidationError( /** * Validate uploaded files action * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $data = $this->getRequest()->getPostValue(); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + /** @var $resultBlock \Magento\ImportExport\Block\Adminhtml\Import\Frame\Result */ + $resultBlock = $resultLayout->getLayout()->getBlock('import.frame.result'); if ($data) { - $this->_view->loadLayout(false); - /** @var $resultBlock \Magento\ImportExport\Block\Adminhtml\Import\Frame\Result */ - $resultBlock = $this->_view->getLayout()->getBlock('import.frame.result'); // common actions $resultBlock->addAction( 'show', @@ -68,13 +72,10 @@ public function execute() try { /** @var $import \Magento\ImportExport\Model\Import */ $import = $this->_objectManager->create('Magento\ImportExport\Model\Import')->setData($data); - $source = \Magento\ImportExport\Model\Import\Adapter::findAdapterFor( + $source = ImportAdapter::findAdapterFor( $import->uploadSource(), - $this->_objectManager->create( - 'Magento\Framework\Filesystem' - )->getDirectoryWrite( - DirectoryList::ROOT - ) + $this->_objectManager->create('Magento\Framework\Filesystem') + ->getDirectoryWrite(DirectoryList::ROOT) ); $validationResult = $import->validateSource($source); @@ -82,7 +83,7 @@ public function execute() $resultBlock->addError(__('File does not contain data. Please upload another one')); } else { if (!$validationResult) { - $this->_processValidationError($import, $resultBlock); + $this->processValidationError($import, $resultBlock); } else { if ($import->isImportAllowed()) { $resultBlock->addSuccess( @@ -107,15 +108,15 @@ public function execute() } catch (\Exception $e) { $resultBlock->addNotice(__('Please fix errors and re-upload file.'))->addError($e->getMessage()); } - $this->_view->renderLayout(); + return $resultLayout; } elseif ($this->getRequest()->isPost() && empty($_FILES)) { - $this->_view->loadLayout(false); - $resultBlock = $this->_view->getLayout()->getBlock('import.frame.result'); $resultBlock->addError(__('File was not uploaded')); - $this->_view->renderLayout(); - } else { - $this->messageManager->addError(__('Data is invalid or file is not uploaded')); - $this->_redirect('adminhtml/*/index'); + return $resultLayout; } + $this->messageManager->addError(__('Data is invalid or file is not uploaded')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('adminhtml/*/index'); + return $resultRedirect; } } diff --git a/app/code/Magento/ProductAlert/Controller/Add.php b/app/code/Magento/ProductAlert/Controller/Add.php index b40a0f91d2e3a..84e5f47fe8b6d 100644 --- a/app/code/Magento/ProductAlert/Controller/Add.php +++ b/app/code/Magento/ProductAlert/Controller/Add.php @@ -5,40 +5,42 @@ */ namespace Magento\ProductAlert\Controller; +use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; +use Magento\Customer\Model\Session as CustomerSession; use Magento\Framework\App\RequestInterface; -class Add extends \Magento\Framework\App\Action\Action +class Add extends Action { /** * @var \Magento\Customer\Model\Session */ - protected $_customerSession; + protected $customerSession; /** - * @param Context $context + * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession */ public function __construct( Context $context, - \Magento\Customer\Model\Session $customerSession + CustomerSession $customerSession ) { - $this->_customerSession = $customerSession; + $this->customerSession = $customerSession; parent::__construct($context); } /** * Check customer authentication for some actions * - * @param RequestInterface $request + * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { - if (!$this->_customerSession->authenticate($this)) { + if (!$this->customerSession->authenticate($this)) { $this->_actionFlag->set('', 'no-dispatch', true); - if (!$this->_customerSession->getBeforeUrl()) { - $this->_customerSession->setBeforeUrl($this->_redirect->getRefererUrl()); + if (!$this->customerSession->getBeforeUrl()) { + $this->customerSession->setBeforeUrl($this->_redirect->getRefererUrl()); } } return parent::dispatch($request); diff --git a/app/code/Magento/ProductAlert/Controller/Add/Price.php b/app/code/Magento/ProductAlert/Controller/Add/Price.php index 5a9fdd0e38d1d..9e1a6d21fb270 100644 --- a/app/code/Magento/ProductAlert/Controller/Add/Price.php +++ b/app/code/Magento/ProductAlert/Controller/Add/Price.php @@ -1,39 +1,47 @@ _storeManager = $storeManager; + $this->storeManager = $storeManager; $this->productRepository = $productRepository; + parent::__construct($context, $customerSession); } /** @@ -42,61 +50,57 @@ public function __construct( * @param string $url * @return bool */ - protected function _isInternal($url) + protected function isInternal($url) { if (strpos($url, 'http') === false) { return false; } - $currentStore = $this->_storeManager->getStore(); - return strpos( - $url, - $currentStore->getBaseUrl() - ) === 0 || strpos( - $url, - $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true) - ) === 0; + $currentStore = $this->storeManager->getStore(); + return strpos($url, $currentStore->getBaseUrl()) === 0 + || strpos($url, $currentStore->getBaseUrl(UrlInterface::URL_TYPE_LINK, true)) === 0; } /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { - $backUrl = $this->getRequest()->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED); + $backUrl = $this->getRequest()->getParam(Action::PARAM_NAME_URL_ENCODED); $productId = (int)$this->getRequest()->getParam('product_id'); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$backUrl || !$productId) { - $this->_redirect('/'); - return; + $resultRedirect->setPath('/'); + return $resultRedirect; } try { + /* @var $product \Magento\Catalog\Model\Product */ $product = $this->productRepository->getById($productId); - - $model = $this->_objectManager->create( - 'Magento\ProductAlert\Model\Price' - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->setProductId( - $product->getId() - )->setPrice( - $product->getFinalPrice() - )->setWebsiteId( - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); + /** @var \Magento\ProductAlert\Model\Price $model */ + $model = $this->_objectManager->create('Magento\ProductAlert\Model\Price') + ->setCustomerId($this->customerSession->getCustomerId()) + ->setProductId($product->getId()) + ->setPrice($product->getFinalPrice()) + ->setWebsiteId( + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ); $model->save(); $this->messageManager->addSuccess(__('You saved the alert subscription.')); } catch (NoSuchEntityException $noEntityException) { - /* @var $product \Magento\Catalog\Model\Product */ $this->messageManager->addError(__('There are not enough parameters.')); - if ($this->_isInternal($backUrl)) { - $this->getResponse()->setRedirect($backUrl); + if ($this->isInternal($backUrl)) { + $resultRedirect->setUrl($backUrl); } else { - $this->_redirect('/'); + $resultRedirect->setPath('/'); } - return; + return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addException($e, __('Unable to update the alert subscription.')); } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); + $resultRedirect->setUrl($this->_redirect->getRedirectUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/ProductAlert/Controller/Add/Stock.php b/app/code/Magento/ProductAlert/Controller/Add/Stock.php index 3e47cd66b2527..c0a5ff8801c72 100644 --- a/app/code/Magento/ProductAlert/Controller/Add/Stock.php +++ b/app/code/Magento/ProductAlert/Controller/Add/Stock.php @@ -1,16 +1,23 @@ productRepository = $productRepository; + parent::__construct($context, $customerSession); } /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { - $backUrl = $this->getRequest()->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED); + $backUrl = $this->getRequest()->getParam(Action::PARAM_NAME_URL_ENCODED); $productId = (int)$this->getRequest()->getParam('product_id'); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$backUrl || !$productId) { - $this->_redirect('/'); - return; + $resultRedirect->setPath('/'); + return $resultRedirect; } try { + /* @var $product \Magento\Catalog\Model\Product */ $product = $this->productRepository->getById($productId); - - $model = $this->_objectManager->create( - 'Magento\ProductAlert\Model\Stock' - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->setProductId( - $product->getId() - )->setWebsiteId( - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); + /** @var \Magento\ProductAlert\Model\Stock $model */ + $model = $this->_objectManager->create('Magento\ProductAlert\Model\Stock') + ->setCustomerId($this->customerSession->getCustomerId()) + ->setProductId($product->getId()) + ->setWebsiteId( + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ); $model->save(); $this->messageManager->addSuccess(__('Alert subscription has been saved.')); } catch (NoSuchEntityException $noEntityException) { - /* @var $product \Magento\Catalog\Model\Product */ $this->messageManager->addError(__('There are not enough parameters.')); - $this->getResponse()->setRedirect($backUrl); - return; + $resultRedirect->setUrl($backUrl); + return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addException($e, __('Unable to update the alert subscription.')); } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); + $resultRedirect->setUrl($this->_redirect->getRedirectUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php b/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php index d02f720a9eaf2..a7d28f45b0d05 100644 --- a/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php +++ b/app/code/Magento/ProductAlert/Controller/Add/TestObserver.php @@ -1,19 +1,22 @@ _objectManager->get('Magento\ProductAlert\Model\Observer'); $observer->process($object); } diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/Price.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/Price.php index 8d6b92fd56fc2..0f2c5334a099d 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/Price.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/Price.php @@ -1,16 +1,22 @@ productRepository = $productRepository; + parent::__construct($context, $customerSession); } /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { $productId = (int)$this->getRequest()->getParam('product'); - + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$productId) { - $this->_redirect(''); - return; + $resultRedirect->setPath('/'); + return $resultRedirect; } try { + /* @var $product \Magento\Catalog\Model\Product */ $product = $this->productRepository->getById($productId); if (!$product->isVisibleInCatalog()) { throw new NoSuchEntityException(); } - - $model = $this->_objectManager->create( - 'Magento\ProductAlert\Model\Price' - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->setProductId( - $product->getId() - )->setWebsiteId( - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - )->loadByParam(); + /** @var \Magento\ProductAlert\Model\Price $model */ + $model = $this->_objectManager->create('Magento\ProductAlert\Model\Price') + ->setCustomerId($this->customerSession->getCustomerId()) + ->setProductId($product->getId()) + ->setWebsiteId( + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ) + ->loadByParam(); if ($model->getId()) { $model->delete(); } $this->messageManager->addSuccess(__('You deleted the alert subscription.')); } catch (NoSuchEntityException $noEntityException) { - /* @var $product \Magento\Catalog\Model\Product */ $this->messageManager->addError(__('We can\'t find the product.')); - $this->_redirect('customer/account/'); - return; + $resultRedirect->setPath('customer/account/'); + return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addException($e, __('Unable to update the alert subscription.')); } - $this->getResponse()->setRedirect($product->getProductUrl()); + $resultRedirect->setUrl($product->getProductUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php index e2b9bf759f64b..dd935f6d85c1b 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php @@ -1,24 +1,26 @@ _objectManager->create( - 'Magento\ProductAlert\Model\Price' - )->deleteCustomer( - $this->_customerSession->getCustomerId(), - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); + $this->_objectManager->create('Magento\ProductAlert\Model\Price') + ->deleteCustomer( + $this->customerSession->getCustomerId(), + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ); $this->messageManager->addSuccess(__('You will no longer receive price alerts for this product.')); return $this->getDefaultResult(); diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/Stock.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/Stock.php index 2d29c9993fc18..703bb606f1687 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/Stock.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/Stock.php @@ -1,16 +1,22 @@ productRepository = $productRepository; + parent::__construct($context, $customerSession); } /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { $productId = (int)$this->getRequest()->getParam('product'); - + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$productId) { - $this->_redirect(''); - return; + $resultRedirect->setPath('/'); + return $resultRedirect; } try { @@ -45,26 +52,27 @@ public function execute() throw new NoSuchEntityException(); } - $model = $this->_objectManager->create( - 'Magento\ProductAlert\Model\Stock' - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->setProductId( - $product->getId() - )->setWebsiteId( - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - )->loadByParam(); + $model = $this->_objectManager->create('Magento\ProductAlert\Model\Stock') + ->setCustomerId($this->customerSession->getCustomerId()) + ->setProductId($product->getId()) + ->setWebsiteId( + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ) + ->loadByParam(); if ($model->getId()) { $model->delete(); } $this->messageManager->addSuccess(__('You will no longer receive stock alerts for this product.')); } catch (NoSuchEntityException $noEntityException) { $this->messageManager->addError(__('The product was not found.')); - $this->_redirect('customer/account/'); - return; + $resultRedirect->setPath('customer/account/'); + return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addException($e, __('Unable to update the alert subscription.')); } - $this->getResponse()->setRedirect($product->getProductUrl()); + $resultRedirect->setUrl($product->getProductUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php index c8dec914e9540..c9a348cb212fd 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php @@ -1,24 +1,26 @@ _objectManager->create( - 'Magento\ProductAlert\Model\Stock' - )->deleteCustomer( - $this->_customerSession->getCustomerId(), - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); + $this->_objectManager->create('Magento\ProductAlert\Model\Stock') + ->deleteCustomer( + $this->customerSession->getCustomerId(), + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface') + ->getStore() + ->getWebsiteId() + ); $this->messageManager->addSuccess(__('You will no longer receive stock alerts.')); return $this->getDefaultResult(); diff --git a/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php deleted file mode 100644 index 9d2cde108b310..0000000000000 --- a/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php +++ /dev/null @@ -1,137 +0,0 @@ - - */ -class Grid extends \Magento\Backend\Block\Widget\Grid\Extended -{ - /** - * @var \Magento\Reports\Model\Resource\Product\CollectionFactory - */ - protected $_collectionFactory; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param \Magento\Reports\Model\Resource\Product\CollectionFactory $collectionFactory - * @param array $data - */ - public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - \Magento\Reports\Model\Resource\Product\CollectionFactory $collectionFactory, - array $data = [] - ) { - $this->_collectionFactory = $collectionFactory; - parent::__construct($context, $backendHelper, $data); - } - - /** - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('productsReportGrid'); - $this->setDefaultSort('entity_id'); - $this->setDefaultDir('desc'); - } - - /** - * @return \Magento\Backend\Block\Widget\Grid - */ - protected function _prepareCollection() - { - $collection = $this->_collectionFactory->create(); - $collection->getEntity()->setStore(0); - - $this->setCollection($collection); - - return parent::_prepareCollection(); - } - - /** - * @return void - */ - protected function _afterLoadCollection() - { - $totalObj = new \Magento\Reports\Model\Totals(); - $this->setTotals($totalObj->countTotals($this)); - } - - /** - * @return \Magento\Backend\Block\Widget\Grid\Extended - */ - protected function _prepareColumns() - { - $this->addColumn( - 'entity_id', - ['header' => __('ID'), 'width' => '50px', 'index' => 'entity_id', 'total' => 'Total'] - ); - - $this->addColumn('name', ['header' => __('Name'), 'index' => 'name']); - - $this->addColumn( - 'viewed', - [ - 'header' => __('Viewed'), - 'width' => '50px', - 'align' => 'right', - 'index' => 'viewed', - 'total' => 'sum' - ] - ); - - $this->addColumn( - 'added', - ['header' => __('Added'), 'width' => '50px', 'align' => 'right', 'index' => 'added', 'total' => 'sum'] - ); - - $this->addColumn( - 'purchased', - [ - 'header' => __('Purchased'), - 'width' => '50px', - 'align' => 'right', - 'index' => 'purchased', - 'total' => 'sum' - ] - ); - - $this->addColumn( - 'fulfilled', - [ - 'header' => __('Fulfilled'), - 'width' => '50px', - 'align' => 'right', - 'index' => 'fulfilled', - 'total' => 'sum' - ] - ); - - $this->addColumn( - 'revenue', - [ - 'header' => __('Revenue'), - 'width' => '50px', - 'align' => 'right', - 'index' => 'revenue', - 'total' => 'sum' - ] - ); - - $this->setCountTotals(true); - - $this->addExportType('*/*/exportProductsCsv', __('CSV')); - $this->addExportType('*/*/exportProductsExcel', __('Excel XML')); - - return parent::_prepareColumns(); - } -} diff --git a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php index d40166dff4bb5..59d5cef6ac745 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php @@ -8,6 +8,8 @@ /** * Adminhtml abandoned shopping carts report grid block * + * @method \Magento\Reports\Model\Resource\Quote\Collection getCollection + * * @author Magento Core Team * @SuppressWarnings(PHPMD.DepthOfInheritance) */ diff --git a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php index 347405789dc2e..53044f15068e6 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php @@ -16,7 +16,7 @@ class Grid extends \Magento\Reports\Block\Adminhtml\Grid\Shopcart /** * @var \Magento\Reports\Model\Resource\Quote\CollectionFactory */ - protected $_quotesFactory; + protected $quoteItemCollectionFactory; /** * @var \Magento\Quote\Model\QueryResolver @@ -26,18 +26,18 @@ class Grid extends \Magento\Reports\Block\Adminhtml\Grid\Shopcart /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Backend\Helper\Data $backendHelper - * @param \Magento\Reports\Model\Resource\Quote\CollectionFactoryInterface $quotesFactory + * @param \Magento\Reports\Model\Resource\Quote\Item\CollectionFactory $quoteItemCollectionFactory * @param \Magento\Quote\Model\QueryResolver $queryResolver * @param array $data */ public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, - \Magento\Reports\Model\Resource\Quote\CollectionFactoryInterface $quotesFactory, \Magento\Quote\Model\QueryResolver $queryResolver, + \Magento\Reports\Model\Resource\Quote\Item\CollectionFactory $quoteItemCollectionFactory, array $data = [] ) { - $this->_quotesFactory = $quotesFactory; + $this->quoteItemCollectionFactory = $quoteItemCollectionFactory; $this->queryResolver = $queryResolver; parent::__construct($context, $backendHelper, $data); } @@ -56,7 +56,8 @@ protected function _construct() */ protected function _prepareCollection() { - $collection = $this->_quotesFactory->create(); + /** @var \Magento\Reports\Model\Resource\Quote\Item\Collection $collection */ + $collection = $this->quoteItemCollectionFactory->create(); $collection->prepareActiveCartItems(); $this->setCollection($collection); return parent::_prepareCollection(); @@ -68,11 +69,11 @@ protected function _prepareCollection() protected function _prepareColumns() { $this->addColumn( - 'entity_id', + 'product_id', [ 'header' => __('ID'), 'align' => 'right', - 'index' => 'entity_id', + 'index' => 'product_id', 'sortable' => false, 'header_css_class' => 'col-id', 'column_css_class' => 'col-id' @@ -146,6 +147,6 @@ protected function _prepareColumns() */ public function getRowUrl($row) { - return $this->getUrl('catalog/product/edit', ['id' => $row->getEntityId()]); + return $this->getUrl('catalog/product/edit', ['id' => $row->getProductId()]); } } diff --git a/app/code/Magento/Reports/Model/Resource/Order/Collection.php b/app/code/Magento/Reports/Model/Resource/Order/Collection.php index 0dd3a60c83761..17ff425618942 100644 --- a/app/code/Magento/Reports/Model/Resource/Order/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Order/Collection.php @@ -900,8 +900,8 @@ public function addCreateAtPeriodFilter($period) $this->addFieldToFilter( $fieldToFilter, [ - 'from' => $from->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT), - 'to' => $to->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + 'from' => $from->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), + 'to' => $to->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) ] ); diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php index ea190558cac88..fc5ed24362727 100644 --- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php @@ -3,96 +3,35 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - -/** - * Reports quote collection - * - * @author Magento Core Team - */ namespace Magento\Reports\Model\Resource\Quote; -/** - * Class Collection - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ class Collection extends \Magento\Quote\Model\Resource\Quote\Collection { - const SELECT_COUNT_SQL_TYPE_CART = 1; - - /** - * @var int - */ - protected $_selectCountSqlType = 0; - - /** - * Join fields - * - * @var array - */ - protected $_joinedFields = []; - - /** - * Map - * - * @var array - */ - protected $_map = ['fields' => ['store_id' => 'main_table.store_id']]; - - /** - * @var \Magento\Catalog\Model\Resource\Product\Collection - */ - protected $productResource; - /** * @var \Magento\Customer\Model\Resource\Customer */ protected $customerResource; /** - * @var \Magento\Sales\Model\Resource\Order\Collection - */ - protected $orderResource; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory + * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Catalog\Model\Resource\Product\Collection $productResource * @param \Magento\Customer\Model\Resource\Customer $customerResource - * @param \Magento\Sales\Model\Resource\Order\Collection $orderResource - * @param null $connection + * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, + \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Catalog\Model\Resource\Product\Collection $productResource, \Magento\Customer\Model\Resource\Customer $customerResource, - \Magento\Sales\Model\Resource\Order\Collection $orderResource, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); - $this->productResource = $productResource; $this->customerResource = $customerResource; - $this->orderResource = $orderResource; - } - - /** - * Set type for COUNT SQL select - * - * @param int $type - * @return $this - */ - public function setSelectCountSqlType($type) - { - $this->_selectCountSqlType = $type; - return $this; } /** @@ -129,89 +68,6 @@ public function prepareForAbandonedReport($storeIds, $filter = null) return $this; } - /** - * Prepare select query for products in carts report - * - * @return \Magento\Framework\DB\Select - */ - public function prepareActiveCartItems() - { - $quoteItemsSelect = $this->getSelect(); - $quoteItemsSelect->reset() - ->from(['main_table' => $this->getTable('quote')], '') - ->columns('quote_items.product_id') - ->columns(['carts' => new \Zend_Db_Expr('COUNT(quote_items.item_id)')]) - ->columns('main_table.base_to_global_rate') - ->joinInner( - ['quote_items' => $this->getTable('quote_item')], - 'quote_items.quote_id = main_table.entity_id', - null - )->where( - 'main_table.is_active = ?', - 1 - )->group( - 'quote_items.product_id' - ); - - return $quoteItemsSelect; - } - - /** - * Orders quantity data - * - * @param array $productIds - * @return array - */ - protected function getOrdersData(array $productIds) - { - $ordersSubSelect = clone $this->orderResource->getSelect(); - $ordersSubSelect->reset()->from( - ['oi' => $this->getTable('sales_order_item')], - ['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')] - )->where('oi.product_id IN (?)', $productIds)->group( - 'oi.product_id' - ); - - return $this->orderResource->getConnection()->fetchAssoc($ordersSubSelect); - } - - /** - * Add store ids to filter - * - * @param array $storeIds - * @return $this - */ - public function addStoreFilter($storeIds) - { - $this->addFieldToFilter('store_id', ['in' => $storeIds]); - return $this; - } - - /** - * Add customer data - * - * @param array|null $filter - * @return $this - */ - public function addCustomerData($filter = null) - { - $customersSelect = $this->customerResource->getReadConnection()->select(); - $customersSelect->from(['customer' => 'customer_entity'], 'entity_id'); - if (isset($filter['customer_name'])) { - $customersSelect = $this->getCustomerNames($customersSelect); - $customerName = $customersSelect->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' '); - $customersSelect->where( - $customerName . ' LIKE ?', '%' . $filter['customer_name'] . '%' - ); - } - if (isset($filter['email'])) { - $customersSelect->where('customer.email LIKE ?', '%' . $filter['email'] . '%'); - } - $filteredCustomers = $this->customerResource->getReadConnection()->fetchCol($customersSelect); - $this->getSelect()->where('main_table.customer_id IN (?)', $filteredCustomers); - return $this; - } - /** * Add subtotals * @@ -225,7 +81,8 @@ public function addSubtotal($storeIds = '', $filter = null) $this->getSelect()->columns( ['subtotal' => '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'] ); - $this->_joinedFields['subtotal'] = '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'; + $this->_joinedFields['subtotal'] = + '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'; } else { $this->getSelect()->columns(['subtotal' => 'main_table.base_subtotal_with_discount']); $this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount'; @@ -252,17 +109,32 @@ public function addSubtotal($storeIds = '', $filter = null) } /** - * Get select count sql + * Resolve customers data based on ids quote table. * - * @return \Magento\Framework\DB\Select + * @return void */ - public function getSelectCountSql() + public function resolveCustomerNames() { - $countSelect = clone $this->prepareActiveCartItems(); - $countSelect->reset(\Zend_Db_Select::COLUMNS) - ->reset(\Zend_Db_Select::GROUP) - ->columns('COUNT(DISTINCT quote_items.product_id)'); - return $countSelect; + $select = $this->customerResource->getReadConnection()->select(); + $customerName = $select->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' '); + + $select->from( + ['customer' => $this->customerResource->getTable('customer_entity')] + )->columns( + ['customer_name' => $customerName] + )->where( + 'customer.entity_id IN (?)', + array_column( + $this->getData(), + 'customer_id' + ) + ); + $customersData = $select->getAdapter()->fetchAll($this->getCustomerNames($select)); + + foreach ($this->getItems() as $item) { + $item->setData(array_merge($item->getData(), current($customersData))); + next($customersData); + } } /** @@ -286,100 +158,12 @@ protected function getCustomerNames($select) 'customer.entity_id = cust_lname.entity_id', ['lastname' => 'cust_lname.value'] )->where( - 'cust_fname.attribute_id = ?', (int)$attrFirstnameId + 'cust_fname.attribute_id = ?', + (int)$attrFirstnameId )->where( - 'cust_lname.attribute_id = ?', (int)$attrLastnameId + 'cust_lname.attribute_id = ?', + (int)$attrLastnameId ); return $select; } - - /** - * Resolve customers data based on ids quote table. - * - * @return void - */ - public function resolveCustomerNames() - { - $select = $this->customerResource->getReadConnection()->select(); - $customerName = $select->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' '); - - $select->from( - ['customer' => 'customer_entity'] - )->columns( - ['customer_name' => $customerName] - )->where( - 'customer.entity_id IN (?)', array_column($this->getData(), 'customer_id') - ); - $customersData = $select->getAdapter()->fetchAll($this->getCustomerNames($select)); - - foreach($this->getItems() as $item) { - $item->setData(array_merge($item->getData(), current($customersData))); - next($customersData); - } - } - - /** - * Separate query for product and order data - * - * @param array $productIds - * @return array - * @throws \Magento\Framework\Exception\LocalizedException - */ - protected function getProductData(array $productIds) - { - $productConnection = $this->productResource->getConnection('read'); - $productAttrName = $this->productResource->getAttribute('name'); - $productAttrNameId = (int)$productAttrName->getAttributeId(); - $productAttrPrice = $this->productResource->getAttribute('price'); - $productAttrPriceId = (int)$productAttrPrice->getAttributeId(); - - $select = clone $this->productResource->getSelect(); - $select->reset(); - $select->from( - ['main_table' => $this->getTable('catalog_product_entity')] - )->useStraightJoin( - true - )->joinInner( - ['product_name' => $productAttrName->getBackend()->getTable()], - 'product_name.entity_id = main_table.entity_id' - . ' AND product_name.attribute_id = ' . $productAttrNameId - . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, - ['name' => 'product_name.value'] - )->joinInner( - ['product_price' => $productAttrPrice->getBackend()->getTable()], - "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}", - ['price' => new \Zend_Db_Expr('product_price.value')] - )->where('main_table.entity_id IN (?)', $productIds); - - $productData = $productConnection->fetchAssoc($select); - return $productData; - } - - /** - * Add data fetched from another database - * - * @return $this - */ - protected function _afterLoad() - { - parent::_afterLoad(); - $items = $this->getItems(); - $productIds = []; - foreach ($items as $item) { - $productIds[] = $item->getProductId(); - } - $productData = $this->getProductData($productIds); - $orderData = $this->getOrdersData($productIds); - foreach ($items as $item) { - $item->setId($item->getProductId()); - $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate()); - $item->setName($productData[$item->getProductId()]['name']); - $item->setOrders(0); - if (isset($orderData[$item->getProductId()])) { - $item->setOrders($orderData[$item->getProductId()]['orders']); - } - } - - return $this; - } } diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php new file mode 100644 index 0000000000000..63c1a45f5132c --- /dev/null +++ b/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php @@ -0,0 +1,227 @@ + ['store_id' => 'main_table.store_id']]; + + /** + * @var \Magento\Catalog\Model\Resource\Product\Collection + */ + protected $productResource; + + /** + * @var \Magento\Customer\Model\Resource\Customer + */ + protected $customerResource; + + /** + * @var \Magento\Sales\Model\Resource\Order\Collection + */ + protected $orderResource; + + /** + * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory + * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Catalog\Model\Resource\Product\Collection $productResource + * @param \Magento\Customer\Model\Resource\Customer $customerResource + * @param \Magento\Sales\Model\Resource\Order\Collection $orderResource + * @param \Zend_Db_Adapter_Abstract $connection + * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource + */ + public function __construct( + \Magento\Framework\Data\Collection\EntityFactory $entityFactory, + \Psr\Log\LoggerInterface $logger, + \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Catalog\Model\Resource\Product\Collection $productResource, + \Magento\Customer\Model\Resource\Customer $customerResource, + \Magento\Sales\Model\Resource\Order\Collection $orderResource, + $connection = null, + \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null + ) { + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $connection, + $resource + ); + $this->productResource = $productResource; + $this->customerResource = $customerResource; + $this->orderResource = $orderResource; + } + + /** + * Resource initialization + * + * @return void + */ + protected function _construct() + { + $this->_init('Magento\Quote\Model\Quote\Item', 'Magento\Quote\Model\Resource\Quote\Item'); + } + + + /** + * Prepare select query for products in carts report + * + * @return \Magento\Framework\DB\Select + */ + public function prepareActiveCartItems() + { + $quoteItemsSelect = $this->getSelect(); + $quoteItemsSelect->reset() + ->from(['main_table' => $this->getTable('quote_item')], '') + ->columns('main_table.product_id') + ->columns(['carts' => new \Zend_Db_Expr('COUNT(main_table.item_id)')]) + ->columns('quote.base_to_global_rate') + ->joinInner( + ['quote' => $this->getTable('quote')], + 'main_table.quote_id = quote.entity_id', + null + )->where( + 'quote.is_active = ?', + 1 + )->group( + 'main_table.product_id' + ); + + return $quoteItemsSelect; + } + + /** + * Orders quantity data + * + * @param array $productIds + * @return array + */ + protected function getOrdersData(array $productIds) + { + $ordersSubSelect = clone $this->orderResource->getSelect(); + $ordersSubSelect->reset()->from( + ['oi' => $this->getTable('sales_order_item')], + ['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')] + )->where('oi.product_id IN (?)', $productIds)->group( + 'oi.product_id' + ); + + return $this->orderResource->getConnection()->fetchAssoc($ordersSubSelect); + } + + /** + * Add store ids to filter + * + * @param array $storeIds + * @return $this + */ + public function addStoreFilter($storeIds) + { + $this->addFieldToFilter('store_id', ['in' => $storeIds]); + return $this; + } + + /** + * Get select count sql + * + * @return \Magento\Framework\DB\Select + */ + public function getSelectCountSql() + { + $countSelect = clone $this->prepareActiveCartItems(); + $countSelect->reset(\Zend_Db_Select::COLUMNS) + ->reset(\Zend_Db_Select::GROUP) + ->columns('COUNT(DISTINCT main_table.product_id)'); + return $countSelect; + } + + /** + * Separate query for product and order data + * + * @param array $productIds + * @return array + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function getProductData(array $productIds) + { + $productConnection = $this->productResource->getConnection('read'); + $productAttrName = $this->productResource->getAttribute('name'); + $productAttrNameId = (int)$productAttrName->getAttributeId(); + $productAttrPrice = $this->productResource->getAttribute('price'); + $productAttrPriceId = (int)$productAttrPrice->getAttributeId(); + + $select = clone $this->productResource->getSelect(); + $select->reset(); + $select->from( + ['main_table' => $this->getTable('catalog_product_entity')] + )->useStraightJoin( + true + )->joinInner( + ['product_name' => $productAttrName->getBackend()->getTable()], + 'product_name.entity_id = main_table.entity_id' + . ' AND product_name.attribute_id = ' . $productAttrNameId + . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, + ['name' => 'product_name.value'] + )->joinInner( + ['product_price' => $productAttrPrice->getBackend()->getTable()], + "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}", + ['price' => new \Zend_Db_Expr('product_price.value')] + )->where('main_table.entity_id IN (?)', $productIds); + + $productData = $productConnection->fetchAssoc($select); + return $productData; + } + + /** + * Add data fetched from another database + * + * @return $this + */ + protected function _afterLoad() + { + parent::_afterLoad(); + $items = $this->getItems(); + $productIds = []; + foreach ($items as $item) { + $productIds[] = $item->getProductId(); + } + $productData = $this->getProductData($productIds); + $orderData = $this->getOrdersData($productIds); + foreach ($items as $item) { + $item->setId($item->getProductId()); + $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate()); + $item->setName($productData[$item->getProductId()]['name']); + $item->setOrders(0); + if (isset($orderData[$item->getProductId()])) { + $item->setOrders($orderData[$item->getProductId()]['orders']); + } + } + + return $this; + } +} diff --git a/app/code/Magento/Reports/Model/Resource/Report/Collection.php b/app/code/Magento/Reports/Model/Resource/Report/Collection.php index c8ee5836cf242..641b5704a92e0 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Report/Collection.php @@ -174,7 +174,7 @@ protected function _getDayInterval(\DateTime $dateStart) \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE ), - 'start' => $dateStart->format('Y-m-d H:i:s'), + 'start' => $dateStart->format('Y-m-d 00:00:00'), 'end' => $dateStart->format('Y-m-d 23:59:59'), ]; return $interval; diff --git a/app/code/Magento/Reports/Model/Totals.php b/app/code/Magento/Reports/Model/Totals.php deleted file mode 100644 index 75fbaaed53317..0000000000000 --- a/app/code/Magento/Reports/Model/Totals.php +++ /dev/null @@ -1,76 +0,0 @@ - - */ -class Totals -{ - /** - * Retrieve count totals - * - * @param \Magento\Backend\Block\Widget\Grid $grid - * @param string $from - * @param string $to - * @return \Magento\Framework\Object - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - public function countTotals($grid, $from, $to) - { - $columns = []; - foreach ($grid->getColumns() as $col) { - $columns[$col->getIndex()] = ["total" => $col->getTotal(), "value" => 0]; - } - - $count = 0; - /** - * This method doesn't work because of commit 6e15235, see MAGETWO-4751 - */ - $report = $grid->getCollection()->getReportFull($from, $to); - foreach ($report as $item) { - if ($grid->getSubReportSize() && $count >= $grid->getSubReportSize()) { - continue; - } - $data = $item->getData(); - - foreach ($columns as $field => $a) { - if ($field !== '') { - $columns[$field]['value'] = $columns[$field]['value'] + (isset($data[$field]) ? $data[$field] : 0); - } - } - $count++; - } - $data = []; - foreach ($columns as $field => $a) { - if ($a['total'] == 'avg') { - if ($field !== '') { - if ($count != 0) { - $data[$field] = $a['value'] / $count; - } else { - $data[$field] = 0; - } - } - } elseif ($a['total'] == 'sum') { - if ($field !== '') { - $data[$field] = $a['value']; - } - } elseif (strpos($a['total'], '/') !== false) { - if ($field !== '') { - $data[$field] = 0; - } - } - } - - $totals = new \Magento\Framework\Object(); - $totals->setData($data); - - return $totals; - } -} diff --git a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php index d3b7eadd6da68..9e9363ce7bfd0 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php @@ -33,17 +33,17 @@ public function testGetSelectCountSql() ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection'); $collection = $this->getMock( 'Magento\Reports\Model\Resource\Quote\Collection', - ['prepareActiveCartItems', 'getSelect'], + ['getSelect'], $constructArgs, '', false ); - $collection->expects($this->once())->method('prepareActiveCartItems')->willReturn($this->selectMock); + $collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock); $this->selectMock->expects($this->atLeastOnce())->method('reset')->willReturnSelf(); $this->selectMock->expects($this->once()) ->method('columns') - ->with('COUNT(DISTINCT quote_items.product_id)') + ->with('COUNT(*)') ->willReturnSelf(); $this->assertEquals($this->selectMock, $collection->getSelectCountSql()); } @@ -52,9 +52,9 @@ public function testPrepareActiveCartItems() { /** @var $collection \PHPUnit_Framework_MockObject_MockObject */ $constructArgs = $this->objectManager - ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection'); + ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Item\Collection'); $collection = $this->getMock( - 'Magento\Reports\Model\Resource\Quote\Collection', + 'Magento\Reports\Model\Resource\Quote\Item\Collection', ['getSelect', 'getTable'], $constructArgs, '', @@ -76,7 +76,7 @@ public function testLoadWithFilter() { /** @var $collection \PHPUnit_Framework_MockObject_MockObject */ $constructArgs = $this->objectManager - ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection'); + ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Item\Collection'); $constructArgs['eventManager'] = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); $readConnectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false); $resourceMock = $this->getMock('\Magento\Quote\Model\Resource\Quote', [], [], '', false); @@ -87,7 +87,7 @@ public function testLoadWithFilter() $constructArgs['orderResource'] = $orderResourceMock; $collection = $this->getMock( - 'Magento\Reports\Model\Resource\Quote\Collection', + 'Magento\Reports\Model\Resource\Quote\Item\Collection', [ '_beforeLoad', '_renderFilters', diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product.php b/app/code/Magento/Review/Controller/Adminhtml/Product.php index 2c6d34056f332..fcb0c4e648857 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product.php @@ -5,10 +5,16 @@ */ namespace Magento\Review\Controller\Adminhtml; +use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; +use Magento\Review\Model\ReviewFactory; +use Magento\Review\Model\RatingFactory; + /** * Reviews admin controller */ -class Product extends \Magento\Backend\App\Action +class Product extends Action { /** * Array of actions which can be processed without secret key validation @@ -22,21 +28,21 @@ class Product extends \Magento\Backend\App\Action * * @var \Magento\Framework\Registry */ - protected $_coreRegistry = null; + protected $coreRegistry = null; /** * Review model factory * * @var \Magento\Review\Model\ReviewFactory */ - protected $_reviewFactory; + protected $reviewFactory; /** * Rating model factory * * @var \Magento\Review\Model\RatingFactory */ - protected $_ratingFactory; + protected $ratingFactory; /** * @param \Magento\Backend\App\Action\Context $context @@ -45,14 +51,14 @@ class Product extends \Magento\Backend\App\Action * @param \Magento\Review\Model\RatingFactory $ratingFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, - \Magento\Review\Model\ReviewFactory $reviewFactory, - \Magento\Review\Model\RatingFactory $ratingFactory + Context $context, + Registry $coreRegistry, + ReviewFactory $reviewFactory, + RatingFactory $ratingFactory ) { - $this->_coreRegistry = $coreRegistry; - $this->_reviewFactory = $reviewFactory; - $this->_ratingFactory = $ratingFactory; + $this->coreRegistry = $coreRegistry; + $this->reviewFactory = $reviewFactory; + $this->ratingFactory = $ratingFactory; parent::__construct($context); } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php index 90818ea3d9d8c..128e1921dd725 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php @@ -1,27 +1,31 @@ getRequest()->getParam('id', false); - $this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete(); - + $this->reviewFactory->create()->setId($reviewId)->aggregate()->delete(); $this->messageManager->addSuccess(__('The review has been deleted.')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if ($this->getRequest()->getParam('ret') == 'pending') { - $this->getResponse()->setRedirect($this->getUrl('review/*/pending')); + $resultRedirect->setPath('review/*/pending'); } else { - $this->getResponse()->setRedirect($this->getUrl('review/*/')); + $resultRedirect->setPath('review/*/'); } + return $resultRedirect; } /** @@ -31,7 +35,9 @@ public function execute() */ public function getDefaultResult() { - $resultRedirect = $this->resultRedirectFactory->create(); - return $resultRedirect->setPath('review/*/edit/', ['id' => $this->getRequest()->getParam('id', false)]); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('review/*/edit/', ['id' => $this->getRequest()->getParam('id', false)]); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php index d87d9da2f8a24..10026df39b87a 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Edit.php @@ -1,25 +1,26 @@ _view->loadLayout(); - $this->_setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Reviews')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Edit Review')); - - $this->_addContent($this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Edit')); - - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Reviews')); + $resultPage->getConfig()->getTitle()->prepend(__('Edit Review')); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Edit')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php index 679364cc1a5b9..da31a87aa9f53 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Index.php @@ -1,29 +1,32 @@ getRequest()->getParam('ajax')) { - return $this->_forward('reviewGrid'); + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('reviewGrid'); + return $resultForward; } - - $this->_view->loadLayout(); - $this->_setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Reviews')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Reviews')); - - $this->_addContent($this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Main')); - - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Reviews')); + $resultPage->getConfig()->getTitle()->prepend(__('Reviews')); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Main')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php b/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php index 600b2046c050c..c3f6aac9880b6 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/JsonProductInfo.php @@ -1,14 +1,24 @@ productRepository = $productRepository; + parent::__construct($context, $coreRegistry, $reviewFactory, $ratingFactory); } /** - * @return void + * @return \Magento\Framework\Controller\Result\Json */ public function execute() { - $response = new \Magento\Framework\Object(); + $response = new Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = $this->productRepository->getById($id); - $response->setId($id); $response->addData($product->getData()); $response->setError(0); @@ -46,6 +55,9 @@ public function execute() $response->setError(1); $response->setMessage(__('We can\'t get the product ID.')); } - $this->getResponse()->representJson($response->toJSON()); + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); + $resultJson->setData($response->toArray()); + return $resultJson; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php index e7c22885c5ae1..0783cec7e24ad 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/MassDelete.php @@ -1,38 +1,42 @@ getRequest()->getParam('reviews'); - if (!is_array($reviewsIds)) { $this->messageManager->addError(__('Please select review(s).')); } else { try { foreach ($reviewsIds as $reviewId) { - $model = $this->_reviewFactory->create()->load($reviewId); + $model = $this->reviewFactory->create()->load($reviewId); $model->delete(); } $this->messageManager->addSuccess( __('A total of %1 record(s) have been deleted.', count($reviewsIds)) ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('An error occurred while deleting record(s).')); } } - - $this->_redirect('review/*/' . $this->getRequest()->getParam('ret', 'index')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('review/*/' . $this->getRequest()->getParam('ret', 'index')); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/MassUpdateStatus.php b/app/code/Magento/Review/Controller/Adminhtml/Product/MassUpdateStatus.php index e83b7ccf7e862..422806f2a6fbe 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/MassUpdateStatus.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/MassUpdateStatus.php @@ -1,15 +1,18 @@ getRequest()->getParam('status'); foreach ($reviewsIds as $reviewId) { - $model = $this->_reviewFactory->create()->load($reviewId); + $model = $this->reviewFactory->create()->load($reviewId); $model->setStatusId($status)->save()->aggregate(); } $this->messageManager->addSuccess( __('A total of %1 record(s) have been updated.', count($reviewsIds)) ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException( @@ -35,7 +38,9 @@ public function execute() ); } } - - $this->_redirect('review/*/' . $this->getRequest()->getParam('ret', 'index')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('review/*/' . $this->getRequest()->getParam('ret', 'index')); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/MassVisibleIn.php b/app/code/Magento/Review/Controller/Adminhtml/Product/MassVisibleIn.php index 9cb636a298d30..5dbd33f8ee81c 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/MassVisibleIn.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/MassVisibleIn.php @@ -1,34 +1,36 @@ getRequest()->getParam('reviews'); - if (!is_array($reviewsIds)) { $this->messageManager->addError(__('Please select review(s).')); } else { try { $stores = $this->getRequest()->getParam('stores'); foreach ($reviewsIds as $reviewId) { - $model = $this->_reviewFactory->create()->load($reviewId); + $model = $this->reviewFactory->create()->load($reviewId); $model->setSelectStores($stores); $model->save(); } $this->messageManager->addSuccess( __('A total of %1 record(s) have been updated.', count($reviewsIds)) ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException( @@ -37,7 +39,9 @@ public function execute() ); } } - - $this->_redirect('review/*/pending'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('review/*/pending'); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php b/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php index 1a8b18c2b2960..e5d2a0e1b3159 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/NewAction.php @@ -1,26 +1,27 @@ _view->loadLayout(); - $this->_setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Reviews')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Review')); - - $this->_addContent($this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Add')); - $this->_addContent($this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')); - - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Review::catalog_reviews_ratings_reviews_all'); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Reviews')); + $resultPage->getConfig()->getTitle()->prepend(__('New Review')); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Add')); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php index a3b872c9def94..46b341492ab8b 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php @@ -1,30 +1,33 @@ getRequest()->getParam('ajax')) { - $this->_coreRegistry->register('usePendingFilter', true); - return $this->_forward('reviewGrid'); + $this->coreRegistry->register('usePendingFilter', true); + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('reviewGrid'); + return $resultForward; } - - $this->_view->loadLayout(); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Customer Reviews')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Pending Reviews')); - - $this->_coreRegistry->register('usePendingFilter', true); - $this->_addContent($this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Main')); - - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->getConfig()->getTitle()->prepend(__('Customer Reviews')); + $resultPage->getConfig()->getTitle()->prepend(__('Pending Reviews')); + $this->coreRegistry->register('usePendingFilter', true); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Main')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php index 5216e2f1db36e..6a332eb52ef8f 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Post.php @@ -1,22 +1,27 @@ getRequest()->getParam('product_id', false); - + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if ($data = $this->getRequest()->getPostValue()) { - /** @var \Magento\Store\Model\StoreManagerInterface $storeManagerInterface */ + /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ $storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface'); if ($storeManager->hasSingleStore()) { $data['stores'] = [ @@ -25,47 +30,39 @@ public function execute() } elseif (isset($data['select_stores'])) { $data['stores'] = $data['select_stores']; } - - $review = $this->_reviewFactory->create()->setData($data); - + $review = $this->reviewFactory->create()->setData($data); try { $review->setEntityId(1) // product ->setEntityPkValue($productId) - ->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID) + ->setStoreId(Store::DEFAULT_STORE_ID) ->setStatusId($data['status_id']) ->setCustomerId(null)//null is for administrator only ->save(); $arrRatingId = $this->getRequest()->getParam('ratings', []); foreach ($arrRatingId as $ratingId => $optionId) { - $this->_ratingFactory->create( - )->setRatingId( - $ratingId - )->setReviewId( - $review->getId() - )->addOptionVote( - $optionId, - $productId - ); + $this->ratingFactory->create() + ->setRatingId($ratingId) + ->setReviewId($review->getId()) + ->addOptionVote($optionId, $productId); } $review->aggregate(); $this->messageManager->addSuccess(__('You saved the review.')); if ($this->getRequest()->getParam('ret') == 'pending') { - $this->getResponse()->setRedirect($this->getUrl('review/*/pending')); + $resultRedirect->setPath('review/*/pending'); } else { - $this->getResponse()->setRedirect($this->getUrl('review/*/')); + $resultRedirect->setPath('review/*/'); } - - return; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + return $resultRedirect; + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('An error occurred while saving review.')); } } - $this->getResponse()->setRedirect($this->getUrl('review/*/')); - return; + $resultRedirect->setPath('review/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php b/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php index f9c50c3f69fdd..afdd87aac5d5a 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/ProductGrid.php @@ -1,20 +1,52 @@ layoutFactory = $layoutFactory; + parent::__construct($context, $coreRegistry, $reviewFactory, $ratingFactory); + } + + /** + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { - $this->getResponse()->setBody( - $this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')->toHtml() - ); + $layout = $this->layoutFactory->create(); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW); + $resultRaw->setContents($layout->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')->toHtml()); + return $resultRaw; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php b/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php index dc0a3b596b43d..f79da2549bf26 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/RatingItems.php @@ -1,22 +1,56 @@ layoutFactory = $layoutFactory; + parent::__construct($context, $coreRegistry, $reviewFactory, $ratingFactory); + } + + /** + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { - $this->getResponse()->setBody( - $this->_view->getLayout()->createBlock( - 'Magento\Review\Block\Adminhtml\Rating\Detailed' - )->setIndependentMode()->toHtml() + $layout = $this->layoutFactory->create(); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW); + $resultRaw->setContents( + $layout->createBlock('Magento\Review\Block\Adminhtml\Rating\Detailed') + ->setIndependentMode() + ->toHtml() ); + return $resultRaw; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/ReviewGrid.php b/app/code/Magento/Review/Controller/Adminhtml/Product/ReviewGrid.php index 9cdc5c83045f0..293b958b6ec98 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/ReviewGrid.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/ReviewGrid.php @@ -1,20 +1,52 @@ layoutFactory = $layoutFactory; + parent::__construct($context, $coreRegistry, $reviewFactory, $ratingFactory); + } + + /** + * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { - $this->getResponse()->setBody( - $this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Grid')->toHtml() - ); + $layout = $this->layoutFactory->create(); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW); + $resultRaw->setContents($layout->createBlock('Magento\Review\Block\Adminhtml\Grid')->toHtml()); + return $resultRaw; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Reviews/Grid.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Reviews/Grid.php index 626b094378865..84606cfe8b33f 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Reviews/Grid.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Reviews/Grid.php @@ -1,12 +1,16 @@ productBuilder = $productBuilder; parent::__construct($context); @@ -28,15 +32,16 @@ public function __construct( /** * Get product reviews grid * - * @return void + * @return \Magento\Framework\View\Result\Layout */ public function execute() { $product = $this->productBuilder->build($this->getRequest()); - $this->_view->loadLayout(); - $this->_view->getLayout()->getBlock('admin.product.reviews') + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + $resultLayout->getLayout()->getBlock('admin.product.reviews') ->setProductId($product->getId()) ->setUseAjax(true); - $this->_view->renderLayout(); + return $resultLayout; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php index a382dea2b917f..f1121eec6b2f5 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Save.php @@ -1,21 +1,26 @@ resultFactory->create(ResultFactory::TYPE_REDIRECT); if (($data = $this->getRequest()->getPostValue()) && ($reviewId = $this->getRequest()->getParam('id'))) { - $review = $this->_reviewFactory->create()->load($reviewId); + $review = $this->reviewFactory->create()->load($reviewId); if (!$review->getId()) { $this->messageManager->addError(__('The review was removed by another user or does not exist.')); } else { @@ -23,38 +28,31 @@ public function execute() $review->addData($data)->save(); $arrRatingId = $this->getRequest()->getParam('ratings', []); - $votes = $this->_objectManager->create( - 'Magento\Review\Model\Rating\Option\Vote' - )->getResourceCollection()->setReviewFilter( - $reviewId - )->addOptionInfo()->load()->addRatingOptions(); + /** @var \Magento\Review\Model\Rating\Option\Vote $votes */ + $votes = $this->_objectManager->create('Magento\Review\Model\Rating\Option\Vote') + ->getResourceCollection() + ->setReviewFilter($reviewId) + ->addOptionInfo() + ->load() + ->addRatingOptions(); foreach ($arrRatingId as $ratingId => $optionId) { if ($vote = $votes->getItemByColumnValue('rating_id', $ratingId)) { - $this->_ratingFactory->create( - )->setVoteId( - $vote->getId() - )->setReviewId( - $review->getId() - )->updateOptionVote( - $optionId - ); + $this->ratingFactory->create() + ->setVoteId($vote->getId()) + ->setReviewId($review->getId()) + ->updateOptionVote($optionId); } else { - $this->_ratingFactory->create( - )->setRatingId( - $ratingId - )->setReviewId( - $review->getId() - )->addOptionVote( - $optionId, - $review->getEntityPkValue() - ); + $this->ratingFactory->create() + ->setRatingId($ratingId) + ->setReviewId($review->getId()) + ->addOptionVote($optionId, $review->getEntityPkValue()); } } $review->aggregate(); $this->messageManager->addSuccess(__('You saved the review.')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving this review.')); @@ -62,12 +60,16 @@ public function execute() } $nextId = (int)$this->getRequest()->getParam('next_item'); - $url = $this->getUrl($this->getRequest()->getParam('ret') == 'pending' ? '*/*/pending' : '*/*/'); if ($nextId) { - $url = $this->getUrl('review/*/edit', ['id' => $nextId]); + $resultRedirect->setPath('review/*/edit', ['id' => $nextId]); + } elseif ($this->getRequest()->getParam('ret') == 'pending') { + $resultRedirect->setPath('*/*/pending'); + } else { + $resultRedirect->setPath('*/*/'); } - return $this->getResponse()->setRedirect($url); + return $resultRedirect; } - $this->_redirect('review/*/'); + $resultRedirect->setPath('review/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating.php b/app/code/Magento/Review/Controller/Adminhtml/Rating.php index 0cbdc054e9564..e4b0fb63d8fa3 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating.php @@ -6,35 +6,39 @@ namespace Magento\Review\Controller\Adminhtml; use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Registry; /** * Admin ratings controller */ -class Rating extends \Magento\Backend\App\Action +class Rating extends Action { /** * Core registry * * @var \Magento\Framework\Registry */ - protected $_coreRegistry = null; + protected $coreRegistry = null; /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry */ - public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry) - { - $this->_coreRegistry = $coreRegistry; + public function __construct( + Context $context, + Registry $coreRegistry + ) { + $this->coreRegistry = $coreRegistry; parent::__construct($context); } /** * @return void */ - protected function _initEnityId() + protected function initEnityId() { - $this->_coreRegistry->register( + $this->coreRegistry->register( 'entityId', $this->_objectManager->create('Magento\Review\Model\Rating\Entity')->getIdByCode('product') ); diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php index 7a224babccb0a..55fc796fc26c3 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Delete.php @@ -1,30 +1,35 @@ resultFactory->create(ResultFactory::TYPE_REDIRECT); if ($this->getRequest()->getParam('id') > 0) { try { + /** @var \Magento\Review\Model\Rating $model */ $model = $this->_objectManager->create('Magento\Review\Model\Rating'); - /* @var $model \Magento\Review\Model\Rating */ $model->load($this->getRequest()->getParam('id'))->delete(); $this->messageManager->addSuccess(__('You deleted the rating.')); - $this->_redirect('review/rating/'); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->_redirect('review/rating/edit', ['id' => $this->getRequest()->getParam('id')]); + $resultRedirect->setPath('review/rating/edit', ['id' => $this->getRequest()->getParam('id')]); + return $resultRedirect; } } - $this->_redirect('review/rating/'); + $resultRedirect->setPath('review/rating/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php index d8ff5617c0e20..54bd62f83a124 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Edit.php @@ -1,38 +1,36 @@ _initEnityId(); - $this->_view->loadLayout(); - + $this->initEnityId(); + /** @var \Magento\Review\Model\Rating $ratingModel */ $ratingModel = $this->_objectManager->create('Magento\Review\Model\Rating'); if ($this->getRequest()->getParam('id')) { $ratingModel->load($this->getRequest()->getParam('id')); } - - $this->_setActiveMenu('Magento_Review::catalog_reviews_ratings_ratings'); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Ratings')); - $this->_view->getPage()->getConfig()->getTitle()->prepend( + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Review::catalog_reviews_ratings_ratings'); + $resultPage->getConfig()->getTitle()->prepend(__('Ratings')); + $resultPage->getConfig()->getTitle()->prepend( $ratingModel->getId() ? $ratingModel->getRatingCode() : __('New Rating') ); - $this->_addBreadcrumb(__('Manage Ratings'), __('Manage Ratings')); - - $this->_addContent( - $this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Rating\Edit') - )->_addLeft( - $this->_view->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Rating\Edit\Tabs') - ); - $this->_view->renderLayout(); + $resultPage->addBreadcrumb(__('Manage Ratings'), __('Manage Ratings')); + $resultPage->addContent($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Rating\Edit')) + ->addLeft($resultPage->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Rating\Edit\Tabs')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php index dfcfe5fae1898..be9bebf78c7e9 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Index.php @@ -1,24 +1,26 @@ _initEnityId(); - $this->_view->loadLayout(); - - $this->_setActiveMenu('Magento_Review::catalog_reviews_ratings_ratings'); - $this->_addBreadcrumb(__('Manage Ratings'), __('Manage Ratings')); - $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Ratings')); - $this->_view->renderLayout(); + $this->initEnityId(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Review::catalog_reviews_ratings_ratings'); + $resultPage->addBreadcrumb(__('Manage Ratings'), __('Manage Ratings')); + $resultPage->getConfig()->getTitle()->prepend(__('Ratings')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php index 994eb427c4453..162f85eac6591 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/NewAction.php @@ -1,18 +1,23 @@ _forward('edit'); + /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('edit'); + return $resultForward; } } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php b/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php index dea639668375a..6cfaeabfa331e 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Rating/Save.php @@ -1,45 +1,42 @@ _initEnityId(); - + $this->initEnityId(); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if ($this->getRequest()->getPostValue()) { try { + /** @var \Magento\Review\Model\Rating $ratingModel */ $ratingModel = $this->_objectManager->create('Magento\Review\Model\Rating'); - $stores = $this->getRequest()->getParam('stores'); $position = (int)$this->getRequest()->getParam('position'); $stores[] = 0; $isActive = (bool)$this->getRequest()->getParam('is_active'); - $ratingModel->setRatingCode( - $this->getRequest()->getParam('rating_code') - )->setRatingCodes( - $this->getRequest()->getParam('rating_codes') - )->setStores( - $stores - )->setPosition( - $position - )->setId( - $this->getRequest()->getParam('id') - )->setIsActive( - $isActive - )->setEntityId( - $this->_coreRegistry->registry('entityId') - )->save(); + + $ratingModel->setRatingCode($this->getRequest()->getParam('rating_code')) + ->setRatingCodes($this->getRequest()->getParam('rating_codes')) + ->setStores($stores) + ->setPosition($position) + ->setId($this->getRequest()->getParam('id')) + ->setIsActive($isActive) + ->setEntityId($this->coreRegistry->registry('entityId')) + ->save(); $options = $this->getRequest()->getParam('option_title'); @@ -51,35 +48,26 @@ public function execute() $optionModel->setId($key); } - $optionModel->setCode( - $optionCode - )->setValue( - $i - )->setRatingId( - $ratingModel->getId() - )->setPosition( - $i - )->save(); + $optionModel->setCode($optionCode) + ->setValue($i) + ->setRatingId($ratingModel->getId()) + ->setPosition($i) + ->save(); $i++; } } $this->messageManager->addSuccess(__('You saved the rating.')); $this->_objectManager->get('Magento\Backend\Model\Session')->setRatingData(false); - - $this->_redirect('review/rating/'); - return; } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - $this->_objectManager->get( - 'Magento\Backend\Model\Session' - )->setRatingData( - $this->getRequest()->getPostValue() - ); - $this->_redirect('review/rating/edit', ['id' => $this->getRequest()->getParam('id')]); - return; + $this->_objectManager->get('Magento\Backend\Model\Session') + ->setRatingData($this->getRequest()->getPostValue()); + $resultRedirect->setPath('review/rating/edit', ['id' => $this->getRequest()->getParam('id')]); + return $resultRedirect; } } - $this->_redirect('review/rating/'); + $resultRedirect->setPath('review/rating/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Customer.php b/app/code/Magento/Review/Controller/Customer.php index f6281a8e38c39..034fc91c0684d 100644 --- a/app/code/Magento/Review/Controller/Customer.php +++ b/app/code/Magento/Review/Controller/Customer.php @@ -5,43 +5,44 @@ */ namespace Magento\Review\Controller; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context; +use Magento\Customer\Model\Session; use Magento\Framework\App\RequestInterface; /** * Customer reviews controller - * - * @author Magento Core Team */ -class Customer extends \Magento\Framework\App\Action\Action +class Customer extends Action { /** * Customer session model * * @var \Magento\Customer\Model\Session */ - protected $_customerSession; + protected $customerSession; /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession */ public function __construct( - \Magento\Framework\App\Action\Context $context, - \Magento\Customer\Model\Session $customerSession + Context $context, + Session $customerSession ) { - $this->_customerSession = $customerSession; + $this->customerSession = $customerSession; parent::__construct($context); } /** * Check customer authentication for some actions * - * @param RequestInterface $request + * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { - if (!$this->_customerSession->authenticate($this)) { + if (!$this->customerSession->authenticate($this)) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } return parent::dispatch($request); diff --git a/app/code/Magento/Review/Controller/Customer/Index.php b/app/code/Magento/Review/Controller/Customer/Index.php index 4aa9477ccd9fb..bc7634964dfb0 100644 --- a/app/code/Magento/Review/Controller/Customer/Index.php +++ b/app/code/Magento/Review/Controller/Customer/Index.php @@ -1,32 +1,32 @@ _view->loadLayout(); - $this->_view->getLayout()->initMessages(); - - if ($navigationBlock = $this->_view->getLayout()->getBlock('customer_account_navigation')) { + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->getLayout()->initMessages(); + if ($navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation')) { $navigationBlock->setActive('review/customer'); } - if ($block = $this->_view->getLayout()->getBlock('review_customer_list')) { + if ($block = $resultPage->getLayout()->getBlock('review_customer_list')) { $block->setRefererUrl($this->_redirect->getRefererUrl()); } - - $this->_view->getPage()->getConfig()->getTitle()->set(__('My Product Reviews')); - - $this->_view->renderLayout(); + $resultPage->getConfig()->getTitle()->set(__('My Product Reviews')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Customer/View.php b/app/code/Magento/Review/Controller/Customer/View.php index d1ea95e7afc90..92972dce3aebc 100644 --- a/app/code/Magento/Review/Controller/Customer/View.php +++ b/app/code/Magento/Review/Controller/Customer/View.php @@ -1,14 +1,21 @@ reviewFactory = $reviewFactory; + parent::__construct($context, $customerSession); } /** * Render review details * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $review = $this->reviewFactory->create()->load($this->getRequest()->getParam('id')); - if ($review->getCustomerId() != $this->_customerSession->getCustomerId()) { - return $this->_forward('noroute'); + if ($review->getCustomerId() != $this->customerSession->getCustomerId()) { + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('noroute'); + return $resultForward; } - $this->_view->loadLayout(); - if ($navigationBlock = $this->_view->getLayout()->getBlock('customer_account_navigation')) { + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + if ($navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation')) { $navigationBlock->setActive('review/customer'); } - $this->_view->getPage()->getConfig()->getTitle()->set(__('Review Details')); - $this->_view->renderLayout(); + $resultPage->getConfig()->getTitle()->set(__('Review Details')); + return $resultPage; } } diff --git a/app/code/Magento/Review/Controller/Product.php b/app/code/Magento/Review/Controller/Product.php index 4aec96dab6678..f0af2ede6e4d5 100644 --- a/app/code/Magento/Review/Controller/Product.php +++ b/app/code/Magento/Review/Controller/Product.php @@ -13,7 +13,6 @@ /** * Review controller * - * @author Magento Core Team * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Product extends \Magento\Framework\App\Action\Action @@ -23,21 +22,21 @@ class Product extends \Magento\Framework\App\Action\Action * * @var \Magento\Framework\Registry */ - protected $_coreRegistry = null; + protected $coreRegistry = null; /** * Customer session model * * @var \Magento\Customer\Model\Session */ - protected $_customerSession; + protected $customerSession; /** * Generic session * * @var \Magento\Framework\Session\Generic */ - protected $_reviewSession; + protected $reviewSession; /** * Catalog catgory model @@ -51,7 +50,7 @@ class Product extends \Magento\Framework\App\Action\Action * * @var \Psr\Log\LoggerInterface */ - protected $_logger; + protected $logger; /** * Catalog product model @@ -65,35 +64,35 @@ class Product extends \Magento\Framework\App\Action\Action * * @var \Magento\Review\Model\ReviewFactory */ - protected $_reviewFactory; + protected $reviewFactory; /** * Rating model * * @var \Magento\Review\Model\RatingFactory */ - protected $_ratingFactory; + protected $ratingFactory; /** * Catalog design model * * @var \Magento\Catalog\Model\Design */ - protected $_catalogDesign; + protected $catalogDesign; /** * Core model store manager interface * * @var \Magento\Store\Model\StoreManagerInterface */ - protected $_storeManager; + protected $storeManager; /** * Core form key validator * * @var \Magento\Framework\Data\Form\FormKey\Validator */ - protected $_formKeyValidator; + protected $formKeyValidator; /** * @param \Magento\Framework\App\Action\Context $context @@ -124,17 +123,17 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator ) { - $this->_storeManager = $storeManager; - $this->_coreRegistry = $coreRegistry; - $this->_customerSession = $customerSession; - $this->_reviewSession = $reviewSession; + $this->storeManager = $storeManager; + $this->coreRegistry = $coreRegistry; + $this->customerSession = $customerSession; + $this->reviewSession = $reviewSession; $this->categoryRepository = $categoryRepository; - $this->_logger = $logger; + $this->logger = $logger; $this->productRepository = $productRepository; - $this->_reviewFactory = $reviewFactory; - $this->_ratingFactory = $ratingFactory; - $this->_catalogDesign = $catalogDesign; - $this->_formKeyValidator = $formKeyValidator; + $this->reviewFactory = $reviewFactory; + $this->ratingFactory = $ratingFactory; + $this->catalogDesign = $catalogDesign; + $this->formKeyValidator = $formKeyValidator; parent::__construct($context); } @@ -153,9 +152,9 @@ public function dispatch(RequestInterface $request) } if (!$allowGuest && $request->getActionName() == 'post' && $request->isPost()) { - if (!$this->_customerSession->isLoggedIn()) { + if (!$this->customerSession->isLoggedIn()) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); - $this->_customerSession->setBeforeAuthUrl($this->_url->getUrl('*/*/*', ['_current' => true])); + $this->customerSession->setBeforeAuthUrl($this->_url->getUrl('*/*/*', ['_current' => true])); $this->_reviewSession->setFormData( $request->getPostValue() )->setRedirectUrl( @@ -173,22 +172,22 @@ public function dispatch(RequestInterface $request) /** * Initialize and check product * - * @return CatalogProduct + * @return \Magento\Catalog\Model\Product|bool */ - protected function _initProduct() + protected function initProduct() { $this->_eventManager->dispatch('review_controller_product_init_before', ['controller_action' => $this]); $categoryId = (int)$this->getRequest()->getParam('category', false); $productId = (int)$this->getRequest()->getParam('id'); - $product = $this->_loadProduct($productId); + $product = $this->loadProduct($productId); if (!$product) { return false; } if ($categoryId) { $category = $this->categoryRepository->get($categoryId); - $this->_coreRegistry->register('current_category', $category); + $this->coreRegistry->register('current_category', $category); } try { @@ -198,7 +197,7 @@ protected function _initProduct() ['product' => $product, 'controller_action' => $this] ); } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->_logger->critical($e); + $this->logger->critical($e); return false; } @@ -212,7 +211,7 @@ protected function _initProduct() * @param int $productId * @return bool|CatalogProduct */ - protected function _loadProduct($productId) + protected function loadProduct($productId) { if (!$productId) { return false; @@ -227,8 +226,8 @@ protected function _loadProduct($productId) return false; } - $this->_coreRegistry->register('current_product', $product); - $this->_coreRegistry->register('product', $product); + $this->coreRegistry->register('current_product', $product); + $this->coreRegistry->register('product', $product); return $product; } diff --git a/app/code/Magento/Review/Controller/Product/ListAction.php b/app/code/Magento/Review/Controller/Product/ListAction.php index a206c8a0c6dc2..3c28379ec4af6 100644 --- a/app/code/Magento/Review/Controller/Product/ListAction.php +++ b/app/code/Magento/Review/Controller/Product/ListAction.php @@ -1,63 +1,56 @@ _view->getPage()->initLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); if ($product->getPageLayout()) { - /** @var \Magento\Framework\View\Page\Config $pageConfig */ - $pageConfig = $this->_objectManager->get('Magento\Framework\View\Page\Config'); - $pageConfig->setPageLayout($product->getPageLayout()); + $resultPage->getConfig()->setPageLayout($product->getPageLayout()); } - $update = $this->_view->getLayout()->getUpdate(); - $urlSafeSku = rawurlencode($product->getSku()); - $this->_view->addPageLayoutHandles( + $resultPage->addPageLayoutHandles( ['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()] ); - - $this->_view->loadLayoutUpdates(); - $update->addUpdate($product->getCustomLayoutUpdate()); - $this->_view->generateLayoutXml(); - $this->_view->generateLayoutBlocks(); + $resultPage->addUpdate($product->getCustomLayoutUpdate()); + return $resultPage; } /** * Show list of product's reviews * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - $product = $this->_initProduct(); + $product = $this->initProduct(); if ($product) { - $this->_coreRegistry->register('productId', $product->getId()); + $this->coreRegistry->register('productId', $product->getId()); - $design = $this->_catalogDesign; - $settings = $design->getDesignSettings($product); + $settings = $this->catalogDesign->getDesignSettings($product); if ($settings->getCustomDesign()) { - $design->applyCustomDesign($settings->getCustomDesign()); + $this->catalogDesign->applyCustomDesign($settings->getCustomDesign()); } - $this->_initProductLayout($product); - + $resultPage = $this->getProductPage($product); // update breadcrumbs - $breadcrumbsBlock = $this->_view->getLayout()->getBlock('breadcrumbs'); + $breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs'); if ($breadcrumbsBlock) { $breadcrumbsBlock->addCrumb( 'product', @@ -65,10 +58,11 @@ public function execute() ); $breadcrumbsBlock->addCrumb('reviews', ['label' => __('Product Reviews')]); } - - $this->_view->renderLayout(); - } elseif (!$this->getResponse()->isRedirect()) { - $this->_forward('noroute'); + return $resultPage; } + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('noroute'); + return $resultForward; } } diff --git a/app/code/Magento/Review/Controller/Product/ListAjax.php b/app/code/Magento/Review/Controller/Product/ListAjax.php index 8b12153017ad8..b261971c509b1 100644 --- a/app/code/Magento/Review/Controller/Product/ListAjax.php +++ b/app/code/Magento/Review/Controller/Product/ListAjax.php @@ -1,22 +1,25 @@ _initProduct(); - $this->_view->loadLayout(); - $this->_view->renderLayout(); + $this->initProduct(); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + return $resultLayout; } } diff --git a/app/code/Magento/Review/Controller/Product/Post.php b/app/code/Magento/Review/Controller/Product/Post.php index 2cff25b0931bf..56260350b878f 100644 --- a/app/code/Magento/Review/Controller/Product/Post.php +++ b/app/code/Magento/Review/Controller/Product/Post.php @@ -1,29 +1,33 @@ _formKeyValidator->validate($this->getRequest())) { - $this->getResponse()->setRedirect($this->_redirect->getRefererUrl()); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + if (!$this->formKeyValidator->validate($this->getRequest())) { + $resultRedirect->setUrl($this->_redirect->getRefererUrl()); + return $resultRedirect; } - $data = $this->_reviewSession->getFormData(true); + $data = $this->reviewSession->getFormData(true); if ($data) { $rating = []; if (isset($data['ratings']) && is_array($data['ratings'])) { @@ -34,48 +38,37 @@ public function execute() $rating = $this->getRequest()->getParam('ratings', []); } - if (($product = $this->_initProduct()) && !empty($data)) { - $review = $this->_reviewFactory->create()->setData($data); - /* @var $review Review */ + if (($product = $this->initProduct()) && !empty($data)) { + /** @var \Magento\Review\Model\Review $review */ + $review = $this->reviewFactory->create()->setData($data); $validate = $review->validate(); if ($validate === true) { try { - $review->setEntityId( - $review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE) - )->setEntityPkValue( - $product->getId() - )->setStatusId( - Review::STATUS_PENDING - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->setStoreId( - $this->_storeManager->getStore()->getId() - )->setStores( - [$this->_storeManager->getStore()->getId()] - )->save(); + $review->setEntityId($review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE)) + ->setEntityPkValue($product->getId()) + ->setStatusId(Review::STATUS_PENDING) + ->setCustomerId($this->customerSession->getCustomerId()) + ->setStoreId($this->storeManager->getStore()->getId()) + ->setStores([$this->storeManager->getStore()->getId()]) + ->save(); foreach ($rating as $ratingId => $optionId) { - $this->_ratingFactory->create()->setRatingId( - $ratingId - )->setReviewId( - $review->getId() - )->setCustomerId( - $this->_customerSession->getCustomerId() - )->addOptionVote( - $optionId, - $product->getId() - ); + $this->ratingFactory->create() + ->setRatingId($ratingId) + ->setReviewId($review->getId()) + ->setCustomerId($this->customerSession->getCustomerId()) + ->addOptionVote($optionId, $product->getId()); } $review->aggregate(); $this->messageManager->addSuccess(__('Your review has been accepted for moderation.')); } catch (\Exception $e) { - $this->_reviewSession->setFormData($data); + $this->reviewSession->setFormData($data); $this->messageManager->addError(__('We cannot post the review.')); } } else { - $this->_reviewSession->setFormData($data); + $this->reviewSession->setFormData($data); if (is_array($validate)) { foreach ($validate as $errorMessage) { $this->messageManager->addError($errorMessage); @@ -85,12 +78,8 @@ public function execute() } } } - - $redirectUrl = $this->_reviewSession->getRedirectUrl(true); - if ($redirectUrl) { - $this->getResponse()->setRedirect($redirectUrl); - return; - } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); + $redirectUrl = $this->reviewSession->getRedirectUrl(true); + $resultRedirect->setUrl($redirectUrl ?: $this->_redirect->getRedirectUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/Review/Controller/Product/View.php b/app/code/Magento/Review/Controller/Product/View.php index 685c5b5e37185..a0f96b5126284 100644 --- a/app/code/Magento/Review/Controller/Product/View.php +++ b/app/code/Magento/Review/Controller/Product/View.php @@ -1,14 +1,15 @@ _reviewFactory->create()->load($reviewId); - /* @var $review Review */ + /** @var \Magento\Review\Model\Review $review */ + $review = $this->reviewFactory->create()->load($reviewId); if (!$review->getId() || !$review->isApproved() - || !$review->isAvailableOnStore($this->_storeManager->getStore()) + || !$review->isAvailableOnStore($this->storeManager->getStore()) ) { return false; } - - $this->_coreRegistry->register('current_review', $review); - + $this->coreRegistry->register('current_review', $review); return $review; } /** * Show details of one review * - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { - $review = $this->_loadReview((int)$this->getRequest()->getParam('id')); + $review = $this->loadReview((int)$this->getRequest()->getParam('id')); + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); if (!$review) { - $this->_forward('noroute'); - return; + $resultForward->forward('noroute'); + return $resultForward; } - $product = $this->_loadProduct($review->getEntityPkValue()); + $product = $this->loadProduct($review->getEntityPkValue()); if (!$product) { - $this->_forward('noroute'); - return; + $resultForward->forward('noroute'); + return $resultForward; } - - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->getLayout()->initMessages(); + return $resultPage; } } diff --git a/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php index f7fd7493d78f3..d20abf31a19c4 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php @@ -3,110 +3,95 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product; +use Magento\Framework\Controller\ResultFactory; + /** * @SuppressWarnings(PHPMD.TooManyFields) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PostTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Review\Controller\Adminhtml\Product - */ - protected $_model; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Review\Controller\Adminhtml\Product\Post */ - protected $_objectManagerHelper; - + protected $postController; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\App\Action\Context */ - protected $_registryMock; + protected $context; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */ - protected $_requestMock; + protected $requestMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $_responseMock; + protected $objectManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $_objectManagerMock; + protected $storeManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */ - protected $_messageManagerMock; + protected $storeModelMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Review\Model\Review|\PHPUnit_Framework_MockObject_MockObject */ - protected $_storeManagerInterfaceMock; + protected $reviewMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Review\Model\ReviewFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $_storeModelMock; + protected $reviewFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Review\Model\Rating|\PHPUnit_Framework_MockObject_MockObject */ - protected $_reviewModelMock; + protected $ratingMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Review\Model\RatingFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $_reviewFactoryMock; + protected $ratingFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $_ratingModelMock; + protected $resultFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ - protected $_ratingFactoryMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_resourceReviewMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_helperMock; - + protected $resultRedirectMock; protected function setUp() { $this->_prepareMockObjects(); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - $this->_model = $objectManagerHelper->getObject( + $this->context = $objectManagerHelper->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'request' => $this->requestMock, + 'objectManager' => $this->objectManagerMock, + 'resultFactory' => $this->resultFactoryMock + ] + ); + $this->postController = $objectManagerHelper->getObject( 'Magento\Review\Controller\Adminhtml\Product\Post', [ - 'coreRegistry' => $this->_registryMock, - 'reviewFactory' => $this->_reviewFactoryMock, - 'ratingFactory' => $this->_ratingFactoryMock, - 'request' => $this->_requestMock, - 'response' => $this->_responseMock, - 'objectManager' => $this->_objectManagerMock, - 'messageManager' => $this->_messageManagerMock, - 'helper' => $this->_helperMock + 'reviewFactory' => $this->reviewFactoryMock, + 'ratingFactory' => $this->ratingFactoryMock, + 'context' => $this->context ] ); @@ -117,50 +102,57 @@ protected function setUp() */ protected function _prepareMockObjects() { - $this->_registryMock = $this->getMock('Magento\Framework\Registry', [], [], '', false); - $this->_requestMock = $this->getMockBuilder('\Magento\Framework\App\Request\Http') - ->disableOriginalConstructor()->getMock(); - $this->_responseMock = $this->getMock( - '\Magento\Framework\App\ResponseInterface', ['setRedirect', 'sendResponse'] - ); - $this->_objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->_messageManagerMock = $this->getMock('\Magento\Framework\Message\Manager', [], [], '', false); - $this->_storeManagerInterfaceMock = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface'); - $this->_storeModelMock = $this->getMock( - 'Magento\Store\Model\Store', ['__wakeup', 'getId'], [], '', false + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); + $this->storeManagerMock = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface'); + $this->storeModelMock = $this->getMock( + 'Magento\Store\Model\Store', + ['__wakeup', 'getId'], + [], + '', + false ); - $this->_reviewModelMock = $this->getMock( + $this->reviewMock = $this->getMock( 'Magento\Review\Model\Review', ['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate'], [], '', false ); - - $this->_reviewFactoryMock = $this->getMock( + $this->reviewFactoryMock = $this->getMock( 'Magento\Review\Model\ReviewFactory', ['create'], [], '', false ); - - $this->_ratingModelMock = $this->getMock( + $this->ratingMock = $this->getMock( 'Magento\Review\Model\Rating', ['__wakeup', 'setRatingId', 'setReviewId', 'addOptionVote'], [], '', - false); - - $this->_ratingFactoryMock = $this->getMock( + false + ); + $this->ratingFactoryMock = $this->getMock( 'Magento\Review\Model\RatingFactory', ['create'], [], '', false ); - - $this->_helperMock = $this->getMock('\Magento\Backend\Helper\Data', [], [], '', false); + $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT, []) + ->willReturn($this->resultRedirectMock); } /** @@ -168,41 +160,55 @@ protected function _prepareMockObjects() */ public function testPostAction() { - $this->_requestMock->expects($this->at(0))->method('getParam') - ->will($this->returnValue(1)); - $this->_requestMock->expects($this->at(2))->method('getParam') - ->will($this->returnValue(['1' => '1'])); - $this->_requestMock->expects($this->once())->method('getPostValue') - ->will($this->returnValue(['status_id' => 1])); - $this->_objectManagerMock->expects($this->at(0))->method('get') + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturnMap( + [ + ['product_id', false, 1], + ['ratings', [], ['1' => '1']] + ] + ); + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->willReturn(['status_id' => 1]); + $this->objectManagerMock->expects($this->any()) + ->method('get') ->with('Magento\Store\Model\StoreManagerInterface') - ->will($this->returnValue($this->_storeManagerInterfaceMock)); - $this->_reviewFactoryMock->expects($this->once())->method('create') - ->will($this->returnValue($this->_reviewModelMock)); - $this->_ratingFactoryMock->expects($this->once())->method('create') - ->will($this->returnValue($this->_ratingModelMock)); - $this->_storeManagerInterfaceMock->expects($this->once())->method('hasSingleStore') - ->will($this->returnValue(true)); - $this->_storeManagerInterfaceMock->expects($this->once())->method('getStore') - ->will($this->returnValue($this->_storeModelMock)); - $this->_storeModelMock->expects($this->once())->method('getId') - ->will($this->returnValue(1)); - $this->_reviewModelMock->expects($this->once())->method('save') - ->will($this->returnValue($this->_reviewModelMock)); - $this->_reviewModelMock->expects($this->once())->method('getId') - ->will($this->returnValue(1)); - $this->_reviewModelMock->expects($this->once())->method('aggregate') - ->will($this->returnValue($this->_reviewModelMock)); - $this->_ratingModelMock->expects($this->once())->method('setRatingId') - ->will($this->returnSelf()); - $this->_ratingModelMock->expects($this->once())->method('setReviewId') - ->will($this->returnSelf()); - $this->_ratingModelMock->expects($this->once())->method('addOptionVote') - ->will($this->returnSelf()); - $this->_helperMock->expects($this->once())->method('geturl') - ->will($this->returnValue('url')); - - $this->_model->execute(); + ->willReturn($this->storeManagerMock); + $this->reviewFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->reviewMock); + $this->ratingFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->ratingMock); + $this->storeManagerMock->expects($this->once()) + ->method('hasSingleStore') + ->willReturn(true); + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeModelMock); + $this->storeModelMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->reviewMock->expects($this->once()) + ->method('save') + ->willReturn($this->reviewMock); + $this->reviewMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->reviewMock->expects($this->once()) + ->method('aggregate') + ->willReturn($this->reviewMock); + $this->ratingMock->expects($this->once()) + ->method('setRatingId') + ->willReturnSelf(); + $this->ratingMock->expects($this->once()) + ->method('setReviewId') + ->willReturnSelf(); + $this->ratingMock->expects($this->once()) + ->method('addOptionVote') + ->willReturnSelf(); + + $this->assertSame($this->resultRedirectMock, $this->postController->execute()); } - } diff --git a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php index 7c9d0b31080f1..5d1c1884335c7 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php @@ -3,11 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Review\Test\Unit\Controller\Product; use Magento\Review\Model\Review; +use Magento\Framework\Controller\ResultFactory; +/** + * @SuppressWarnings(PHPMD.TooManyFields) + */ class PostTest extends \PHPUnit_Framework_TestCase { /** @@ -80,6 +83,24 @@ class PostTest extends \PHPUnit_Framework_TestCase */ protected $model; + /** + * @var \Magento\Framework\App\Action\Context + */ + protected $context; + + /** + * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultFactoryMock; + + /** + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ public function setUp() { $this->redirect = $this->getMock('\Magento\Framework\App\Response\RedirectInterface'); @@ -104,8 +125,10 @@ public function setUp() $this->coreRegistry = $this->getMock('\Magento\Framework\Registry'); $this->review = $this->getMock( '\Magento\Review\Model\Review', - ['setData', 'validate', 'setEntityId', 'getEntityIdByCode', 'setEntityPkValue', 'setStatusId', - 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate'], + [ + 'setData', 'validate', 'setEntityId', 'getEntityIdByCode', 'setEntityPkValue', 'setStatusId', + 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate' + ], [], '', false, @@ -119,7 +142,7 @@ public function setUp() false, false ); - $reviewFactory->expects($this->once())->method('create')->will($this->returnValue($this->review)); + $reviewFactory->expects($this->once())->method('create')->willReturn($this->review); $this->customerSession = $this->getMock( '\Magento\Customer\Model\Session', ['getCustomerId'], @@ -144,31 +167,51 @@ public function setUp() false, false ); - $ratingFactory->expects($this->once())->method('create')->will($this->returnValue($this->rating)); + $ratingFactory->expects($this->once())->method('create')->willReturn($this->rating); $this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface'); $this->store = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); $storeManager = $this->getMockForAbstractClass('\Magento\Store\Model\StoreManagerInterface'); - $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store)); - $this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) - ->getObject( - '\Magento\Review\Controller\Product\Post', - [ - 'request' => $this->request, - 'response' => $this->response, - 'redirect' => $this->redirect, - 'formKeyValidator' => $this->formKeyValidator, - 'reviewSession' => $this->reviewSession, - 'eventManager' => $this->eventManager, - 'productRepository' => $this->productRepository, - 'coreRegistry' => $this->coreRegistry, - 'reviewFactory' => $reviewFactory, - 'customerSession' => $this->customerSession, - 'ratingFactory' => $ratingFactory, - 'storeManager' => $storeManager, - 'messageManager' => $this->messageManager, - ] - ); + $storeManager->expects($this->any())->method('getStore')->willReturn($this->store); + + $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->with(ResultFactory::TYPE_REDIRECT, []) + ->willReturn($this->resultRedirectMock); + + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->context = $objectManagerHelper->getObject( + 'Magento\Framework\App\Action\Context', + [ + 'request' => $this->request, + 'resultFactory' => $this->resultFactoryMock, + 'messageManager' => $this->messageManager + ] + ); + $this->model = $objectManagerHelper->getObject( + '\Magento\Review\Controller\Product\Post', + [ + 'response' => $this->response, + 'redirect' => $this->redirect, + 'formKeyValidator' => $this->formKeyValidator, + 'reviewSession' => $this->reviewSession, + 'eventManager' => $this->eventManager, + 'productRepository' => $this->productRepository, + 'coreRegistry' => $this->coreRegistry, + 'reviewFactory' => $reviewFactory, + 'customerSession' => $this->customerSession, + 'ratingFactory' => $ratingFactory, + 'storeManager' => $storeManager, + 'context' => $this->context + ] + ); } /** @@ -184,19 +227,16 @@ public function testExecute() $redirectUrl = 'url'; $this->formKeyValidator->expects($this->any())->method('validate') ->with($this->request) - ->will($this->returnValue(true)); + ->willReturn(true); $this->reviewSession->expects($this->any())->method('getFormData') ->with(true) - ->will($this->returnValue($ratingsData)); - $this->eventManager->expects($this->at(0))->method('dispatch') - ->with('review_controller_product_init_before', ['controller_action' => $this->model]) - ->will($this->returnSelf()); + ->willReturn($ratingsData); $this->request->expects($this->at(0))->method('getParam') ->with('category', false) - ->will($this->returnValue(false)); + ->willReturn(false); $this->request->expects($this->at(1))->method('getParam') ->with('id') - ->will($this->returnValue(1)); + ->willReturn(1); $product = $this->getMock( 'Magento\Catalog\Model\Product', ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'], @@ -206,83 +246,75 @@ public function testExecute() ); $product->expects($this->once()) ->method('isVisibleInCatalog') - ->will($this->returnValue(true)); + ->willReturn(true); $product->expects($this->once()) ->method('isVisibleInSiteVisibility') - ->will($this->returnValue(true)); + ->willReturn(true); $this->productRepository->expects($this->any())->method('getById') ->with(1) - ->will($this->returnValue($product)); + ->willReturn($product); $this->coreRegistry->expects($this->at(0))->method('register') ->with('current_product', $product) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->coreRegistry->expects($this->at(1))->method('register') ->with('product', $product) - ->will($this->returnSelf()); - $this->eventManager->expects($this->at(1))->method('dispatch') - ->with('review_controller_product_init', ['product' => $product]) - ->will($this->returnSelf()); - $this->eventManager->expects($this->at(2))->method('dispatch') - ->with('review_controller_product_init_after', ['product' => $product, 'controller_action' => $this->model]) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('setData') ->with($ratingsData) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('validate') - ->will($this->returnValue(true)); + ->willReturn(true); $this->review->expects($this->once())->method('getEntityIdByCode') ->with(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE) - ->will($this->returnValue(1)); + ->willReturn(1); $this->review->expects($this->once())->method('setEntityId') ->with(1) - ->will($this->returnSelf()); + ->willReturnSelf(); $product->expects($this->exactly(2)) ->method('getId') - ->will($this->returnValue($productId)); + ->willReturn($productId); $this->review->expects($this->once())->method('setEntityPkValue') ->with($productId) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('setStatusId') ->with(\Magento\Review\Model\Review::STATUS_PENDING) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->customerSession->expects($this->exactly(2))->method('getCustomerId') - ->will($this->returnValue($customerId)); - $this->review->expects($this->once())->method('setCustomerId')->with($customerId)->will($this->returnSelf()); + ->willReturn($customerId); + $this->review->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf(); $this->store->expects($this->exactly(2))->method('getId') - ->will($this->returnValue($storeId)); + ->willReturn($storeId); $this->review->expects($this->once())->method('setStoreId') ->with($storeId) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('setStores') ->with([$storeId]) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('save') - ->will($this->returnSelf()); + ->willReturnSelf(); $this->rating->expects($this->once())->method('setRatingId') ->with(1) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('getId') - ->will($this->returnValue($reviewId)); + ->willReturn($reviewId); $this->rating->expects($this->once())->method('setReviewId') ->with($reviewId) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->rating->expects($this->once())->method('setCustomerId') ->with($customerId) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->rating->expects($this->once())->method('addOptionVote') ->with(1, $productId) - ->will($this->returnSelf()); + ->willReturnSelf(); $this->review->expects($this->once())->method('aggregate') - ->will($this->returnSelf()); + ->willReturnSelf(); $this->messageManager->expects($this->once())->method('addSuccess') - ->with('Your review has been accepted for moderation.') - ->will($this->returnSelf()); + ->with(__('Your review has been accepted for moderation.')) + ->willReturnSelf(); $this->reviewSession->expects($this->once())->method('getRedirectUrl') ->with(true) - ->will($this->returnValue($redirectUrl)); - $this->response->expects($this->once())->method('setRedirect') - ->with($redirectUrl) - ->will($this->returnSelf()); - $this->model->execute(); + ->willReturn($redirectUrl); + + $this->assertSame($this->resultRedirectMock, $this->model->execute()); } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term.php b/app/code/Magento/Search/Controller/Adminhtml/Term.php index 9fa504f2fa72b..f1dcba98250a1 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term.php @@ -6,33 +6,17 @@ namespace Magento\Search\Controller\Adminhtml; use Magento\Backend\App\Action; +use Magento\Framework\Controller\ResultFactory; -class Term extends \Magento\Backend\App\Action +class Term extends Action { - /** - * @var \Magento\Framework\View\Result\PageFactory - */ - protected $resultPageFactory; - - /** - * @param Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory - ) { - parent::__construct($context); - $this->resultPageFactory = $resultPageFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Page */ protected function createPage() { /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ - $resultPage = $this->resultPageFactory->create(); + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); $resultPage->setActiveMenu('Magento_Search::search_term') ->addBreadcrumb(__('Search'), __('Search')); return $resultPage; diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php index 0649b87dc8cfe..78a24106294be 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php @@ -1,12 +1,14 @@ getRequest()->getParam('id'); /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */ - $redirectResult = $this->resultRedirectFactory->create(); + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); 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/*/'); + $resultRedirect->setPath('search/*/'); + return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); - return $redirectResult->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]); + $resultRedirect->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]); + return $resultRedirect; } } $this->messageManager->addError(__('We can\'t find a search term to delete.')); - return $redirectResult->setPath('search/*/'); + $resultRedirect->setPath('search/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php index 8f650796bf197..ad6502e18ad19 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php @@ -1,38 +1,38 @@ _coreRegistry = $coreRegistry; + $this->coreRegistry = $coreRegistry; + parent::__construct($context); } /** - * @return \Magento\Backend\Model\View\Result\Page + * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() @@ -44,8 +44,10 @@ public function execute() $model->load($id); if (!$model->getId()) { $this->messageManager->addError(__('This search no longer exists.')); - $this->_redirect('search/*'); - return; + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('search/*'); + return $resultRedirect; } } @@ -55,20 +57,17 @@ public function execute() $model->addData($data); } - $this->_coreRegistry->register('current_catalog_search', $model); + $this->coreRegistry->register('current_catalog_search', $model); $resultPage = $this->createPage(); $resultPage->getConfig()->getTitle()->prepend(__('Search Terms')); $resultPage->getConfig()->getTitle()->prepend($id ? $model->getQueryText() : __('New Search')); - $resultPage->getLayout()->getBlock('adminhtml.search.term.edit') ->setData('action', $this->getUrl('search/term/save')); - $resultPage->addBreadcrumb( $id ? __('Edit Search') : __('New Search'), $id ? __('Edit Search') : __('New Search') ); - return $resultPage; } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchCsv.php b/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchCsv.php index 353d123087419..da777ec44e462 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchCsv.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchCsv.php @@ -1,44 +1,45 @@ _httpFileFactory = $fileFactory; - parent::__construct($context, $resultPageFactory); + public function __construct( + Context $context, + FileFactory $fileFactory + ) { + $this->fileFactory = $fileFactory; + parent::__construct($context); } /** * Export search report grid to CSV format * - * @return ResponseInterface + * @return \Magento\Framework\App\ResponseInterface */ public function execute() { - $this->_view->loadLayout(false); - $content = $this->_view->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export'); - return $this->_httpFileFactory->create('search.csv', $content->getCsvFile(), DirectoryList::VAR_DIR); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + $content = $resultLayout->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export'); + return $this->fileFactory->create('search.csv', $content->getCsvFile(), DirectoryList::VAR_DIR); } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchExcel.php b/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchExcel.php index 237888252146a..b287a1f6ea8b2 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchExcel.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/ExportSearchExcel.php @@ -1,44 +1,45 @@ _fileFactory = $fileFactory; + $this->fileFactory = $fileFactory; + parent::__construct($context); } /** * Export search report to Excel XML format * - * @return ResponseInterface + * @return \Magento\Framework\App\ResponseInterface */ public function execute() { - $this->_view->loadLayout(false); - $content = $this->_view->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export'); - return $this->_fileFactory->create('search.xml', $content->getExcelFile(), DirectoryList::VAR_DIR); + /** @var \Magento\Framework\View\Result\Layout $resultLayout */ + $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); + $content = $resultLayout->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export'); + return $this->fileFactory->create('search.xml', $content->getExcelFile(), DirectoryList::VAR_DIR); } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php index 7fe20f79c8557..6bce708278a12 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Index.php @@ -1,12 +1,13 @@ messageManager->addError($e->getMessage()); } } - /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */ - $redirectResult = $this->resultRedirectFactory->create(); - return $redirectResult->setPath('search/*/'); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setPath('search/*/'); + return $resultRedirect; } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php b/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php index bc59d81d1bff2..35f6d63e637f9 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/NewAction.php @@ -1,39 +1,22 @@ resultForwardFactory = $resultForwardFactory; - } +use Magento\Search\Controller\Adminhtml\Term as TermController; +use Magento\Framework\Controller\ResultFactory; +class NewAction extends TermController +{ /** * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ - $resultForward = $this->resultForwardFactory->create(); + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); return $resultForward->forward('edit'); } } diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php index b10df5ef4e881..1c512961e58ed 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Report.php @@ -1,42 +1,30 @@ _view->loadLayout(); - $this->_addBreadcrumb(__('Reports'), __('Reports')); - return $this; - } +use Magento\Reports\Controller\Adminhtml\Index as ReportsIndexController; +use Magento\Framework\Controller\ResultFactory; +class Report extends ReportsIndexController +{ /** * Search terms report action * - * @return void + * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { $this->_eventManager->dispatch('on_view_report', ['report' => 'search']); - - $this->_initAction()->_setActiveMenu( - 'Magento_Reports::report_search' - )->_addBreadcrumb( - __('Search Terms'), - __('Search Terms') - ); - $this->_view->getPage()->getConfig()->getTitle()->set(__('Search Terms Report')); - $this->_view->renderLayout(); + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Reports::report_search') + ->addBreadcrumb(__('Reports'), __('Reports')) + ->addBreadcrumb(__('Search Terms'), __('Search Terms')); + $resultPage->getConfig()->getTitle()->set(__('Search Terms Report')); + return $resultPage; } /** diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php index cf503b4e61255..4226695723fd5 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php @@ -1,12 +1,15 @@ getRequest()->getPostValue(); $queryId = $this->getRequest()->getPost('query_id', null); - /** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */ - $redirectResult = $this->resultRedirectFactory->create(); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if ($this->getRequest()->isPost() && $data) { /* @var $model \Magento\Search\Model\Query */ $model = $this->_objectManager->create('Magento\Search\Model\Query'); @@ -34,7 +37,7 @@ public function execute() $model->setStoreId($storeId); $model->loadByQueryText($queryText); if ($model->getId() && $model->getId() != $queryId) { - throw new \Magento\Framework\Exception\LocalizedException( + throw new LocalizedException( __('You already have an identical search term query.') ); } elseif (!$model->getId() && $queryId) { @@ -48,7 +51,7 @@ public function execute() $model->setIsProcessed(0); $model->save(); $this->messageManager->addSuccess(__('You saved the search term.')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $hasError = true; } catch (\Exception $e) { @@ -59,9 +62,11 @@ public function execute() if ($hasError) { $this->_getSession()->setPageData($data); - return $redirectResult->setPath('search/*/edit', ['id' => $queryId]); + $resultRedirect->setPath('search/*/edit', ['id' => $queryId]); + return $resultRedirect; } else { - return $redirectResult->setPath('search/*'); + $resultRedirect->setPath('search/*'); + return $resultRedirect; } } } diff --git a/app/code/Magento/Search/Controller/Ajax/Suggest.php b/app/code/Magento/Search/Controller/Ajax/Suggest.php index de76161e9f9b9..f39c7bf708b45 100644 --- a/app/code/Magento/Search/Controller/Ajax/Suggest.php +++ b/app/code/Magento/Search/Controller/Ajax/Suggest.php @@ -1,41 +1,44 @@ autocomplete = $autocomplete; + parent::__construct($context); } /** - * @return void + * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { if (!$this->getRequest()->getParam('q', false)) { - $this->getResponse()->setRedirect($this->_url->getBaseUrl()); - return; + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $resultRedirect->setUrl($this->_url->getBaseUrl()); + return $resultRedirect; } $autocompleteData = $this->autocomplete->getItems(); @@ -43,6 +46,9 @@ public function execute() foreach ($autocompleteData as $resultItem) { $responseData[] = $resultItem->toArray(); } - $this->getResponse()->representJson(json_encode($responseData)); + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); + $resultJson->setData($responseData); + return $resultJson; } } diff --git a/app/code/Magento/Search/Controller/Term/Popular.php b/app/code/Magento/Search/Controller/Term/Popular.php index 8e4687542e2ff..687e17f62abe0 100644 --- a/app/code/Magento/Search/Controller/Term/Popular.php +++ b/app/code/Magento/Search/Controller/Term/Popular.php @@ -5,11 +5,14 @@ */ namespace Magento\Search\Controller\Term; +use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\ResponseInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Framework\Controller\ResultFactory; -class Popular extends \Magento\Framework\App\Action\Action +class Popular extends Action { /** * @var \Magento\Framework\App\Config\ScopeConfigInterface @@ -17,10 +20,10 @@ class Popular extends \Magento\Framework\App\Action\Action protected $scopeConfig; /** - * @param Context $context + * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */ - public function __construct(Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) + public function __construct(Context $context, ScopeConfigInterface $scopeConfig) { $this->scopeConfig = $scopeConfig; parent::__construct($context); @@ -29,14 +32,14 @@ public function __construct(Context $context, \Magento\Framework\App\Config\Scop /** * Dispatch request * - * @param RequestInterface $request - * @return ResponseInterface + * @param \Magento\Framework\App\RequestInterface $request + * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { $searchTerms = $this->scopeConfig->getValue( 'catalog/seo/search_terms', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); if (!$searchTerms) { $this->_redirect('noroute'); @@ -46,11 +49,12 @@ public function dispatch(RequestInterface $request) } /** - * @return void + * @return \Magento\Framework\View\Result\Page */ public function execute() { - $this->_view->loadLayout(); - $this->_view->renderLayout(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + return $resultPage; } } diff --git a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Ajax/SuggestTest.php b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Ajax/SuggestTest.php index bde05d2c660f8..c8493a32a6bb3 100644 --- a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Ajax/SuggestTest.php +++ b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Ajax/SuggestTest.php @@ -7,6 +7,7 @@ namespace Magento\Search\Test\Unit\Controller\Adminhtml\Ajax; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\Controller\ResultFactory; class SuggestTest extends \PHPUnit_Framework_TestCase { @@ -16,9 +17,6 @@ class SuggestTest extends \PHPUnit_Framework_TestCase /** @var ObjectManagerHelper */ private $objectManagerHelper; - /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $response; - /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ private $request; @@ -31,6 +29,21 @@ class SuggestTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Search\Model\AutocompleteInterface|\PHPUnit_Framework_MockObject_MockObject */ private $autocomplete; + /** + * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectMock; + + /** + * @var \Magento\Framework\Controller\Result\Json|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultJsonMock; + protected function setUp() { $this->autocomplete = $this->getMockBuilder('Magento\Search\Model\AutocompleteInterface') @@ -41,27 +54,41 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods([]) ->getMockForAbstractClass(); - $this->response = $this->getMockBuilder('\Magento\Framework\App\ResponseInterface') - ->disableOriginalConstructor() - ->setMethods(['representJson', 'setRedirect']) - ->getMockForAbstractClass(); $this->url = $this->getMockBuilder('Magento\Framework\UrlInterface') ->disableOriginalConstructor() ->setMethods(['getBaseUrl']) ->getMockForAbstractClass(); + $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Json') + ->disableOriginalConstructor() + ->getMock(); + $this->context = $this->getMockBuilder('Magento\Framework\App\Action\Context') - ->setMethods(['getRequest', 'getResponse', 'getUrl']) ->disableOriginalConstructor() ->getMock(); $this->context->expects($this->atLeastOnce()) ->method('getRequest') ->will($this->returnValue($this->request)); - $this->context->expects($this->atLeastOnce()) - ->method('getResponse') - ->will($this->returnValue($this->response)); $this->context->expects($this->any()) ->method('getUrl') ->will($this->returnValue($this->url)); + $this->context->expects($this->any()) + ->method('getResultFactory') + ->willReturn($this->resultFactoryMock); + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->willReturnMap( + [ + [ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], + [ResultFactory::TYPE_JSON, [], $this->resultJsonMock] + ] + ); + $this->objectManagerHelper = new ObjectManagerHelper($this); $this->controller = $this->objectManagerHelper->getObject( 'Magento\Search\Controller\Ajax\Suggest', @@ -95,23 +122,30 @@ public function testExecute() ->method('getItems') ->will($this->returnValue([$firstItemMock, $secondItemMock])); - $this->response->expects($this->once()) - ->method('representJson'); - $this->controller->execute(); + $this->resultJsonMock->expects($this->once()) + ->method('setData') + ->willReturnSelf(); + + $this->assertSame($this->resultJsonMock, $this->controller->execute()); } public function testExecuteEmptyQuery() { - $searchString = ""; + $url = 'some url'; + $searchString = ''; $this->request->expects($this->once()) ->method('getParam') ->with('q') ->will($this->returnValue($searchString)); $this->url->expects($this->once()) - ->method('getBaseUrl'); - $this->response->expects($this->once()) - ->method('setRedirect'); - $this->controller->execute(); + ->method('getBaseUrl') + ->willReturn($url); + $this->resultRedirectMock->expects($this->once()) + ->method('setUrl') + ->with($url) + ->willReturnSelf(); + + $this->assertSame($this->resultRedirectMock, $this->controller->execute()); } } diff --git a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php index 27fea3b5cd06d..fd0e5f83a2594 100644 --- a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php +++ b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php @@ -7,6 +7,7 @@ namespace Magento\Search\Test\Unit\Controller\Adminhtml\Term; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Framework\Controller\ResultFactory; class MassDeleteTest extends \PHPUnit_Framework_TestCase { @@ -28,16 +29,18 @@ class MassDeleteTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ private $pageFactory; - /** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */ - private $redirectFactory; - - /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $response; - /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ private $request; - /** @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ - private $redirect; + + /** + * @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $resultFactoryMock; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + private $resultRedirectMock; protected function setUp() { @@ -45,10 +48,6 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods([]) ->getMockForAbstractClass(); - $this->response = $this->getMockBuilder('\Magento\Framework\App\ResponseInterface') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMockForAbstractClass(); $this->objectManager = $this->getMockBuilder('\Magento\Framework\ObjectManagerInterface') ->disableOriginalConstructor() ->setMethods(['create']) @@ -61,26 +60,22 @@ protected function setUp() ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - $this->redirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->setMethods(['setPath']) + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); - $this->redirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->setMethods(['create']) + $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') ->disableOriginalConstructor() ->getMock(); - $this->redirectFactory->expects($this->any()) + $this->resultFactoryMock->expects($this->any()) ->method('create') - ->will($this->returnValue($this->redirect)); + ->with(ResultFactory::TYPE_REDIRECT, []) + ->willReturn($this->resultRedirectMock); $this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->getMock(); $this->context->expects($this->atLeastOnce()) ->method('getRequest') ->willReturn($this->request); - $this->context->expects($this->atLeastOnce()) - ->method('getResponse') - ->willReturn($this->response); $this->context->expects($this->any()) ->method('getObjectManager') ->willReturn($this->objectManager); @@ -88,8 +83,8 @@ protected function setUp() ->method('getMessageManager') ->willReturn($this->messageManager); $this->context->expects($this->any()) - ->method('getResultRedirectFactory') - ->willReturn($this->redirectFactory); + ->method('getResultFactory') + ->willReturn($this->resultFactoryMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->controller = $this->objectManagerHelper->getObject( @@ -114,13 +109,12 @@ public function testExecute() $this->messageManager->expects($this->once()) ->method('addSuccess') ->will($this->returnSelf()); - $this->redirect->expects($this->once()) + $this->resultRedirectMock->expects($this->once()) ->method('setPath') ->with('search/*/') - ->will($this->returnSelf()); + ->willReturnSelf(); - $result = $this->controller->execute(); - $this->assertSame($this->redirect, $result); + $this->assertSame($this->resultRedirectMock, $this->controller->execute()); } /** diff --git a/app/code/Magento/Sendfriend/Controller/Product/Send.php b/app/code/Magento/Sendfriend/Controller/Product/Send.php index 7ccbac755b5fd..e9d55a9b6c019 100644 --- a/app/code/Magento/Sendfriend/Controller/Product/Send.php +++ b/app/code/Magento/Sendfriend/Controller/Product/Send.php @@ -1,25 +1,28 @@ _initProduct(); if (!$product) { - $this->_forward('noroute'); - return; + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('noroute'); + return $resultForward; } /* @var $session \Magento\Catalog\Model\Session */ $catalogSession = $this->_objectManager->get('Magento\Catalog\Model\Session'); @@ -30,19 +33,20 @@ public function execute() ); } - $this->_view->loadLayout(); - $this->_view->getLayout()->initMessages(); + /** @var \Magento\Framework\View\Result\Page $resultPage */ + $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->getLayout()->initMessages(); $this->_eventManager->dispatch('sendfriend_product', ['product' => $product]); $data = $catalogSession->getSendfriendFormData(); if ($data) { $catalogSession->setSendfriendFormData(true); - $block = $this->_view->getLayout()->getBlock('sendfriend.send'); + $block = $resultPage->getLayout()->getBlock('sendfriend.send'); if ($block) { $block->setFormData($data); } } - $this->_view->renderLayout(); + return $resultPage; } } diff --git a/app/code/Magento/Sendfriend/Controller/Product/Sendmail.php b/app/code/Magento/Sendfriend/Controller/Product/Sendmail.php index d4bebcbeae288..995bf49d09523 100644 --- a/app/code/Magento/Sendfriend/Controller/Product/Sendmail.php +++ b/app/code/Magento/Sendfriend/Controller/Product/Sendmail.php @@ -1,6 +1,5 @@ resultFactory->create(ResultFactory::TYPE_REDIRECT); + if (!$this->_formKeyValidator->validate($this->getRequest())) { - $this->_redirect('sendfriend/product/send', ['_current' => true]); - return; + $resultRedirect->setPath('sendfriend/product/send', ['_current' => true]); + return $resultRedirect; } $product = $this->_initProduct(); $data = $this->getRequest()->getPostValue(); if (!$product || !$data) { - $this->_forward('noroute'); - return; + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); + $resultForward->forward('noroute'); + return $resultForward; } $categoryId = $this->getRequest()->getParam('cat_id', null); @@ -82,8 +87,8 @@ public function execute() $this->sendFriend->send(); $this->messageManager->addSuccess(__('The link to a friend was sent.')); $url = $product->getProductUrl(); - $this->getResponse()->setRedirect($this->_redirect->success($url)); - return; + $resultRedirect->setUrl($this->_redirect->success($url)); + return $resultRedirect; } else { if (is_array($validate)) { foreach ($validate as $errorMessage) { @@ -103,6 +108,7 @@ public function execute() $catalogSession->setSendfriendFormData($data); $url = $this->_url->getUrl('sendfriend/product/send', ['_current' => true]); - $this->getResponse()->setRedirect($this->_redirect->error($url)); + $resultRedirect->setUrl($this->_redirect->error($url)); + return $resultRedirect; } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php index 31ce3901f6bb4..ef66092a66cf4 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\View; -use Magento\Framework\View\Layout\BuilderFactory; +use Magento\Framework\App\State; class LayoutDirectivesTest extends \PHPUnit_Framework_TestCase { @@ -26,10 +26,16 @@ class LayoutDirectivesTest extends \PHPUnit_Framework_TestCase */ protected $objectManager; + /** + * @var \Magento\Framework\App\State + */ + protected $state; + protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->layoutFactory = $this->objectManager->get('Magento\Framework\View\LayoutFactory'); + $this->state = $this->objectManager->get('Magento\Framework\App\State'); } /** @@ -223,11 +229,11 @@ public function testMoveAliasBroken() $this->_getLayoutModel('move_alias_broken.xml'); } - /** - * @expectedException \OutOfBoundsException - */ public function testRemoveBroken() { + if ($this->state->getMode() === State::MODE_DEVELOPER) { + $this->setExpectedException('OutOfBoundsException'); + } $this->_getLayoutModel('remove_broken.xml'); } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php index 5462dd5b09991..d9a4d886c26c1 100644 --- a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php @@ -80,7 +80,7 @@ public function testGetCountTotals($from, $to, $expectedResult) $block->setFilterData($filterData); $block->toHtml(); - $this->assertEquals($block->getCountTotals(), $expectedResult); + $this->assertEquals($expectedResult, $block->getCountTotals()); } /** @@ -90,9 +90,10 @@ public function testGetCountTotals($from, $to, $expectedResult) */ public function getCountTotalsDataProvider() { + $time = time(); return [ - [date("Y-m-d", time() + 24 * 60 * 60), date("Y-m-d", time() + 48 * 60 * 60), false], - [date("Y-m-d", time() - 24 * 60 * 60), date("Y-m-d", time() + 24 * 60 * 60), true], + [date("Y-m-d", $time + 48 * 60 * 60), date("Y-m-d", $time + 72 * 60 * 60), false], + [date("Y-m-d", $time - 48 * 60 * 60), date("Y-m-d", $time + 48 * 60 * 60), true], [null, null, false], ]; } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php new file mode 100644 index 0000000000000..c5e7f6fd6978c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php @@ -0,0 +1,37 @@ +get('Magento\Framework\View\LayoutInterface'); + /** @var Grid $grid */ + $grid = $layout->createBlock('Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid'); + $result = $grid->getPreparedCollection(); + + $this->assertCount(1, $result->getItems()); + /** @var Quote $quote */ + $quote = $result->getFirstItem(); + $this->assertEquals('customer@example.com', $quote->getCustomerEmail()); + $this->assertEquals(10.00, $quote->getSubtotal()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php new file mode 100644 index 0000000000000..42c3700c1d1a5 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php @@ -0,0 +1,32 @@ +create('Magento\Customer\Api\CustomerRepositoryInterface'); + $customerData = $customerRepository->getById(1); + + /** @var Quote $quoteFixture */ + $quoteFixture = $objectManager->create('Magento\Quote\Model\Quote'); + $quoteFixture->load('test01', 'reserved_order_id'); + $quoteFixture->setIsActive(true); + $quoteFixture->setCustomer($customerData); + $quoteFixture->save(); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php new file mode 100644 index 0000000000000..204b1b64c7106 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php @@ -0,0 +1,39 @@ +get('Magento\Framework\View\LayoutInterface'); + /** @var Grid $grid */ + $grid = $layout->createBlock('Magento\Reports\Block\Adminhtml\Shopcart\Product\Grid'); + $result = $grid->getPreparedCollection(); + + $this->assertCount(1, $result->getItems()); + /** @var Item $quoteItem */ + $quoteItem = $result->getFirstItem(); + $this->assertInstanceOf('Magento\Quote\Model\Quote\Item', $quoteItem); + + $this->assertEquals(1, $quoteItem->getProductId()); + $this->assertEquals('Simple Product', $quoteItem->getName()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Review/Controller/ProductTest.php b/dev/tests/integration/testsuite/Magento/Review/Controller/ProductTest.php index e2aac7a8f3877..eab90b8583b4e 100644 --- a/dev/tests/integration/testsuite/Magento/Review/Controller/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Review/Controller/ProductTest.php @@ -14,7 +14,7 @@ class ProductTest extends \Magento\TestFramework\TestCase\AbstractController public function testListActionDesign($productId, $expectedDesign) { $this->getRequest()->setParam('id', $productId); - $this->dispatch('review/product/list'); + $this->dispatch('review/product/listAction'); $result = $this->getResponse()->getBody(); $this->assertContains("static/frontend/{$expectedDesign}/en_US/Magento_Theme/favicon.ico", $result); } diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 59cf16d245655..7f76c862105e0 100755 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3161,6 +3161,8 @@ ['Magento\Framework\Exception\File\ValidatorException'], ['Magento\Framework\Filesystem\FilesystemException', 'Magento\Framework\Exception\FileSystemException'], ['Magento\Shipping\Exception'], + ['Magento\Reports\Block\Adminhtml\Product\Grid'], + ['Magento\Reports\Model\Totals'], ['Magento\Log\Model\Shell'], ['Magento\Log\App\Shell'], ['Magento\Framework\App\Cache\ManagerApp'], diff --git a/dev/tools/performance-toolkit/fixtures/orders.php b/dev/tools/performance-toolkit/fixtures/orders.php index 041fcea755125..db077ab2fbbdd 100644 --- a/dev/tools/performance-toolkit/fixtures/orders.php +++ b/dev/tools/performance-toolkit/fixtures/orders.php @@ -190,7 +190,9 @@ public function execute() $country = 'US'; $zip = '11111'; $phone = '911'; - $time = date("Y-m-d h:i:s"); + $dateStart = new \DateTime(); + $dateStart->setTimezone(new \DateTimeZone('Etc/UTC')); + $time = $dateStart->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $simpleProductIdLen[0] = strlen($simpleProductId[0]($entityId)); $simpleProductIdLen[1] = strlen($simpleProductId[1]($entityId)); diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index da8130891b3b0..265a7abd8bd2f 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -10,6 +10,9 @@ use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; use Magento\Framework\View\Layout\Element; use Magento\Framework\View\Layout\ScheduledStructure; +use Magento\Framework\App\State as AppState; +use Psr\Log\LoggerInterface as Logger; +use Magento\Framework\Exception\LocalizedException; /** * Layout model @@ -152,6 +155,16 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra */ protected $readerContext; + /** + * @var \Magento\Framework\App\State + */ + protected $appState; + + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * @param Layout\ProcessorFactory $processorFactory * @param ManagerInterface $eventManager @@ -163,6 +176,8 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * @param FrontendInterface $cache * @param Layout\Reader\ContextFactory $readerContextFactory * @param Layout\Generator\ContextFactory $generatorContextFactory + * @param \Magento\Framework\App\State $appState + * @param \Psr\Log\LoggerInterface $logger * @param bool $cacheable */ public function __construct( @@ -176,6 +191,8 @@ public function __construct( FrontendInterface $cache, Layout\Reader\ContextFactory $readerContextFactory, Layout\Generator\ContextFactory $generatorContextFactory, + AppState $appState, + Logger $logger, $cacheable = true ) { $this->_elementClass = 'Magento\Framework\View\Layout\Element'; @@ -190,9 +207,10 @@ public function __construct( $this->generatorPool = $generatorPool; $this->cacheable = $cacheable; $this->cache = $cache; - $this->readerContextFactory = $readerContextFactory; $this->generatorContextFactory = $generatorContextFactory; + $this->appState = $appState; + $this->logger = $logger; } /** @@ -467,15 +485,25 @@ public function renderElement($name, $useCache = true) * * @param string $name * @return string + * @throws \Exception */ public function renderNonCachedElement($name) { - if ($this->isUiComponent($name)) { - $result = $this->_renderUiComponent($name); - } elseif ($this->isBlock($name)) { - $result = $this->_renderBlock($name); - } else { - $result = $this->_renderContainer($name); + $result = ''; + try { + if ($this->isUiComponent($name)) { + $result = $this->_renderUiComponent($name); + } elseif ($this->isBlock($name)) { + $result = $this->_renderBlock($name); + } else { + $result = $this->_renderContainer($name); + } + } catch (\Exception $e) { + if ($this->appState->getMode() === AppState::MODE_DEVELOPER) { + throw $e; + } + $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage(); + $this->logger->critical($message); } return $result; } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php index 3d60c5e411300..2e98cf8fd5d8c 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -86,6 +86,16 @@ class LayoutTest extends \PHPUnit_Framework_TestCase */ protected $generatorContextFactoryMock; + /** + * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject + */ + protected $appStateMock; + + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $loggerMock; + protected function setUp() { $this->structureMock = $this->getMockBuilder('Magento\Framework\View\Layout\Data\Structure') @@ -136,8 +146,14 @@ protected function setUp() ->getMock(); $this->generatorContextFactoryMock = $this->getMockBuilder( 'Magento\Framework\View\Layout\Generator\ContextFactory' - )->disableOriginalConstructor() - ->getMock(); + ) + ->disableOriginalConstructor() + ->getMock(); + $this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State') + ->disableOriginalConstructor() + ->getMock(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMock(); $this->model = new \Magento\Framework\View\Layout( $this->processorFactoryMock, @@ -150,6 +166,8 @@ protected function setUp() $this->cacheMock, $this->readerContextFactoryMock, $this->generatorContextFactoryMock, + $this->appStateMock, + $this->loggerMock, true ); } diff --git a/lib/web/mage/adminhtml/globals.js b/lib/web/mage/adminhtml/globals.js index c9f708bd6846e..de0e06295e05b 100644 --- a/lib/web/mage/adminhtml/globals.js +++ b/lib/web/mage/adminhtml/globals.js @@ -2,8 +2,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -define([ -], function () { +define([], function () { 'use strict'; /** @@ -13,4 +12,18 @@ define([ window.setLocation = function (url) { window.location.href = url; }; + + /** + * Helper for onclick action. + * @param {String} message + * @param {String} url + * @returns {boolean} + */ + window.deleteConfirm = function (message, url) { + if (confirm(message)) { + setLocation(url); + } + + return false; + }; }); diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 35f3a6fed1489..7dd717f0c4a72 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1120,6 +1120,7 @@ private function assertDbAccessible() private function installSampleData($request) { $userName = isset($request[AdminAccount::KEY_USER]) ? $request[AdminAccount::KEY_USER] : ''; + $this->objectManagerProvider->reset(); $this->sampleData->install($this->objectManagerProvider->get(), $this->log, $userName); } diff --git a/setup/src/Magento/Setup/Model/SampleData.php b/setup/src/Magento/Setup/Model/SampleData.php index f01948c53323b..0e9e4eaeea9b9 100644 --- a/setup/src/Magento/Setup/Model/SampleData.php +++ b/setup/src/Magento/Setup/Model/SampleData.php @@ -50,11 +50,11 @@ public function isDeployed() * * @param ObjectManagerInterface $objectManager * @param LoggerInterface $logger - * @param string $adminUserName + * @param string $userName * @throws \Exception * @return void */ - public function install(ObjectManagerInterface $objectManager, LoggerInterface $logger, $adminUserName) + public function install(ObjectManagerInterface $objectManager, LoggerInterface $logger, $userName) { /** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */ $sampleDataLogger = $objectManager->get('Magento\Tools\SampleData\Logger'); @@ -68,11 +68,8 @@ public function install(ObjectManagerInterface $objectManager, LoggerInterface $ $configLoader = $objectManager->get('Magento\Framework\App\ObjectManager\ConfigLoader'); $objectManager->configure($configLoader->load($areaCode)); - /** @var \Magento\User\Model\UserFactory $userFactory */ - $userFactory = $objectManager->get('Magento\User\Model\UserFactory'); - $user = $userFactory->create()->loadByUsername($adminUserName); - + /** @var \Magento\Tools\SampleData\Installer $installer */ $installer = $objectManager->get('Magento\Tools\SampleData\Installer'); - $installer->run($user); + $installer->run($userName); } }