Skip to content

Commit

Permalink
Merge pull request #60 from magento-tango/MAGETWO-31522
Browse files Browse the repository at this point in the history
[Tango] S45 Controller Refactoring
  • Loading branch information
vpelipenko committed Jan 27, 2015
2 parents a68cc70 + 57c8b15 commit 8892e7b
Show file tree
Hide file tree
Showing 223 changed files with 5,035 additions and 2,505 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Controller/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class View extends \Magento\Catalog\Controller\Product
protected $viewHelper;

/**
* @var \Magento\Framework\Controller\Result\Redirect
* @var \Magento\Framework\Controller\Result\RedirectFactory
*/
protected $resultRedirectFactory;

Expand Down
51 changes: 20 additions & 31 deletions app/code/Magento/Catalog/Helper/Product/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ViewInterface;
use Magento\Framework\View\Result\LayoutFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Catalog\Helper\Product;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -43,9 +43,9 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper
protected $_storeManager;

/**
* @var ViewInterface
* @var \Magento\Framework\View\Result\LayoutFactory
*/
protected $_view;
protected $resultLayoutFactory;

/**
* @var ProductRepositoryInterface
Expand All @@ -62,7 +62,7 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param Product $catalogProduct
* @param Registry $coreRegistry
* @param ViewInterface $view
* @param LayoutFactory $resultLayoutFactory
* @param ProductRepositoryInterface $productRepository
* @param CustomerRepositoryInterface $customerRepository
*/
Expand All @@ -71,14 +71,14 @@ public function __construct(
StoreManagerInterface $storeManager,
Product $catalogProduct,
Registry $coreRegistry,
ViewInterface $view,
LayoutFactory $resultLayoutFactory,
ProductRepositoryInterface $productRepository,
CustomerRepositoryInterface $customerRepository
) {
$this->_storeManager = $storeManager;
$this->_coreRegistry = $coreRegistry;
$this->_catalogProduct = $catalogProduct;
$this->_view = $view;
$this->resultLayoutFactory = $resultLayoutFactory;
$this->productRepository = $productRepository;
$this->customerRepository = $customerRepository;
parent::__construct($context);
Expand All @@ -87,30 +87,26 @@ public function __construct(
/**
* Init layout of product configuration update result
*
* @return $this
* @return \Magento\Framework\View\Result\Layout
*/
protected function _initUpdateResultLayout()
{
$this->_view->getLayout()->getUpdate()->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT');
$this->_view->loadLayoutUpdates();
$this->_view->generateLayoutXml();
$this->_view->generateLayoutBlocks();
return $this;
$resultLayout = $this->resultLayoutFactory->create();
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT');
return $resultLayout;
}

/**
* Prepares and render result of composite product configuration update for a case
* when single configuration submitted
*
* @param \Magento\Framework\Object $updateResult
* @return void
* @return \Magento\Framework\View\Result\Layout
*/
public function renderUpdateResult(\Magento\Framework\Object $updateResult)
{
$this->_coreRegistry->register('composite_update_result', $updateResult);

$this->_initUpdateResultLayout();
$this->_view->renderLayout();
return $this->_initUpdateResultLayout();
}

/**
Expand All @@ -121,24 +117,18 @@ public function renderUpdateResult(\Magento\Framework\Object $updateResult)
*
* @param bool $isOk
* @param string $productType
* @return $this
* @return \Magento\Framework\View\Result\Layout
*/
protected function _initConfigureResultLayout($isOk, $productType)
{
$update = $this->_view->getLayout()->getUpdate();
$resultLayout = $this->resultLayoutFactory->create();
if ($isOk) {
$update->addHandle(
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE'
)->addHandle(
'catalog_product_view_type_' . $productType
);
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE')
->addHandle('catalog_product_view_type_' . $productType);
} else {
$update->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
$resultLayout->addHandle('CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
}
$this->_view->loadLayoutUpdates();
$this->_view->generateLayoutXml();
$this->_view->generateLayoutBlocks();
return $this;
return $resultLayout;
}

/**
Expand All @@ -149,7 +139,7 @@ protected function _initConfigureResultLayout($isOk, $productType)
* - 'error' = true, and 'message' to show
*
* @param \Magento\Framework\Object $configureResult
* @return void
* @return \Magento\Framework\View\Result\Layout
*/
public function renderConfigureResult(\Magento\Framework\Object $configureResult)
{
Expand Down Expand Up @@ -194,7 +184,6 @@ public function renderConfigureResult(\Magento\Framework\Object $configureResult
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
}

$this->_initConfigureResultLayout($isOk, $productType);
$this->_view->renderLayout();
return $this->_initConfigureResultLayout($isOk, $productType);
}
}
20 changes: 19 additions & 1 deletion app/code/Magento/Customer/Controller/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\View\Result\PageFactory;

/**
* Customer account controller
Expand Down Expand Up @@ -40,15 +42,31 @@ class Account extends \Magento\Framework\App\Action\Action
/** @var Session */
protected $session;

/**
* @var RedirectFactory
*/
protected $resultRedirectFactory;

/**
* @var PageFactory
*/
protected $resultPageFactory;

/**
* @param Context $context
* @param Session $customerSession
* @param RedirectFactory $resultRedirectFactory
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
Session $customerSession
Session $customerSession,
RedirectFactory $resultRedirectFactory,
PageFactory $resultPageFactory
) {
$this->session = $customerSession;
$this->resultRedirectFactory = $resultRedirectFactory;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}

Expand Down
27 changes: 19 additions & 8 deletions app/code/Magento/Customer/Controller/Account/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Framework\App\Action\Context;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\View\Result\PageFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
Expand Down Expand Up @@ -46,16 +48,22 @@ class Confirm extends \Magento\Customer\Controller\Account
/**
* @param Context $context
* @param Session $customerSession
* @param RedirectFactory $resultRedirectFactory
* @param PageFactory $resultPageFactory
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param AccountManagementInterface $customerAccountManagement
* @param CustomerRepositoryInterface $customerRepository
* @param Address $addressHelper
* @param UrlFactory $urlFactory
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Session $customerSession,
RedirectFactory $resultRedirectFactory,
PageFactory $resultPageFactory,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
AccountManagementInterface $customerAccountManagement,
Expand All @@ -69,19 +77,22 @@ public function __construct(
$this->customerRepository = $customerRepository;
$this->addressHelper = $addressHelper;
$this->urlModel = $urlFactory->create();
parent::__construct($context, $customerSession);
parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory);
}

/**
* Confirm customer account by id and confirmation key
*
* @return void
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();

if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
try {
$customerId = $this->getRequest()->getParam('id', false);
Expand All @@ -96,17 +107,17 @@ public function execute()
$this->_getSession()->setCustomerDataAsLoggedIn($customer);

$this->messageManager->addSuccess($this->getSuccessMessage());
$this->getResponse()->setRedirect($this->getSuccessRedirect());
return;
$resultRedirect->setUrl($this->getSuccessRedirect());
return $resultRedirect;
} catch (StateException $e) {
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
} catch (\Exception $e) {
$this->messageManager->addException($e, __('There was an error confirming the account'));
}
// die unhappy
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
$this->getResponse()->setRedirect($this->_redirect->error($url));
return;
$resultRedirect->setUrl($this->_redirect->error($url));
return $resultRedirect;
}

/**
Expand Down
52 changes: 25 additions & 27 deletions app/code/Magento/Customer/Controller/Account/Confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

use Magento\Framework\App\Action\Context;
use Magento\Customer\Model\Session;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\View\Result\PageFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Framework\UrlFactory;
use Magento\Framework\Exception\State\InvalidTransitionException;

class Confirmation extends \Magento\Customer\Controller\Account
Expand All @@ -21,44 +22,47 @@ class Confirmation extends \Magento\Customer\Controller\Account
/** @var AccountManagementInterface */
protected $customerAccountManagement;

/** @var \Magento\Framework\UrlInterface */
protected $urlModel;

/**
* @param Context $context
* @param Session $customerSession
* @param RedirectFactory $resultRedirectFactory
* @param PageFactory $resultPageFactory
* @param StoreManagerInterface $storeManager
* @param AccountManagementInterface $customerAccountManagement
* @param UrlFactory $urlFactory
*/
public function __construct(
Context $context,
Session $customerSession,
RedirectFactory $resultRedirectFactory,
PageFactory $resultPageFactory,
StoreManagerInterface $storeManager,
AccountManagementInterface $customerAccountManagement,
UrlFactory $urlFactory
AccountManagementInterface $customerAccountManagement
) {
$this->storeManager = $storeManager;
$this->customerAccountManagement = $customerAccountManagement;
$this->urlModel = $urlFactory->create();
parent::__construct($context, $customerSession);
parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory);
}

/**
* Send confirmation link to specified email
*
* @return void
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
*/
public function execute()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}

// try to confirm by email
$email = $this->getRequest()->getPost('email');
if ($email) {
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();

try {
$this->customerAccountManagement->resendConfirmation(
$email,
Expand All @@ -69,26 +73,20 @@ public function execute()
$this->messageManager->addSuccess(__('This email does not require confirmation.'));
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Wrong email.'));
$this->getResponse()->setRedirect(
$this->urlModel->getUrl('*/*/*', ['email' => $email, '_secure' => true])
);
return;
$resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
return $resultRedirect;
}
$this->_getSession()->setUsername($email);
$this->getResponse()->setRedirect($this->urlModel->getUrl('*/*/index', ['_secure' => true]));
return;
$resultRedirect->setPath('*/*/index', ['_secure' => true]);
return $resultRedirect;
}

// output form
$this->_view->loadLayout();

$this->_view->getLayout()->getBlock(
'accountConfirmation'
)->setEmail(
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getLayout()->getBlock('accountConfirmation')->setEmail(
$this->getRequest()->getParam('email', $email)
);

$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
$resultPage->getLayout()->initMessages();
return $resultPage;
}
}
Loading

0 comments on commit 8892e7b

Please sign in to comment.